Skip to the content.

ROS 2 Course Repository

Official repository for the ROS 2 course taught at Tecnológico de Monterrey, Campus Guadalajara. This course is designed for students in the Robotics and Intelligent Systems Engineering program and aims to provide a solid foundation in the use and development of ROS 2 Humble applications.

Instructions to launch the ROS 2 Packages

1. Running ROS 2 Examples

Examples to Try

Talker-Listener

After installing ros-humble-desktop (and optionally Terminator), try the following:

You should observe that the talker publishes messages and the listener confirms their reception.

Turtlesim: Publish and Move a Turtle

Another example is provided by the turtlesim package:

Use the arrow keys to move the turtle. This example demonstrates publishing velocity commands to control the simulated turtle.

Evidence: Example screenshot showing terminal outputs from both the Talker-Listener example and the Turtlesim node example in action. Figure: Example screenshot showing terminal outputs from both the Talker-Listener example and the Turtlesim node example in action.

2. Running ROS 2 Nodes

Executing ROS 2 Publishers and Subscribers

Running the Python Publisher and Subscriber

After implementing and saving your Python nodes and updating package.xml and setup.py files, build your package and run the nodes. In two separate terminal sessions (or using the Terminator emulator), execute the following commands from the root of your workspace:

You should observe that the py_publisher node sends a personalized message (e.g., displaying your name), and the py_subscriber node awaits the reception of the messages.

Running the C++ Publisher and Subscriber

After implementing and saving your C++ nodes and updating package.xml and CMakeLists.txt files, build your package and run the nodes. In two additional terminal sessions (or another two sessions in Terminator), execute the following commands from the root of your workspace:

You should observe that the py_publisher node publishes your personalized message (e.g., displaying your name), and the cpp_subscriber node confirms its reception. Likewise, the cpp_publisher node publishes your other personalized message, and the py_subscriber node confirms its reception.

Visualizing the ROS Graph with rqt_graph

To ensure that your publisher and subscriber nodes are correctly connected, use the rqt_graph tool. In Terminal 5, execute the following command (no need to enter your workspace directory):

ros2 run rqt_graph rqt_graph

or simply:

rqt_graph

This visualization should show the topics connecting your publisher and subscriber nodes.

Evidence: Example screenshot showing terminal outputs of the publisher and subscriber nodes, in C++ and Python, in action. Figure: Example screenshot showing terminal outputs of the publisher and subscriber nodes, in C++ and Python, in action.

3. Running ROS 2 Services and Clients

Executing ROS 2 Services and Clients

Running the Python Service and Client

After implementing and saving your Python nodes and updating the package.xml and setup.py files, build your package and run the nodes. In three separate terminal sessions (or using the Terminator emulator), execute the following commands from the root of your workspace:

You should observe that the py_server node processes service requests from both the py_client node and the command-line client in Terminal 3.

Running the C++ Service and Client

After implementing and saving your C++ nodes and updating the package.xml and CMakeLists.txt files, build your package and run the nodes. In three additional terminal sessions (or three new sessions in Terminator), execute the following commands from the root of your workspace:

You should observe that the cpp_server node processes service requests from both the cpp_client node and the command-line client in Terminal 6.

Requesting a Service Using rqt_service_caller

Use the rqt_service_caller tool to send service requests to both the Python and C++ servers. In Terminal 7, run:

ros2 run rqt_service_caller rqt_service_caller

Then, request a service call for:

You should observe that the py_server and cpp_server nodes successfully process the service requests sent via rqt_service_caller.

Evidence: Example screenshot showing terminal outputs from the servers and clients in action. Figure: Example screenshot showing terminal outputs from the servers and clients in action.

4. ROS 2 Custom .msg and .srv Files

Executing ROS 2 Publishers, Subscribers, Services, and Clients

After editing and saving your custom .msg and .srv files, and updating your C++ and Python nodes along with CMakeLists.txt, setup.py, and package.xml, build the packages:

colcon build --packages-select s4_custom_interface
colcon build --packages-select s4_cpp_apps
colcon build --packages-select s4_py_apps

Then, in eight separate terminal sessions (or using the Terminator emulator), source your ROS 2 workspace in each terminal and run the nodes as follows:

You should observe the following:

  1. The py_publisher node publishes the custom HardwareStatus and Sphere messages.
  2. The py_subscriber node receives the HardwareStatus message from the cpp_publisher and the Sphere message from the py_publisher.
  3. The py_server node processes the service request from the py_client node.
  4. The cpp_publisher node publishes the custom HardwareStatus and Sphere messages.
  5. The cpp_subscriber node receives the HardwareStatus message from the py_publisher and the Sphere message from the cpp_publisher.
  6. The cpp_server node processes the service request from the cpp_client node.

Visualizing the ROS Graph with rqt_graph

To verify that all nodes are correctly connected, use the rqt_graph tool.

In Terminal 9, run:

ros2 run rqt_graph rqt_graph

or simply:

rqt_graph

This will display a graph of all publishers, subscribers, and services, confirming proper communication and node topology.

Evidence 1: Example screenshot showing terminal outputs of the publishers, subscribers, services, and clients, in C++ and Python, in action. Figure: Example screenshot showing terminal outputs of the publishers, subscribers, services, and clients, in C++ and Python, in action.

Evidence 2: Example screenshot showing the ROS 2 graph of the publisher, subscriber, and service nodes. Figure: Example screenshot showing the ROS 2 graph of the publisher, subscriber, and service nodes.

5. ROS 2 Parameters, YAML, and Launch Files (Image Acquisition)

Executing ROS 2 Image Publishers and Subscribers

After editing and saving your C++ and Python nodes, and updating the CMakeLists.txt, setup.py, and package.xml files, build the packages:

colcon build --packages-select s5_cpp_camera
colcon build --packages-select s5_cpp_camera_usr
colcon build --packages-select s5_py_camera
colcon build --packages-select s5_py_camera_usr

Then, in three separate terminal sessions (or using the Terminator emulator), source your ROS 2 workspace in each terminal and run the following:

You should observe that:

  1. The cpp_camera or py_camera node publishes the image message.
  2. Both cpp_camera_usr and py_camera_usr nodes receive the image message.

Visualizing the Image Topic with rqt_image_view

To verify that the publisher is correctly publishing the image topic, use:

ros2 run rqt_image_view rqt_image_view

This will display the image stream from either the C++ or Python image publisher node.


Visualizing the ROS Graph with rqt_graph

To ensure that the publisher and subscriber nodes are correctly connected, run in a new terminal:

ros2 run rqt_graph rqt_graph

Or simply:

rqt_graph

This will show the image topic being published and subscribed to, confirming proper ROS 2 graph connectivity.

Evidence 1: Example screenshot showing terminal outputs of the publisher and subscribers, in C++ and Python, in action. Figure: Example screenshot showing terminal outputs of the publisher and subscribers, in C++ and Python, in action.

Evidence 2: Example screenshot showing the image windows and the ROS 2 graph of the publisher and subscriber nodes. Figure: Example screenshot showing the image windows and the ROS 2 graph of the publisher and subscriber nodes.

6. URDF Modeling and Launch Files (Robot States)

Executing ROS 2 Robot State Publishers

After editing and saving your C++ and Python nodes, and updating the CMakeLists.txt, setup.py, and package.xml files, build the packages:

colcon build --packages-select s6_cpp_urdf
colcon build --packages-select s6_py_urdf

Then, in two terminals, source the workspace environment and run:

You should observe:

  1. The robot_state_publisher node publishing the URDF model and TFs.
  2. The rdk_x3_robot node publishing joint states for dynamic updates in RViz.

Visualizing the Frames with view_frames

To view the coordinate frame hierarchy, run:

ros2 run tf2_tools view_frames

This will generate a PDF file in the current directory, showing the TF tree published by the robot’s robot_state_publisher node.


Visualizing the ROS Graph with rqt_graph

To verify that the robot state publisher nodes are correctly connected, use:

ros2 run rqt_graph rqt_graph

Or simply:

rqt_graph

This will show the joint_states topic and how the publisher nodes are linked.

Evidence 1: Example screenshot showing terminal outputs and the ROS 2 graph of the robot state publishers in action. Figure: Example screenshot showing terminal outputs and the ROS 2 graph of the robot state publishers in action.

Evidence 2: PDF showing the graphical representation of the current coordinate frame tree. Figure: PDF showing the graphical representation of the current coordinate frame tree.

Evidence 3: Example screenshot showing the simulation of the RDK X3 Robot in RViz. Figure: Example screenshot showing the simulation of the RDK X3 Robot in RViz.

7. tf2 Library (Robot Network)

Executing ROS 2 Robot Status Publishers

After editing and saving the Python nodes and updating the CMakeLists.txt, setup.py, and package.xml files, build the packages:

colcon build --packages-select s7_robot_network_interface
colcon build --packages-select s7_py_task_manager
colcon build --packages-select s7_py_client_robot
colcon build --packages-select s7_py_robot_task_monitoring

Then, in five terminals, source your ROS 2 workspace in each and execute:

You should observe:

  1. The task_manager node processing service requests from the robot1 client.
  2. The cylinder1/robot_state_publisher and cylinder2/robot_state_publisher publishing pickup/delivery poses.
  3. The robot1/robot_state_publisher broadcasting robot1’s URDF model and TFs.
  4. The cylinders node broadcasting TFs for pickup and delivery poses.
  5. The robots node publishing robot1’s status and joint states.
  6. The robot_status_logger node printing the robot status when data is received.

Visualizing the Frame Tree with view_frames

To observe the current frame hierarchy, use:

ros2 run tf2_tools view_frames

This generates a PDF file in the current terminal directory, representing the current TF tree.


Visualizing the ROS Graph with rqt_graph

To verify the node connections, run:

ros2 run rqt_graph rqt_graph

Or:

rqt_graph

This shows the connections between all publishers, subscribers, services, and clients in the robot network.

Evidence 1: Example screenshot showing terminal outputs and the ROS 2 graph of the robot network in action. Figure: Example screenshot showing terminal outputs and the ROS 2 graph of the robot network in action.

Evidence 2: PDF showing the graphical representation of the current coordinate frame tree. Figure: PDF showing the graphical representation of the current coordinate frame tree.

Evidence 3: Example screenshot showing the visualization of the RDK X3 Robot1 in RViz. Figure: Example screenshot showing the visualization of the RDK X3 Robot1 in RViz.

8. Occupancy Grid Map (SLAM Simulation)

Executing ROS 2 SLAM Simulation

After editing the Python nodes and updating CMakeLists.txt, setup.py, and package.xml, build the package:

colcon build --packages-select s8_py_slam

Then, in five separate terminals, source your workspace and run:

You should observe:

  1. The robot URDF model is spawned in Gazebo with a LiDAR plugin.
  2. The robot_state_publisher node visualizes the robot in RViz.
  3. An occupancy grid is built and displayed through the /map topic in RViz as the robot explores the environment.

Visualizing Frame Tree with view_frames

To generate a TF frame tree PDF:

ros2 run tf2_tools view_frames

This creates a frames.pdf in the current directory.


Visualizing the ROS Graph with rqt_graph

To check node and topic connections:

ros2 run rqt_graph rqt_graph

Or simply:

rqt_graph

This displays the complete ROS 2 graph for the SLAM setup.

Evidence 1: Example screenshot showing terminal outputs and the ROS 2 graph of the SLAM simulation in action. Figure: Terminal outputs and ROS 2 graph of the SLAM simulation.

Evidence 2: PDF showing the graphical representation of the current coordinate frame tree. Figure: PDF showing the current coordinate frame tree.

Evidence 3: Example screenshot showing the simulation of the RDK X3 Robot in Gazebo. Figure: Simulation of the RDK X3 Robot in Gazebo.

Evidence 4: Example screenshot showing the visualization of the RDK X3 Robot in RViz. Figure: Visualization of the RDK X3 Robot in RViz.