This is an old revision of the document!
Using simulations is a good way to learn ROS without having to own a physical robot. In this chapter we just use a 2D simulation called Turtlesim.
First, run roscore:
$ roscore
Run a node named turtlesim_node from the library turtlesim:
$ rosrun turtlesim turtlesim_node
When the node is run, a simulation with a graphical user interface opens.
The library also contains a node that can be used to send keyboard movement messages to the robot.
Run the robot remote control node in a new terminal window:
$ rosrun turtlesim turtle_teleop_key
Now by pressing the arrow keys in this terminal, we can move the robot in the simulation:
Let's see how it works using the rqt_graph tool, which visualizes the relationships between nodes and themes:
$ rqt_graph
Launching the command opens a graphical user interface. We see that the /teleop_turtle node reads the arrow keys and turns them into a robot speed geometry_msgs/twist. It is sent to /turtle1/command_velocity, which is listened to by a robot simulation. By running the same nodes on different computers, we can control the robot from another computer. A similar configuration is often used to control real robots.
The robot type is controlled by the message type geometry_msgs/twist, which consists of linear and angular velocities. Let's try to speed ourselves from the command line. The TAB key can be used to automatically complete the command. We use the rostopic pub tool argument to r 1, which sends the given message at 1 Hz:
$ rostopic pub/turtle1/cmd_vel geometry_msgs /Twist -r 1 - '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'
We see that the robot moves from a circular motion in the simulation.
The rqt_plot tool is used to visualize the subject data over time. With this tool you can display the values of the messages as a graph. This tool can be used, for example, to visualize sensor values. Turtlesim simulator publishes the x and y coordinates of a robot in /turtle1/pose/x and /turtle1/pose/y. Let's try to display these topics on the graph.
Run rqt_plot:
$ rqt_plot
Adding /turtle1/pose/x and /turtle1/pose/y to the graph shows the real-time position of the robot on the x and y axes: