tuto_move 1.14 KB
#!/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()