Steps for Execution the Turtlesim
Start ROS in the terminal using the command:
$ roscore
Start the turtlesim node on a new terminal using the command:
$ rosrun turtlesim turtlesim_node
Execute the program using the following command:
$ rosrun my_package turtlesim.py 2.0
Below is the implementation:
Python3
#!/usr/bin/env python # author : Sumanth Nethi import rospy from geometry_msgs.msg import Twist import sys def turtle_circle(radius): rospy.init_node( 'turtlesim' , anonymous = True ) pub = rospy.Publisher( '/turtle1/cmd_vel' , Twist, queue_size = 10 ) rate = rospy.Rate( 10 ) vel = Twist() while not rospy.is_shutdown(): vel.linear.x = radius vel.linear.y = 0 vel.linear.z = 0 vel.angular.x = 0 vel.angular.y = 0 vel.angular.z = 1 rospy.loginfo( "Radius = %f" , radius) pub.publish(vel) rate.sleep() if __name__ = = '__main__' : try : turtle_circle( float (sys.argv[ 1 ])) except rospy.ROSInterruptException: pass |
Output:
Draw a circle using Turtlesim in ROS-Python
In this article, we are going to see how to draw a circle using Turtlesim in ROS-Python.
ROS stands for Robot Operating System. ROS is a set of libraries and tools that help build robot applications. It’s extensively used in robotics projects. ROS is an open-source, meta-operating system for robots. The software in the ROS ecosystem has both language-dependent and language-independent tools. ROS supports Python, C++, Lisp and other languages.
rospy is a pure Python client library ROS. We shall make use of this library to implement our code. Turtlesim is a common tool specifically made to teach ROS and ROS packages.
The idea is to import Twist from geometry_msgs.msg library and assign appropriate values for velocity components. Twist expresses the velocity of turtle in 3D space broken into 3 linear components and 3 angular components. Turtle here is 2D and is governed by 1 linear component (x-component) and 1 angular component (z-component). This is because the turtle cannot move in y or z directions. Hence. all other components are equated to 0.