# Tutorial 1: ROS 2 Basics :::{admonition} Learning Objectives :class: learning-objs - 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 ` - Observing ROS2 system with RQT ::: ## Connecting to the Container --- :::{warning} The container `ros2-demo` must be running! See, [Using The ROS2 Demo Container](../../setup/using_container.md). ::: Open the tutorial_1 directory in VSCodium by directing your browser to: :::{div} url-callout ::: Or going to `File->Open Folder` in VSC and selecting `/home/robot/ros2-vsc-demo/tutorials/tutorial1`. ```{figure} /_static/images/getting_started_vsc_task.png :alt: placeholder :width: 60% :align: center VSCodium task to launch container's openvscode-server. ``` ## Running ROS 2 Nodes Build workspace: ::::{div} grouped-block ```console ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ colcon build ``` ```console Starting >>> mypkg1 ... Finished <<< mypkg1 [0.73s] Summary: 1 package finished [0.78s] ``` :::: Source workspace: ::::{div} grouped-block ```console ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ colcon build ``` ```console Starting >>> mypkg1 ... Finished <<< mypkg1 [0.73s] Summary: 1 package finished [0.78s] ``` :::: Open two shells and run the following: ::::{div} grouped-block ```console $ ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ ros2 run mypkg1 talker ``` ```console [INFO] [1779739548.456968934] [talker_node]: Publishing: "Hello World: 0" [INFO] [1779739548.937330081] [talker_node]: Publishing: "Hello World: 1" ... ``` :::: ::::{div} grouped-block ```console $ ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ ros2 run mypkg1 listener ``` ```console [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[[?]](tutorial_01.md#accessing-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: ```console $ cd tutorial_1_ws ``` Then, run: ::::{div} grouped-block ```console ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ colcon build ``` ```console Starting >>> mypkg1 ... Finished <<< mypkg1 [0.73s] Summary: 1 package finished [0.78s] ``` :::: Then source the built workspace: ```console ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ source install/setup.bash ``` And run the launch file: ::::{div} grouped-block ```console ~/ros2-vsc-demo/tutorials/tutorial1/tutorial_1_ws$ ros2 launch mypkg1 demo.launch.py ``` ```console [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" ... ``` ::::