You are on page 1of 17

Robot Operating System 2 (ROS 2)

Lab 6: Multiple Machines Communications

Haitham El-Hussieny, PhD


August 13, 2023
Department of Mechatronics and Robotics Engineering
Egypt-Japan University of Science and Technology (E-JUST)
Alexandria, Egypt.
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

O UTLINE

1. ROS 2 on Multiple Machines

2. ROS2 Bag: Recording and playing ROS data

3. ROS2: Next Steps

1
ROS 2 on Multiple Machines
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

ROS 2 ON M ULTIPLE M ACHINES

ROS could run on multiple


machaines, including Nvidia
Jetson, Raspberry Pis, etc.
The devices should be
connected to the same network
to see each others.

2
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

ROS 2 ON M ULTIPLE M ACHINES

To check if both machines are connected:


On Machine 1:
$ hostname -I
returns 192.168.43.138
On Machine 2:
$ hostname -I
returns 192.168.43.56
Ping other machine from one of the
machines.

3
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

R UN ROS2 ON 2 MACHINES

Start some nodes in Machine 1,


Machine 1
$ ros2 run demo nodes cpp talker

Start another node on Machine 2,


Machine 2
$ ros2 run demo nodes cpp listener
And you should see logs on both machines!

4
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

U SE OF ROS DOMAIN ID

ROS DOMAIN ID is new in ROS 2 that


allows you to seperate ROS applications
that can be communicated.
By default, ROS DOMAIN ID = 0.
Nodes having the same
ROS DOMAIN ID can coomunicate to
each others.

5
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

U SE OF ROS DOMAIN ID

6
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

U SE OF ROS DOMAIN ID

7
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

U SE OF ROS DOMAIN ID

On one terminal run a node with ROS DOMAIN ID=1


$ export ROS DOMAIN ID=1
$ ros2 run turtlesim turtlesim node

On another terminal try to list the ROS topics.


$ ros2 topic list

You will not see any turtlesim related topics due to different ROS ID.
Now change the ROS DOMAIN ID=1 on the second terminal:
$ export ROS DOMAIN ID=1
$ ros2 topic list

You should see the turtlesim topics.

8
ROS2 Bag: Recording and
playing ROS data
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

ROS2 BAG : R ECORDING AND PLAYING ROS DATA

ROS2 Bag
This is a set of tools for recording from and playing
back ROS topics.
To record ros topics:
$ ros2 bag record

To playback a ros topics:


$ ros2 bag play <name of bag
file>

9
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

ROS2 BAG : R ECORDING AND PLAYING ROS DATA

1. Start roscore.
2. Run the turtlebot simulator
$ ros2 run turtlsim turtlesim node
3. Run the keyboard teleoperation:
$ ros2 run turtlesim
turtle teleop key

4. make a temporary directory:


$ mkdir ros bag files

5. Record all topics:


$ ros2 bag record -a

6. To record selective topics


$ ros2 bag record -o subset
/turtle1/cmd vel /turtle1/pose 10
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

ROS2 BAG : R ECORDING AND PLAYING ROS DATA

To play a bag file


$ ros2 bag play <name of bag file>

To play a bag file with rate x 2


$ ros2 bag play -r 2 <name of bag
file>
To play the bag file in a loop
$ ros2 bag play -l <name of bag
file>

11
ROS2: Next Steps
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

ROS2: N EXT S TEPS

Future steps:

ROS2 on Jetson Nano, Rasbperry Pi 4.


ROS2 Navigation Stack.
ROS2 Moveit for manipulation.

12
ROS 2 on Multiple Machines ROS2 Bag: Recording and playing ROS data ROS2: Next Steps

End of Lecture

haitham.elhussieny@ejust.edu.eg

13

You might also like