This repository contains a ROS 2 + Gazebo project for autonomous right-wall following with the TurtleBot3 Burger using tabular Q-learning and SARSA.
The final system uses a manually discretized LiDAR state space, a compact action set, checkpointed training, quantitative reward logging, and a one-time test respawn strategy to demonstrate all required wall-following situations in the maze world.
- ROS 2 Jazzy project built around the TurtleBot3 Burger in Gazebo
- Two learning agents: Q-learning and SARSA
- Final compact 27-state right-wall representation based on three LiDAR sectors
- Five-action motion policy:
CRUISE,BANK_LEFT,BANK_RIGHT,HOOK_LEFT,HOOK_RIGHT - Training checkpoints and reward CSV logs for both algorithms
- Comparison plots for reward, episode length, and summary metrics
- Legacy hand-authored Q-table baseline also included for reference
The maze world used for training and evaluation is shown below.
The figure below compares training reward over the first 550 episodes for both methods.
Using the shared 550-episode comparison window from the final runs:
| Metric | Q-learning | SARSA |
|---|---|---|
| Average reward | 937.86 | 1052.43 |
| Best reward | 3891.77 | 3927.00 |
| Average episode length | 172.41 | 175.17 |
| Last-100 average reward | 1354.85 | 1861.07 |
| Last-100 average steps | 198.67 | 227.85 |
| Best wall-follow streak | 92 | 98 |
SARSA achieved the stronger overall result in the final matched comparison, while Q-learning remained competitive and reached strong peak rewards.
wall_following_ros2/
+-- checkpoints/ # Saved training checkpoints for both algorithms
+-- config/
¦ +-- bridge_topics.yaml # ROS <-> Gazebo bridge topics
¦ +-- generate_q_table.py # Helper for legacy Q-table generation
¦ +-- q_table.yaml # Legacy hand-authored Q-table
¦ +-- rl_params.yaml # Main RL hyperparameters and spawn settings
+-- doc/
¦ +-- img/
+-- launch/
¦ +-- rl_wall_following.launch.py # Main RL launch file
¦ +-- wall_following.launch.py # Legacy Q-table launch
+-- logs/ # Reward CSV files and generated comparison plots
+-- scripts/
¦ +-- q_learning_wall_follower.py
¦ +-- sarsa_wall_follower.py
¦ +-- rl_common.py # Shared training/testing logic
¦ +-- plot_rewards.py # Reward plotting helper
¦ +-- q_table_wall_follower.py # Legacy baseline controller
+-- worlds/
+-- largemaze.world
The final trained agents use a compact state representation:
F: front distance bucketRF: right-front distance bucketRB: right-back distance bucket
Each variable is discretized into three bins, producing 27 total states.
LiDAR is divided into three sectors:
- front:
350°to10° - right-front:
300°to340° - right-back:
200°to270°
The final action set is:
CRUISEBANK_LEFTBANK_RIGHTHOOK_LEFTHOOK_RIGHT
Default tuned configuration in config/rl_params.yaml:
alpha = 0.20gamma = 0.95epsilon_start = 0.55epsilon_decay = 0.992epsilon_min = 0.05max_episodes = 550max_steps_per_episode = 250target_distance = 0.60 mdistance_band = 0.20 m
This package assumes ROS 2 Jazzy and Gazebo with the TurtleBot3 simulation stack installed.
Main runtime dependencies include:
ros-jazzy-rclpyros-jazzy-ros-gz-bridgeros-jazzy-ros-gz-simros-jazzy-ros-gz-interfacesros-jazzy-turtlebot3-gazeboros-jazzy-nav2-bringupros-jazzy-rviz2ros-jazzy-robot-state-publisher
cd ~/ros2_ws_assignment2
source /opt/ros/jazzy/setup.bash
colcon build --packages-select wall_following_ros2
source install/setup.bashIf you use Conda, deactivate it first to avoid Python path conflicts:
conda deactivate 2>/dev/null || true
unset PYTHONPATH PYTHONHOME CONDA_PREFIX CONDA_DEFAULT_ENVros2 launch wall_following_ros2 rl_wall_following.launch.py algorithm:=q_learning mode:=trainros2 launch wall_following_ros2 rl_wall_following.launch.py algorithm:=sarsa mode:=trainros2 launch wall_following_ros2 rl_wall_following.launch.py algorithm:=sarsa mode:=train resume:=trueros2 launch wall_following_ros2 rl_wall_following.launch.py algorithm:=q_learning mode:=test resume:=trueros2 launch wall_following_ros2 rl_wall_following.launch.py algorithm:=sarsa mode:=test resume:=trueTraining writes:
- checkpoints to
checkpoints/q_learning/andcheckpoints/sarsa/ - reward CSV logs to
logs/q_learning_rewards.csvandlogs/sarsa_rewards.csv
Generated comparison plots currently include:
logs/training_reward_comparison_550.pnglogs/training_steps_comparison_550.pnglogs/algorithm_summary_comparison_550.png
The repository also keeps the earlier hand-crafted Q-table controller for comparison:
ros2 launch wall_following_ros2 wall_following.launch.pyThat controller is useful as a baseline, but the main project result is the RL-based right-wall-following system in rl_wall_following.launch.py.
- The project is centered on the package at the root of this repository.
- Reward logs and checkpoints are included because they document the final training runs.
- If you want a lighter public repository, you can trim old checkpoints and keep only
latest.yamlplus final plots.
Demo and report assets can be linked here:
- Video / drive folder: https://drive.google.com/drive/folders/1F6Jn4CsxW4kGzQGw0XMZueJe4_jBndT8?usp=sharing
Himanshu Ranjan

