This repository is created for team ROSpace to control a physical TurtleBot3 Waffle robot using ROS2 architecture. The project implements wall following, landmark detection, and autonomous navigation using colored markers.
This is a ROS2-based robotics project for the TurtleBot3 Waffle that includes:
- Wall Following: Navigate through maze environments by following walls
- Landmark Detection: Identify and track colored cylindrical markers using computer vision
- Autonomous Navigation: Navigate to waypoints using Nav2 stack
- Color Calibration: Tool for calibrating HSV color ranges for marker detection
- Mapping: SLAM-based mapping using cartographer
ROSpace-3431/
├── README.md # This file - project documentation
├── landmarks.csv # Detected landmark positions (x, y, marker_type)
├── map/ # Map files for navigation
│ ├── map.pgm # Occupancy grid map image
│ └── map.yaml # Map metadata (resolution, origin, thresholds)
└── src/ # Source code directory
├── color_retriever.py # Interactive color calibration tool
└── wall_follower/ # Main ROS2 package
├── CMakeLists.txt # CMake build configuration
├── package.xml # ROS2 package metadata
├── README # Launch instructions for the package
├── startup.bash # Automated startup script
├── landmarks.csv # Package-level landmarks file
├── waypoints.csv # Navigation waypoints (x, y coordinates)
├── config/ # Configuration files
│ └── waypoint_nav_params.yaml # Nav2 navigation parameters
├── launch/ # Launch files
│ ├── wall_follower.launch.py # Launch wall follower system
│ └── waypoint_navigator.launch.py # Launch navigation system
├── scripts/ # Python executable scripts
│ ├── see_marker.py # Vision-based marker detection
│ ├── point_transformer.py # Transform marker positions to map frame
│ └── waypoint_navigator.py # Autonomous waypoint navigation
├── src/ # C++ source files
│ └── wall_follower.cpp # Wall following algorithm
├── wall_follower/ # Python module
│ ├── __init__.py # Package initialization
│ └── landmark.py # Landmark data structures
├── include/ # C++ header files
├── model_editor_models/ # Gazebo simulation models
└── screenshots/ # Documentation images
landmarks.csv: Output file containing detected landmark positions in format:x,y,marker_typemap/map.pgm: Occupancy grid map generated from SLAM (Simultaneous Localization and Mapping)map/map.yaml: Map metadata including resolution (0.05m/pixel), origin coordinates, and occupancy thresholds
src/color_retriever.py: Interactive ROS2 node for HSV color range calibration- Subscribes to
/camera/image_rawtopic - Provides GUI for selecting color samples by clicking on pixels
- Supports calibration for 4 colors: Green (G), Blue (B), Yellow (Y), Pink (P)
- Outputs HSV color bounds for use in marker detection
- Controls:
- Click pixels to sample colors in current mode
G/B/Y/Pkeys: Switch between color modesCkey: Clear current color samplesOkey: Output color bounds to consoleESCkey: Exit application
- Subscribes to
src/wall_follower.cpp: Main wall following algorithm- Subscribes to
/scan(LaserScan) for distance sensing - Subscribes to
/odom(Odometry) for robot position - Publishes to
/cmd_vel(Twist) for robot motion control - Implements wall following behavior using laser scan data
- Uses PID-style control to maintain constant distance from walls
- Subscribes to
-
scripts/see_marker.py: Computer vision node for marker detection- Subscribes to
/camera/image_rawfor camera feed - Subscribes to
/scan(LaserScan) for distance measurements - Uses HSV color segmentation to detect colored markers
- Applies bilateral filtering for noise reduction
- Detects two-color cylindrical landmarks (e.g., yellow/pink, blue/pink)
- Publishes detected marker positions as
PointStampedmessages to/marker_position - Supports 6 marker types: yellow/pink, green/pink, blue/pink, pink/yellow, pink/green, pink/blue
- Subscribes to
-
scripts/point_transformer.py: Coordinate transformation node- Subscribes to
/marker_position(PointStamped) from see_marker.py - Uses TF2 to transform marker positions from camera frame to map frame
- Maintains running average of marker positions for stability
- Publishes
MarkerArrayvisualization messages for RViz - Saves landmark positions to
landmarks.csvon shutdown
- Subscribes to
-
scripts/waypoint_navigator.py: Autonomous navigation node- Uses Nav2 (Navigation2) stack for path planning and execution
- Reads waypoint coordinates from CSV file (configurable parameter)
- Sequentially navigates through all waypoints
- Monitors navigation task completion and handles failures
- Default waypoints file:
/home/troublemaker/comp3431/turtlebot_ws/landmarks.csv
wall_follower/landmark.py: Landmark data structures and utilities- Defines
Landmarkclass for storing marker information - Maintains position averaging for stable marker localization
- Creates RViz visualization markers (cylinders with two colors)
- Defines 6 marker types with color combinations
- Exports landmark data to CSV format
- Defines
config/waypoint_nav_params.yaml: Nav2 navigation parameters- Controller, planner, and behavior server configurations
- Robot footprint and collision checking parameters
- Path planning algorithms and tolerances
- Recovery behavior settings
-
launch/wall_follower.launch.py: Launches the wall following system- Starts three nodes simultaneously:
wall_follower(C++ node) - wall following controlsee_marker.py- marker detectionpoint_transformer.py- coordinate transformation
- Starts three nodes simultaneously:
-
launch/waypoint_navigator.launch.py: Launches autonomous navigation- Includes Nav2 navigation stack
- Starts waypoint navigator node
- Configurable parameters:
params_file: Navigation parameters YAMLmap: Map file pathwaypoints_file: CSV file with waypointsuse_sim_time: True for simulation, False for real robot
landmarks.csv: Package-level landmark storagewaypoints.csv: List of waypoint coordinates for navigation
This project requires:
- ROS2 (tested on ROS2 Humble or later)
- TurtleBot3 packages:
turtlebot3_gazebo- Simulation environmentturtlebot3_cartographer- SLAM functionalityturtlebot3_navigation2- Navigation stack
- Python packages:
rclpy- ROS2 Python client libraryopencv-python(cv2) - Computer visionnumpy- Numerical operationscv_bridge- ROS-OpenCV conversionnav2_simple_commander- Navigation interface
- C++ libraries:
rclcpp- ROS2 C++ client librarygeometry_msgs,nav_msgs,sensor_msgs- ROS2 message typestf2- Transform library
# Navigate to workspace root
cd /path/to/your/ros2_workspace
# Build the wall_follower package
colcon build --packages-select wall_follower
# Source the workspace
source install/setup.bashUse the provided startup script to launch all required components:
cd src/wall_follower
bash startup.bashThis script will:
- Launch TurtleBot3 in Gazebo maze environment
- Start cartographer for SLAM (mapping)
- Launch the wall follower system
Launch each component in a separate terminal:
Terminal 1 - Simulation Environment (skip for real robot):
ros2 launch turtlebot3_gazebo turtlebot3_maze.launch.pyTerminal 2 - SLAM/Mapping:
# For simulation:
ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
# For real robot:
ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=FalseTerminal 3 - Wall Follower:
ros2 launch wall_follower wall_follower.launch.pyOptional - Autonomous Navigation:
ros2 launch wall_follower waypoint_navigator.launch.py \
map:=/path/to/your/map.yaml \
waypoints_file:=/path/to/waypoints.csv \
use_sim_time:=true # or false for real robotTo calibrate colors for marker detection:
# Ensure robot/simulation is running with camera
python3 src/color_retriever.pyFollow the on-screen instructions to select color samples and export HSV bounds.
To visualize the robot, map, and detected markers:
rviz2In RViz:
- Set Fixed Frame to
map - Add displays for:
- RobotModel
- Map
- LaserScan
- MarkerArray (for visualizing detected landmarks)
- Path (for navigation trajectories)
x_coordinate,y_coordinate,marker_type_id
-0.045,-3.168,0
-0.071,-1.037,2
x_coordinate: X position in map frame (meters)y_coordinate: Y position in map frame (meters)marker_type_id: Integer 0-5 representing marker type
x_coordinate,y_coordinate
0.0,0.0
1.5,2.0
- Each line contains a waypoint coordinate in map frame
The system recognizes 6 two-color marker types: 0. Yellow/Pink (yellow top, pink bottom)
- Green/Pink
- Blue/Pink
- Pink/Yellow (pink top, yellow bottom)
- Pink/Green
- Pink/Blue
- No camera image: Check camera topic name in scripts (default:
/camera/image_raw) - Markers not detected: Recalibrate colors using
color_retriever.py - Navigation fails: Ensure map is loaded and robot is localized
- TF errors: Check that all transforms are being published correctly
Released under GPLv3. Most resources are written by UNSW demonstrators and students.
- Claude Sammut (Main contributor)
- UNSW COMP3431 Teaching Team
- Team ROSpace