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:
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.
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!
This site uses Akismet to reduce spam. Learn how your comment data is processed.