Your First ROS based System

Many newcomers to ROS don’t know where to start. Indeed, ROS is not an application, but it is rather a robotics middleware. That is an infrastructure to run robotic software. It provides plenty of tools, libraries and packages to ease developing, managing and reusing code. In this post, we’ll go quickly through the main concepts and illustrate them using a simple example.

If you want to experiment by yourself, all you need is the Fuerte version of ROS. You can install it as we explained in a pervious post. A ready to use alternative is to download the VirtualBox ROS virtual machine we provide.

Main ROS Concepts

The first concept ROS concept that you should know is Node. At run-time, a ROS based system is made of a set of nodes, running on a one or more computers connected to the same network. A node is a computational unit. It may offer services which can be viewed as procedures or functions that can be called by other nodes. Each service has a type that expresses the format of the parameters and the returned value, since services enable request/response communication.

A node can also broadcast messages (i.e. data structures) consumed by other nodes that subscribe to the same communication channel called topic. Every topic has a type that is actually the type of messages. So, to exchange multiple kinds of data, nodes use different topics with different types. Communication through topics differs from service based communication in two ways. First, a topic enables many-to-many communications since each topic can have multiple publishers and multiple subscribers. A message sent by a topic publisher is received by all topic subscribers. The second difference with services is that topic subscribers only consume received messages without providing any answer.

The code for ROS nodes is distributed as part of packages. A package is a coherent group of files that include binary code and other files. A single package can include the binary code for multiple nodes.

ROS packges are shared in groups called stacks. A typical stack gathers packages that collectively provide some functionality. An example is the navigation stack that allows to drive a robot based on 2D geometry.

Running ROS Nodes

Now, let’s consider the example of a simulated robot that we want to control through the keyboard. In this scenario, we have 2 nodes: the simulated robot and the keyboard-based driver. When an arrow key is pressed, the driver will send a command message with linear and rotation speed through a topic. The robot which is a subscriber of the same topic will receive the command and move accordingly.

The code of both nodes of our example is provided with ROS Fuerte in turtlesim package. But, before starting them, we need to launch first the infrastructure by evaluating in a terminal the following command line:
roscore

This first step is mandatory for any ROS application. Indeed, the roscore command runs a collection of nodes that are pre-requisites of any ROS-based system. One of these core nodes is the ROS master which allows other nodes discover each other. On startup, every node registers itself into the ROS master and requests information about other nodes.

Note: When running roscore, you will encounter an exception AttributeError(“‘_DummyThread’ object has no attribute ‘_Thread__block'”,). This issue is due to a known bug in python. It seem to have no impact on roscore, so you can simply ignore it.

Now, we can start the two nodes of our example. This can be done in any order. Let’s begin with the simulated robot. Evaluate the following command line in a new terminal:
rosrun turtlesim turtlesim_node

The command line relies on the rosrun utility provided by ROS. The first parameter is the name of the package which is turtlesim. The second parameter is the code of the node inside the given package. This command line runs the turtlesim_node.

Tip “Tab Completion”: There’s a completion support that use by pressing the “TAB” button of your keyboard. You can use it for the package name (first parameter) as well aas for the node (second parameter). It saves you from typing an entire name, or lists available alternatives if any.

The result of the previous command line is a blue window with a turtle standing still in the middle. What you get should be similar to Picture 1. The colors and the drawings of the turtle might differ. They actually change randomly on every launch.

wpid-wpid-turtleSimAtStartUp-2012-06-5-16-09-2012-11-26-19-21.png

Picture 1: Simulated Turtle Robot

To complete the example, you need to launch the driver node. To do so, evaluate the following command line in a third terminal:
rosrun turtlesim turtle_teleop_key

As with the simulated robot, we use here again the rosrun utility. We run the turtle_teleop_key node which code is available in the turtlesim package. Once this node is started, the application is ready. You can send speed commands to the simulated robot by pressing arrow keys in the terminal where you run the turtle_teleop_key node. The turtle robot should move accordingly. Et voilà! You have your first ROS-based system!

7 Comments

  • I am completely new to ROS. Just the second tutorial I was trying to follow. I typed in roscore and got the following result:

    viki@c3po:~$ roscore
    … logging to /home/viki/.ros/log/08a0c776-6f70-11e7-bec7-080027b46cdd/roslaunch-c3po-2191.log
    Checking log directory for disk usage. This may take awhile.
    Press Ctrl-C to interrupt
    Done checking log file disk usage. Usage is <1GB.

    started roslaunch server http://c3po:58836/
    ros_comm version 1.11.8

    SUMMARY
    ========

    PARAMETERS
    * /rosdistro: indigo
    * /rosversion: 1.11.8

    NODES

    auto-starting new master
    process[master]: started with pid [2230]
    ROS_MASTER_URI=http://c3po:11311/

    setting /run_id to 08a0c776-6f70-11e7-bec7-080027b46cdd
    process[rosout-1]: started with pid [2243]
    started core service [/rosout]

    I am stuck here as no further commands seem to respond.

    I am new to Ubuntu too. Kindly help

    Reply
    • You need to run every command in a new terminal. You’ll need 3 terminals for this tutorial.

      Reply
  • viki@c3po:~$ roscore
    … logging to /home/viki/.ros/log/08a0c776-6f70-11e7-bec7-080027b46cdd/roslaunch-c3po-2191.log
    Checking log directory for disk usage. This may take awhile.
    Press Ctrl-C to interrupt
    Done checking log file disk usage. Usage is <1GB.

    started roslaunch server http://c3po:58836/
    ros_comm version 1.11.8

    SUMMARY
    ========

    PARAMETERS
    * /rosdistro: indigo
    * /rosversion: 1.11.8

    NODES

    auto-starting new master
    process[master]: started with pid [2230]
    ROS_MASTER_URI=http://c3po:11311/

    setting /run_id to 08a0c776-6f70-11e7-bec7-080027b46cdd
    process[rosout-1]: started with pid [2243]
    started core service [/rosout]

    Reply
  • Hi Thanks so much for the image. I was able to run 32 image. Just want to know is it possible to run ros-husky with image 32, cz it gave me following errors.

    xacro.XacroException: Invalid parameter “topic” while expanding macro “sick_lms1xx”
    while processing /opt/ros/indigo/share/husky_gazebo/launch/spawn_husky.launch:
    Invalid tag: Cannot load command parameter [robot_description]: command [/opt/ros/indigo/share/xacro/xacro.py ‘/opt/ros/indigo/share/husky_gazebo/urdf/description.gazebo.xacro’ laser_enabled:=true ur5_enabled:=false kinect_enabled:=false ] returned with code [1].

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top