Search this site
Embedded Files
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
  • More
    • Home
      • Computer Geek
      • Learning
      • Math Geek
      • Projects

TurtleSim Tutorial

< Back to ROS Beginner tutorials

Time for the first tutorial in ROS. We'll be using a prebuilt package called turtlesim for this tutorial. It's okay if you don't understand it all on the first run, just get the gist of what's happening. Perform the following steps and note the outputs carefully

Open the terminal (Ctrl + Alt + T) and start the ROS server. Type in the following commands into the terminal and press Enter after every command to execute it:

    • roscore
      • This command starts the ROS server in the current terminal session. Open another terminal, we'll have to enter commands into separate terminals from now on (whenever the current process will take hold of the terminal).

Run the node for turtlesim graphics window. This will spawn up the turtle in a window. Type in the following commands into different terminal and press Enter after every command to execute it:

  • rosrun turtlesim turtlesim_node
    • This will run the node and it'll spawn the graphical window in which you'll be able to see a turtle. Now you can't move it around yet, we'll do that soon.
    • If this node is killed, the window will close.
  • rosnode list
    • This lists all the active nodes. Note that rosout is a node started by the server for debugging. You'll also see the "/turtlesim" node.

Run a node to make the turtle go in rectangles (it draws rectangles on the screen). Type the following in a terminal and check the output on the screen:

  • rosrun turtlesim draw_square
    • This runs another node to make the turtle go in squares.
    • See what topics are running by executing
      • rostopic list
    • Once done, terminate this running process using `Ctrl + C` combination on the terminal and go to the next step

It sometimes might not work as desired.

Now, let's control the turtle using our keyboard. Type the following into different terminals (I'd suggest you don't use different tabs here) and press enter after every command:

    • rostopic echo /turtle1/cmd_vel
      • This just shows blank output for now, but keep checking it while you use the next step
      • It starts a node that listens to this topic actually
    • rosrun turtlesim turtle_teleop_key
      • This let's you control the turtle using the arrow keys. You can get the windows side by side and select the terminal session running this command. This way, your keyboard input will go to the node running in the terminal whereas the output would be visible on the graphical window to the side.
      • Also observe the messages exchanged on the topic "/turtle1/cmd_vel" (output of the previous command) as you keep moving the turtle.

Great. Now you can try playing around a bit more with the command line tools. I'd suggest that you do the following

  • Run rqt_graph on a terminal and see the graph made

This shows the communication between different nodes. It basically shows the network structure of the ROS system. We'll learn more about this in later tutorials.

This is the computation graph that ROS makes. There are three nodes: one handling the turtle GUI ("/turtlesim"), one for the keyboard controller ("/teleop_turtle") and another is for the rostopic echo /turtle1/cmd_vel command we had previously ("/rostopic_2670_...", you might have something else, such numbers are assigned randomly).

Call a service to spawn another turtle on the same figure, move it and then kill it:

  • rosservice list
    • Shows a list of ongoing services
  • rosservice call /clear
    • Clears the line marks
  • rosservice info /spawn
    • Shows information about the spawn service
  • rosservice call /spawn "x: 2.0 y: 2.0 theta: 1.0 name: 'turtle2'"
    • This spawns another turtle on the board. Note that 'theta' is the angle in radians
    • You can only write "rosservice call /spawn" and press tab twice, you'll get a list, now just fill in the values. In fact, tab key proves to be very helpful for auto completion on terminal.
    • You can see the newly spawned turtle near the mouse pointer in the image.
  • rostopic list
    • Gives you a list of topics that are open on the server.
  • rostopic pub /turtle2/cmd_vel geometry_msgs/Twist "linear: x: 2.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0"
  • rostopic pub /turtle2/cmd_vel geometry_msgs/Twist "linear: x: 0.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: -2.0"
  • rostopic pub /turtle2/cmd_vel geometry_msgs/Twist "linear: x: 2.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0"
    • Press 'Ctrl + C' after every command because the publishing latches itself. You'll observe that the turtle makes a movement. These are relative, so x is actually in the direction the turtle is facing. We now also know that topics transfer messages (like topic /turtle2/cmd_vel exchanges messages of type geometry_msgs/Twist).
    • The path that the above three commands make is shown in the image.
    • Since the commands are lengthy, it's suggested that you use `tab` to auto complete on terminal.
    • This publishes messages on a topic, we'll learn more about it in the future tutorials.
  • rosservice call /kill "name: 'turtle2'"
    • This vanishes the turtle from the window, but doesn't clear the lines. You could use the command discussed earlier to do that.

Spawned the blue turtle

Path the turtle makes

Yay, we've completed the first tutorial

< Back to ROS Beginner tutorials
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse