This repository contains the code for simulating dynamic window approach (DWA) for Turtlebot3 Waffle in Gazebo. The algorithm logic is based on the amazing robotics library AtsushiSakai/PythonRobotics and the paper on The Dynamic Window Approach to Collision Avoidance.
The simulations were performed on WSL2 with Ubuntu-22.04.5 LTS (Jammy), ROS2 Humble, and Gazebo Harmonic.
To setup the environment, do the following:
- Install ROS2 Humble
Follow the steps here
Note
Source ROS2 Installation
source /opt/ros/humble/setup.bash- Install Gazebo Harmonic
Follow the steps here
Note
Enable GPU Acceleration for NVIDIA GPUs in WSL2
export NVIDIA_DRIVER_CAPABILITIES=all
export LD_LIBRARY_PATH=/usr/lib/wsl/lib
export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
export MESA_LOADER_DRIVER_OVERRIDE=d3d12
export GALLIUM_DRIVER=d3d12
export LIBGL_ALWAYS_INDIRECT=0
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/dri:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH- Setup Turtlebot3 Simulations
Follow the steps here to complete the initial setup.
Note
The Simulation setup provided here is incompatible with Gazebo Harmonic. Perform the following:
cd ~/turtlebot3_ws/src
git clone -b new_gazebo https://github.com/azeey/turtlebot3_simulations.git
cd ~/turtlebot3_ws
colcon build --symlink-install
source ~/turtlebot3_ws/install/setup.bash- Setup Custom DWA
git clone https://github.com/reckylurker/assgn_ws.git && cd assgn_ws
colcon build --packages-select custom_dwa
source install/setup.bashNote
Ensure that the custom_dwa package is sourced in all terminals.
source assgn_ws/install/setup.bash- In a terminal, launch
custom_dwaplanner:
ros2 run custom_dwa launch_dwa- In another terminal, launch Gazebo and RViz2:
export TURTLEBOT3_MODEL=waffle
ros2 launch custom_dwa custom_dwa.launch.py- Uncheck
TFandOdometryin RViz2 for better visuals. - Add
MakerArraydisplay with topic/dwa_trajs. - Use
2D Goal Posein RViz2 to give navigation commands.
Watch the robot navigate.
The custom_dwa planner prints the DWA planning costs and the selected bestCmd to the terminal directly instead of publishing to /rosout. Commands are shown in the format (linear velocity, angular velocity).
To check published velocity commands:
ros2 topic echo /cmd_velThe DWA algorithm follows these steps:
- Dynamic Window Generation: Sample velocity commands (linear and angular) within the robot's dynamic constaints.
- Trajectory Prediction: For each velocity sample, numerically predict the robot's trajectory over a time horizon. The unicycle dynamics model is used for this prediction.
- Cost Evaluation: Evaluate each trajectory using a multi-objective cost function:
- Goal Distance: Distance from trajectory endpoint to goal.
- Obstacle Avoidance: Minimum distance to obstacles along trajectory
- Path Smoothness: Velocity and Angular Velocity Magnitudes
- Best Command Selection: Choose the velocity command with the lowest total cost.
where
The configurable parameters can be found in assgn_ws/src/custom_dwa/custom_dwa/DWAConfig.py.
With the current parameter settings, the algorithm rarely manages to recover after colliding with an obstacle. The robot tends to exhibit oscillatory behavior near obstacles, likely due to suboptimal parameter tuning. Given the time constraints of this assignment, extensive tuning was not performed. Currently, The robot should operate correctly for any goal as long as it avoids collisions.
assgn_turtlebot/
├── README.md
└── src
└── custom_dwa
├── custom_dwa
│ ├── DWAConfig.py
│ ├── DWALogging.py
│ ├── DWANode.py
│ ├── DWAPlanner.py
│ ├── dwa.py
│ └── __init__.py
├── launch
│ └── custom_dwa.launch.py
├── package.xml
├── resource
│ └── custom_dwa
├── setup.cfg
├── setup.py
└── test
├── test_copyright.py
├── test_flake8.py
└── test_pep257.py