Skip to the content.


In robot programming, implementing planning processes that is customized into the specific application is very essential. In this regard, ROS has a big advantage to control robot with user defined process plans. However, it is not easy to find a precise tutorial that helps to devive into ROS in short time.

Let us consider a turtle sim, 2D robot and dive fast into ROS. Assuming you have a complete installation of ROS packages,and turtle sim;


Explained tutorial using Command terminal with Turtle simulation

This tutorial helps to get familiar with ROS environment using Turtle sim using command line.

$ rostopic echo /turtle1/cmd_vel

Publishers: None


Explained tutorial with Python script

Subscriber function

Save the Subscriber function as “” in your src folder in catkin_ws.

import sys
import rospy
from geometry_msgs.msg import Twist
import datetime

def callback_pose(data):
    """Get the ROS message"""   

def listener():
   """Subscribe to ROS topic node"""

    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/turtle1/cmd_vel", Twist, callback_pose)

if __name__ == '__main__':

Publisher function

Save the publisher function as “” in your src folder in catkin_ws.

import rospy
from geometry_msgs.msg import Twist
import sys

def moveFunction_turtle(linear_velocity, angular_velocity):
    """Move turtle robot with input velocity"""
    rospy.init_node('moveFunction_turtle', anonymous=True)
    pub = rospy.Publisher("/turtle1/cmd_vel", Twist, queue_size=10)
    rate = rospy.Rate(10) # 10hz
    velocity = Twist()
    while not rospy.is_shutdown():
	velocity.linear.x = linear_velocity
	velocity.angular.z = angular_velocity

        rospy.loginfo("Linear velocity = %f: Angular velocity = %f: ", linear_velocity, angular_velocity)

if __name__ == '__main__':
        moveFunction_turtle(float(sys.argv[1]), float(sys.argv[2]))
    except rospy.ROSInterruptException:

How to run the script

Open new terminal and change the directory to the publisher and subscriber function containing folder and run the functions separately as follows;

python 2.0 4.0



Congratulations, now you are able to subscribe and publish to rostopic node!!