1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3
"""Move in cirle"""
# Imports
import rclpy # core ROS2 client python library
from rclpy.node import Node # Manipulate ROS Nodes
from geometry_msgs.msg import Twist
# Message to publish:
print("tuto_move :: START...")
# Main loop
def main():
"""Main loop"""
rclpy.init() # Initialize ROS2 client
myNode= Node('move_node') # Create a Node, with a name
# Initialize a publisher:
velocity_publisher = myNode.create_publisher(Twist, '/cmd_vel', 10)
# Start the ros infinite loop with myNode.
while True :
rclpy.spin_once( myNode, timeout_sec=0.1 )
print("Running...")
# Publish a msg
velo = Twist()
velo.linear.x= 0.2 # meter per second
velo.angular.z = 0.5 # radians per second
velocity_publisher.publish(velo)
# At the end, destroy the node explicitly.
myNode.destroy_node()
# and shut the light down.
rclpy.shutdown()
print("tuto_move :: STOP.")
# activate main() function only if the file is executed as a script (ie. not imported).
if __name__ == '__main__':
# call main() function
main()