NooTriX

Your First ROS based System

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!

Related Articles

6 Comments

  1. arif
    arif March 03, 08:00

    Great tutorial! Keep ’em coming please!

    Reply to this comment
  2. darkredhorse
    darkredhorse May 16, 09:03

    Great, simple, trouble-free first step
    Thanks

    Reply to this comment
  3. Shr
    Shr July 01, 21:39

    Excellent!

    Reply to this comment
  4. bongo
    bongo July 23, 07:15

    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 to this comment
  5. bongo
    bongo July 23, 07:20

    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 to this comment

Write a Comment

Related Posts

    Computers with Emotions Talk by Peter Robinson

Computers with Emotions Talk by Peter Robinson

1 comment Read Full Article
    Robots can Help Understand Humans Talk by Pierre Yves Oudeyer

Robots can Help Understand Humans Talk by Pierre Yves Oudeyer

0 comment Read Full Article
    Human-Level AI Talk by Murray Shanahan

Human-Level AI Talk by Murray Shanahan

0 comment Read Full Article
    Learn How Make Robots Hear and Localize Sound Sources

Learn How Make Robots Hear and Localize Sound Sources

0 comment Read Full Article
    Fast 3D Printing of Robot Parts

Fast 3D Printing of Robot Parts

0 comment Read Full Article
    How Many Actuators are Needed to Build a Robot?

How Many Actuators are Needed to Build a Robot?

0 comment Read Full Article
    Free Online Course on Developmental Robotics and AI

Free Online Course on Developmental Robotics and AI

0 comment Read Full Article
    Sharing USB Devices over Wifi using Arduino Yún

Sharing USB Devices over Wifi using Arduino Yún

2 comments Read Full Article
    Upgrade the Arduino Yún’s Linux

Upgrade the Arduino Yún’s Linux

4 comments Read Full Article
    ROS Indigo Igloo Preinstalled Virtual Machine

ROS Indigo Igloo Preinstalled Virtual Machine

27 comments Read Full Article
    PiBot: The Raspberry Pi-Based Robot

PiBot: The Raspberry Pi-Based Robot

0 comment Read Full Article
    Hands on the Arduino Yún

Hands on the Arduino Yún

0 comment Read Full Article
    Jimmy the 3D Printed Open Source Humanoid Robot Alternative to Nao

Jimmy the 3D Printed Open Source Humanoid Robot Alternative to Nao

1 comment Read Full Article
    How to Customize Your Turtlebot

How to Customize Your Turtlebot

0 comment Read Full Article
    Virtual Machine with ROS Hydro Medusa Pre-Installed

Virtual Machine with ROS Hydro Medusa Pre-Installed

33 comments Read Full Article
    A Robotic Elevator using Lego & Arduino – Part 4

A Robotic Elevator using Lego & Arduino – Part 4

1 comment Read Full Article
    Intelligent Robots Should Maximize Their Future Options

Intelligent Robots Should Maximize Their Future Options

0 comment Read Full Article
    Super Simple Robots for Weekend Projects

Super Simple Robots for Weekend Projects

0 comment Read Full Article
    A Robotic Elevator using Lego & Arduino – Part 3

A Robotic Elevator using Lego & Arduino – Part 3

0 comment Read Full Article

The Future of Human-Robot Interaction

Read Full Article