ROS: Can you control the ROS Turtle and make your first ROS System?


ROS is the most popular Robot Operating system and this blog will talk about beginners approach to start understanding some basic concepts by using the Turtle example to build your first ROS System.

The Turtle example is a captured in the ROS Official tutorial that we would be using in this blog.

The aim of this blog:

We would see how we shall start the roscore and use the turtle to move using directional keys and also using angle provided. Finally, we will leave the turtle in continuous motion to build our first mini ROS System.

Since this blog will deal with visuals and motion we decided to put short Youtube videos of the output. Please have a look at the videos as well to make sense of this blog.

We would see the core concepts in ROS fundamentals as below as we code the ROS Turtle:

  • Nodes

  • Topic

  • Graph

  • Data exchange

  • Continuous data stream exchange

  • Concept of publisher and subscriber

Prerequisites for this blog:

You must have ROS installed. You should have some basic idea about UNIX commands. If you don't have ROS installed then you may refer our earlier blog on ROS installation over Ubuntu here.

ROS Indigo installation over Ubuntu

Please note that all Unix commands are in Green and are executed in multiple terminal and not the same terminal. You can hear this podcast to know about the top 'mantras' we have for ROS.

1. To call the Turtle:

In this part, we will initiate Roscore and call the turtle.

a) Run the core component of ROS by typing roscore. Please keep this terminal open and donot close this roscore terminal.

b) Open a new terminal and type-

rosrun turtlesim turtlesim_node

Here turtlesim is the package name and turtlesim_node is the node name. In ROS a node is an executable which uses ROS to communicate with each other.

c) Optional: To see the nodes running type in a new terminal -

rosnode list

You can also ping this node by -

rosnode ping turtlesim_node

2. Control the Turtle using keystrokes (ROS Topic):

a) Open a new terminal and here we will create another node which will 'talk' with the earlier node we created for Turtle as-

rosrun turtlesim turtle_teleop_key

Here, turtle_teleop_key is the second node which we have created to talk with the first node. ROS uses the concept of Topic (imagine a straight line between two points where points are like nodes) to communicate with Nodes.

b) Now move to the terminal of turtle_teleop_key and press the directional arrows to control the Turtle.

The below video demonstrates the output.

3. Visualise the nodes and Topic using graphs (rqt_graph):

a) We will use the rqt_graph for visualisation. This should have been installed by default when you installed Indigo ROS. In a new terminal type -

rosrun rqt_graph rqt_graph

b) Optional: If you see that rqt_graph is missing then you may separately install using the below two commands.

In ROS a node is an executable which uses ROS to communicate with each other

sudo apt-get install ros-indigo-rqt sudo apt-get install ros-indigo-rqt-common-plugins

c) If you place your mouse over /turtle1/command_velocity it will highlight the ROS nodes (here blue and green) and topics (here red). Keep all terminals open and move on.

4. Check the data published between nodes to a topic:

a) This can be done by calling the topic name as -

rostopic echo /turtle1/cmd_vel

b) Make sure that you select the turtle_teleop_key terminal again and you would see the data exchanged between the nodes and showing values of x,y,z.

5. Data exchange:

Now that we have seen the data published on a ROS topic we will try to send data between two nodes. In ROS the data from a publisher to a subscriber should be of the same data type. As pointed out in the ROS official site -

" Communication on topics happens by sending ROS messages between nodes. For the publisher (turtle_teleop_key) and subscriber (turtlesim_node) to communicate, the publisher and subscriber must send and receive the same type of message. "

a) So to do this communication we would need to know the data type for the publisher node which can be known by-

rostopic type /turtle1/cmd_vel

You would see that it returns the type Twist and further details can be seen by-

rosmsg show geometry_msgs/Twist

This shows that float64 is used for both angular and linear representation.

b) We use this data type to send a command to the nodes as -

rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'

Where,

  • rostopic pub = Publish a message for the topic

  • -1 = Only one message and then exit, not continuous stream of message packets

  • turtle1/cmd_vel = Name of the topic ( Something as an interface-attribute)

  • geometry_msgs/Twist = Message Type/Data type (Imagine an XML file)

  • '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]' = Linear velocity of 2.0 in x and angular velocity of 1.8 in z. These are in YAML syntax

Please have a look at the video which shows the angular movement of the turtle.

For the publisher (turtle_teleop_key) and subscriber (turtlesim_node) to communicate, the publisher and subscriber must send and receive the same type of message

6. Continuous message stream:

a) As you may have seen in the video that the previous command only causes a part linear and angular movement of the turtle.

To perform a continuous movement of the turtle we would need to send a steady stream of messages and at a frequency.

So we send continuous messages stream at 1 Hz as below-

rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

Note that 1 here denotes the 1hz.

b) The output can be seen as continuous this time and the turtle will keep moving unless you stop it with a ctrl +c in the terminal. This is shown in the next video.

c) You can now again check the rqt_graph and see that this is reflected. Press the refresh button on the top left to see this.

References:

1. http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics

2. http://wiki.ros.org/ROS/Tutorials/UnderstandingNodes

3. http://www.ros.org/

4. https://www.mierobot.com/single-post/ROS-Robot-UbuntuInstallation

5. http://wiki.ros.org/ROS/YAMLCommandLine

#roboticsblog #freerobotics #robotics #roboticsinindia