Unit 03 · lesson

Run Reusable Nodes More Than Once

This lesson is about a design idea hidden inside a fun simulator.

A good ROS node can often be reused in more than one place when its runtime names and configuration are separated from its code.

Create a second turtle

With /turtlesim running, you can use the /spawn service through rqt or, after Unit 5, through the CLI. If using rqt now, open:

rqt

Choose Plugins → Services → Service Caller, select /spawn, and create a uniquely named turtle such as turtle2.

Start another teleop node

If you simply run another default teleop executable, it still targets turtle1.

Instead use the remapping command from the official Turtlesim tutorial:

ros2 run turtlesim turtle_teleop_key \
  --ros-args \
  --remap turtle1/cmd_vel:=turtle2/cmd_vel \
  --remap turtle1/rotate_absolute:=turtle2/rotate_absolute

Now one copy can control turtle1 and another can control turtle2.

Inspect the graph

Run:

ros2 node list
ros2 topic list

Open rqt_graph and compare the new graph to the simpler one-turtle system.

The engineering lesson

Do not summarize this as "ROS can make two turtles."

The useful lesson is:

runtime names/remaps let reusable executables participate in different parts of a larger graph.

Checkpoint

Explain which parts were duplicated and which were changed:

Executable code:
Running process/node instance:
Target topic names:
Visible graph: