# ROS components

# What is ROS?

ROS is an open-source, meta-operating system for your robot. It provides the services you would expect from an operating system, including hardware abstraction, low-level device control, implementation of commonly-used functionality, message-passing between processes, and package management. It also provides tools and libraries for obtaining, building, writing, and running code across multiple computers. http://www.ros.org

ROS is similar in some respects to 'robot frameworks,' such as Player, YARP, Orocos, CARMEN, Orca, MOOS, and Microsoft Robotics Studio.

The ROS runtime "graph" is a peer-to-peer network of processes (potentially distributed across machines) that are loosely coupled using the ROS communication infrastructure. ROS implements several different styles of communication, including synchronous RPC-style communication over services, asynchronous streaming of data over topics, and storage of data on a Parameter Server. These are explained in greater detail in our Conceptual Overview.

ROS is not a realtime framework, though it is possible to integrate ROS with realtime code. The Willow Garage PR2 robot uses a system called pr2_etherCAT, which transports ROS messages in and out of a realtime process. ROS also has seamless integration with the Orocos Real-time Toolkit.

In sections below the different kinds of ros components are handled. Each time illustrated with an example on the turtlesim:

The following compenents will be handled:

  • roscore
  • rosnode
  • rostopic
  • rosservice
  • rosparam

# roscore

The roscore command starts ROS and creates the Master so that ROS nodes can communicate.

The ROS master coordinates the communication between the different ROS nodes (processes). Each ROS node registers with the ROS master at start-up. The ROS master can/should be started via the command.

roscoreis a collection of nodes and programs that are pre-requisites of a ROS-based system. You must have a roscore running in order for ROS nodes to communicate. It is launched using the roscore command.

roscore will start up:

  • ROS Master
  • ROS Parameter Server
  • rosout logging node

WARNING

There can only be one ROS master. When starting up a 2nd ROS master, the first ROS master is turned off.

Add the roscore in the container terminal

root@74b5eecc7ce2:/# roscore	
1

WARNING

Make sure that you work in the container environment!

WARNING

Leave this window active but minimized so that the ROS Master is still available.

Output

Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://127.0.0.1:46711/
ros_comm version 1.14.11


SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.11

NODES

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

setting /run_id to eb2d08e8-89ab-11ec-a6d9-0242ac110002
process[rosout-1]: started with pid [128]
started core service [/rosout]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

TIP

If you use roslaunch, it will automatically start roscore if it detects that it is not already running. For this tutorial we won't be using roslaunch.

source: wiki ros (opens new window)

# rosnode

A ROS node is an executable program (executable file) contained in a ROS package. The ROS nodes use the ROS client library which allows to communicate with other nodes. Nodes can publish or subscribe to one or more topics. Nodes can also offer or use a service. There are 2 types of client libraries:

  • rospy: python client library
  • roscpp: c++ client library
  • or others (java, lsp,...)

We will start the turtlesim node and explore its properties. Execute a turtlesim node in a new container terminal from the package turtlesim.

WARNING

roscore should already be running otherwise you will receive an error

roscore
1

Connect with the Docker container with a new container terminal.

docker exec -it turtlesim_cont bash
1

Start the turtlesim node with rosrun:

rosrun turtlesim turtlesim_node 
1

Output

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
[ INFO] [1644570735.732915989]: Starting turtlesim with node name /turtlesim
[ INFO] [1644570735.735655326]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
1
2
3
4
5

The rosrun command takes the arguments [package name] [node name].

The node creates the screen image and the turtle.

drawing

Here the turtle is in the center in x = 5.5, y = 5.5with no rotation.

Before moving the turtle, let's study the properties of the node available with turtlesim package in another container terminal.

# Get node list

With argument list we can look up the existing/active ROS nodes. Execute this command again in a new terminal connected to the container.

docker exec -it turtlesim_cont bash
1

Add the command below in the new terminal:

rosnode list
1

Output

/rosout 
/turtlesim 
1
2

We can see that there are 2 ros nodes active.

Important

Note the difference in notation between the node /turtlesim and the package turtlesim.

# Get info of node

To get the info of the turtlesim node add the command in the container terminal. Reuse the terminal of the previous step.

rosnode info /turtlesim 
1

Output

--------------------------------------------------------------------------------
Node [/turtlesim]
Publications: 
 * /rosout [rosgraph_msgs/Log]
 * /turtle1/color_sensor [turtlesim/Color]
 * /turtle1/pose [turtlesim/Pose]

Subscriptions: 
 * /turtle1/cmd_vel [unknown type]

Services: 
 * /clear
 * /kill
 * /reset
 * /spawn
 * /turtle1/set_pen
 * /turtle1/teleport_absolute
 * /turtle1/teleport_relative
 * /turtlesim/get_loggers
 * /turtlesim/set_logger_level


contacting node http://127.0.0.1:33755/ ...
Pid: 252
Connections:
 * topic: /rosout
    * to: /rosout
    * direction: outbound (47461 - 127.0.0.1:38932) [16]
    * transport: TCPROS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# rosservice

A ROS service is an example of synchronous communication. It is based on the Request and Response system. Some ROS nodes provide a ROS service with a specific name. Clients can request a request from the service and have to wait for a response. The principle of communication can be compared to a telephone conversation between 2 ROS nodes. However, this is intended for short-term communication between 2 nodes.

# Get ROS services

To get all the supported services of a rosnode. Use the command below.

rosnode info /turtlesim 
1

Output

...
Services: 
 * /clear
 * /kill
 * /reset
 * /spawn
 * /turtle1/set_pen
 * /turtle1/teleport_absolute
 * /turtle1/teleport_relative
 * /turtlesim/get_loggers
 * /turtlesim/set_logger_level
...
1
2
3
4
5
6
7
8
9
10
11
12

The turtlesim node supports 9 services.

With these services we can read out the node but also command the node depending on the feature.

The format of a rosservice call rosservice <service> <arguments> is the following

The turtle can be moved using the rosservice teleport option. The format of the position is [x y theta].

To get the info of a specific rosservice use the command below:

rosservice info /spawn
1

Output:

Node: /turtlesim
URI: rosrpc://127.0.0.1:47461
Type: turtlesim/Spawn
Args: x y theta name
1
2
3
4

# Example rosservices turtlesim

Teleport_absolute

The absolute teleport option moves the turtle to the absolute position in de screen. The arguments are [x y theta].

rosservice call /turtle1/teleport_absolute 1 1 0 
1

drawing

teleport_relative

The relative teleport option moves the turtle with respect to its present position. The arguments are [linear angle].

rosservice call /turtle1/teleport_relative  1 0 
1

drawing

Exercise 1

Try to move the turtle to location x=2, y=1.

Solution Exercise 1
rosservice call /turtle1/teleport_absolute 2 1 0 
1

Exercise 2

Try to change the pen color of the turtle.

TIP

Look for set_pen

Solution Exercise 2

Get the info of the service:

rosservice info /turtle1/set_pen
1

Output

Node: /turtlesim
URI: rosrpc://127.0.0.1:47461
Type: turtlesim/SetPen
Args: r g b width off
1
2
3
4
rosservice call /turtle1/set_pen 100 150 100 3 0
1

# rostopic

ROS nodes can communicate with each other via ROS topics. ROS nodes can publish a ROS Topic but can also subscribe (subscribe) to an existing ROS topic. In most cases there is one publisher and several subscribers. The topics are streamed asynchronously. It can be compared to a chat room.

The node /turtlesim publishes three topics and subscribes to the /turtle1/cmd_vel topic.

# Examples rostopics

Turtlesim pose

A interesting topic of turtlesim node is the turtles pose (position). This is the x, y position, angular direction, and the linear and angular velocity of the turtle.

The following command gives insight in following items:

  • Type of the topic
  • How is publishing the topic
  • How is subscribed to the topic

We start with the turtlesim pose topic:

rostopic info /turtle1/pose 
1

Output

Type: turtlesim/Pose

Publishers: 
* /turtlesim (http://127.0.0.1:33755/)

Subscribers: None
1
2
3
4
5
6

A rostopic is always based on a rosmsg (ROS message) structure.

To get the ROS message name used by the ROS topic use the command below.

rostopic type /turtle1/pose 
1

Output:

turtlesim/Pose
1

To get the specific structure of the ros message use the command below.

rosmsg show turtlesim/Pose 
1

Output:

turtlesim/Pose
root@74b5eecc7ce2:/# rosmsg show turtlesim/Pose
float32 x
float32 y
float32 theta
float32 linear_velocity
float32 angular_velocity
1
2
3
4
5
6
7

To read the actual values of the ROS topic use the rostopic echo command:

rostopic echo /turtle1/pose 
1

Output:

x: 6.0
y: 1.0
theta: 0.0
linear_velocity: 0.0
angular_velocity: 0.0
---
x: 6.0
y: 1.0
theta: 0.0
linear_velocity: 0.0
angular_velocity: 0.0
---
1
2
3
4
5
6
7
8
9
10
11
12

We get a continuous output of the position, orientation, and velocities. Compare to the position on the turtle window. To stop the output press CTRL+C.

Extra info: http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics (opens new window)

# rosparam

ROS parameters allows data to be stored via key/name in a central location. This means that these parameters are globally visible.

ROS parameters are intended to store configuration data:

  • Update hardware drivers
  • Algorithms Adjustment

WARNING

rosparam is not intended for high polling rates. Also not intended for queries.

To get an overview of the existing rosparam use the list argument.

rosparam list
1

Output

/rosdistro
/roslaunch/uris/host_127_0_0_1__46711
/rosversion
/run_id
/turtlesim/background_b
/turtlesim/background_g
/turtlesim/background_r

1
2
3
4
5
6
7
8

# Read a parameter value

We want to get parameters and change color of background to red.

rosparam get /turtlesim/background_r
1

The response will be the red value of the background.

TIP

use Tab to get the available rosparams

To change a rosparam use the argument set

rosparam set /turtlesim/background_r 0
1

# Set a parameter value

This changes the parameter value, now we have to call the clear service for the parameter change to take effect:

rosservice call /clear
1

# Other components

This tutorial doens't handled all the ros components, sorry. Feel free to surf the ROS wiki (opens new window) pages: