Autonomous Systems Course · CRTA Lab, University of Zagreb
This repository contains a template for the first laboratory exercise. The goal is to implement a ROS 2 node that subscribes to one or more topics and logs the received data to the terminal and/or a file using ROS 2 logging utilities.
Before you begin, make sure the following are installed on your system:
- Ubuntu 22.04 (recommended) or a compatible Linux distribution
- ROS 2 Humble (or the distro specified by your instructor)
- Python 3.10+
- colcon build tool
If ROS 2 is not yet installed, follow the official guide: https://docs.ros.org/en/humble/Installation.html
If you do not already have a workspace, create one with the following commands:
mkdir -p ~/ros2_ws/src
cd ~/ros2_wsSource your ROS 2 installation (add this to ~/.bashrc to avoid repeating it):
source /opt/ros/humble/setup.bashClone the package into the src directory of your workspace:
cd ~/ros2_ws/src
git clone https://github.com/CRTA-Lab/lab1_logger_exercise.gitYour workspace structure should now look like this:
ros2_ws/
└── src/
└── lab1_logger_exercise/
├── lab1_logger_exercise/
├── resource/
├── test/
├── package.xml
├── setup.cfg
└── setup.py
From the root of your workspace, install any declared dependencies:
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -yBuild the workspace using colcon:
cd ~/ros2_ws
colcon build --symlink-installAfter a successful build, source the local workspace overlay:
source install/setup.bashTip: Add
source ~/ros2_ws/install/setup.bashto your~/.bashrcso you don't have to source it manually every time.
Once built, run the logger node with:
ros2 run lab1_logger_exercise <node_name>Replace <node_name> with the entry point defined in setup.py (e.g. logger_node).
The exercise is split into two parts. Both nodes are provided as templates — your job is to fill in the missing logic marked with # Fill.
Implement a ROS 2 node that subscribes to the /odom topic and saves the robot's position and orientation to a CSV file.
- Subscribe to
/odom(nav_msgs/msg/Odometry) - On every received message, extract:
- x — position along the X axis (
pose.pose.position.x) - y — position along the Y axis (
pose.pose.position.y) - yaw — heading angle, converted from quaternion to Euler angles
- x — position along the X axis (
- Append each row to a CSV file in the format:
x,y,yaw
1.234,0.567,0.312
...
- On node shutdown (
Ctrl+C), close the CSV file cleanly and display a trajectory plot of the recorded path (x vs y).
Terminal 1 — start the logger node:
ros2 run lab1_logger_exercise logger_nodeTerminal 2 — play back the provided ROS bag file:
ros2 bag play <path_to_bag_file>Once the bag file finishes playing, press Ctrl+C in Terminal 1 to stop the logger node. A plot of the recorded trajectory will appear automatically.
Implement a ROS 2 node that reads the CSV file saved in Part 1 and publishes the recorded trajectory as a nav_msgs/msg/Path message in the odom frame.
- Read the CSV file generated by the logger node
- For each row, create a
geometry_msgs/msg/PoseStampedwith:header.frame_id = "odom"pose.position.xandpose.position.yfrom the CSVpose.orientationconverted back from yaw to quaternion
- Publish the full list of poses as a
nav_msgs/msg/Pathon the/pathtopic
Make sure the CSV file from Part 1 exists, then run:
ros2 run lab1_logger_exercise path_publisher_nodeTo visualise the published path, open RViz2 in a separate terminal:
rviz2In RViz2:
- Set the Fixed Frame to
odom - Add a Path display and set its topic to
/path
You should see the recorded trajectory rendered in the odom frame.
Logger node:
- Subscribes to
/odomand writesx,y,yawrows to a CSV file - Closes the file and shows a trajectory plot on
Ctrl+C
Path publisher node:
- Reads the CSV file and publishes a valid
nav_msgs/msg/Pathon/path - Path is correctly visualised in RViz2 in the
odomframe
# Check that /odom is being published during bag playback
ros2 topic echo /odom
# Verify the path is being published
ros2 topic echo /path
# List all active topics
ros2 topic list| Path | Description |
|---|---|
lab1_logger_exercise/ |
Main Python package containing node source files |
resource/ |
Package resource marker (required by ament) |
test/ |
Unit and integration tests |
package.xml |
Package metadata and dependencies |
setup.py |
Python package build configuration |
setup.cfg |
Entry points and install settings |
This project is licensed under the Apache License 2.0. See LICENSE for details.

