Tutorial 1: ROS 2 Basics#

Learning Objectives

  • How to use common ros2 CLI commands

  • Running ROS 2 nodes with ros2 run

  • Launching ROS2 nodes with ros2 launch

  • Observing ROS2 system with ros2 <topic|node>

  • Observing ROS2 system with RQT

Connecting to the Container#


Warning

The container ros2-demo must be running! See, Using The ROS2 Demo Container.

Open the tutorial_1 directory in VSCodium by directing your browser to:

Or going to File->Open Folder in VSC and selecting /home/robot/ros2-vsc-demo/tutorials/tutorial1.

placeholder

VSCodium task to launch container’s openvscode-server.#

Running ROS 2 Nodes#

Build workspace:

~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ colcon build
Starting >>> mypkg1 
...
Finished <<< mypkg1 [0.73s]          

Summary: 1 package finished [0.78s]

Source workspace:

~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ colcon build
Starting >>> mypkg1 
...
Finished <<< mypkg1 [0.73s]          

Summary: 1 package finished [0.78s]

Open two shells and run the following:

$ ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ ros2 run mypkg1 talker 
[INFO] [1779739548.456968934] [talker_node]: Publishing: "Hello World: 0"
[INFO] [1779739548.937330081] [talker_node]: Publishing: "Hello World: 1"
...
$ ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ ros2 run mypkg1 listener 
[INFO] [1779739598.667475455] [talker_node]: Publishing: "Hello World: 0"
[INFO] [1779739599.157543411] [talker_node]: Publishing: "Hello World: 1"
...

Caution

Each shell must have the workspace sourced for commands like ros2 run to know where to find the packages and nodes!.

Launch ROS 2 Nodes#

Before we observe a ROS 2 system we need to have one! We will use a launch file

To do this, open a shell[?] in the container.

In the directory /home/robot/ros2-vsc-demo/tutorials/tutorial1 there will be a directory tutorial_1_ws.

cd into that directory by running:

$ cd tutorial_1_ws

Then, run:

~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ colcon build
Starting >>> mypkg1 
...
Finished <<< mypkg1 [0.73s]          

Summary: 1 package finished [0.78s]

Then source the built workspace:

~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ source install/setup.bash

And run the launch file:

~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ ros2 launch mypkg1 demo.launch.py 
[INFO] [launch]: All log files can be found below /home/robot/.ros/log/2026-05-25-19-59-51-613584-06d685a94a45-34527
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [talker-1]: process started with pid [34530]
[INFO] [listener-2]: process started with pid [34531]
[talker-1] [INFO] [1779739192.331062106] [talker_node]: Publishing: "Hello World: 0"
[listener-2] [INFO] [1779739192.331352416] [listener_node]: I heard: "Hello World: 0"
[talker-1] [INFO] [1779739192.826401701] [talker_node]: Publishing: "Hello World: 1"
[listener-2] [INFO] [1779739192.827032251] [listener_node]: I heard: "Hello World: 1"
...