This repository hosts the source code for the final project at the Autonomous Mobile Robots (AMR) course. Our work encapsulates the integration of sophisticated navigation capabilities on the Robile platform, including path planning, localization, and environment exploration utilizing ROS2 and custom-developed algorithms.
-
assets/
: Contains visual resources and diagrams, such asamr-simulation-map.png
, which illustrate the simulated environment and help in visualizing the robot's operational context. -
src/
: The core of our project, structured into specific modules for organization and clarity:common/
: Defines shared resources across the project, including constants and utility functions that form the backbone of our navigation algorithms.services/
: Houses the core functionalities crucial to Robile's navigation and exploration capabilities:astar_service.py
: Implements the A* algorithm, enabling global path planning by finding the most efficient path between two points.exploration_service.py
: Manages the strategy for autonomous exploration, allowing Robile to intelligently navigate and map unknown environments.frontier_service.py
: Focuses on detecting and managing frontiers, which are boundaries between explored and unexplored areas, facilitating systematic exploration.localization_service.py
: Implements a custom particle filter algorithm for precise localization, using sensor data to accurately estimate Robile's position within its environment.path_planning_service.py
: Provides mechanisms for dynamic path planning, integrating various algorithms to navigate efficiently while avoiding obstacles.potential_field_service.py
: Utilizes the potential field method for local navigation, directing the robot away from obstacles and towards its goal through simulated forces.
-
utils/
: Supports the main services with additional utilities like an event bus system for inter-component communication. -
test/
: Contains unit tests for validating the functionality and reliability of our algorithms and utilities, ensuring robustness and efficiency in the system's operations. -
main.py
: Serves as the entry point to our application, orchestrating the initialization and interaction of various components within the system.
In order to use this project, make sure the following prerequisites are met:
- OS: Ubuntu 22.04 LTS
- Python (tested on Python 3.10.12)
- ROS2 and Robile-related setup (use these Bash scripts)
- VSCode, alongside Python and ROS extensions
Next, create a settings.json
file in .vscode
folder:
{
"python.autoComplete.extraPaths": [
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"python.analysis.extraPaths": [
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"ros.distro": "humble"
}
This will ensure access to autocompletion and source code analysis, and it will configure the ROS extension. If needed, reload the window.
Remember to always source ROS2 and potentially also the the ros2_ws
workspace (when launching Robile in simulation).
source /opt/ros/humble/setup.bash
# Only when running Robile in simulation
source ~/ros2_ws/install/setup.bash
Our design of the project is simple: first explore the environment and build a map, and then, using the generated map, we manually provide start/goal, and let the robot find its way.
In the first terminal window, launch Robile in simulation (refer to command above). For the exploration mode to work, make sure you set the following environment variable BEFORE launching the program:
export EXPLORATION=true
python3 main.py
In the first terminal window, launch Robile in simulation (refer to command above). In the second terminal window, launch the program:
python3 main.py
You will need to start the map server and then configure + activate it. For that, first start the server:
cd maps
ros2 run nav2_map_server map_server --ros-args -p yaml_filename:="my_map.yaml"
To configure and activate the map server, in another terminal window, execute the following:
ros2 lifecycle set /map_server configure
ros2 lifecycle set /map_server activate
In order to run tests (they should all be in the test
folder), you will need to set the PYTHONPATH
variable in order for Python to be able to correctly resolve module imports.
source /opt/ros/humble/setup.bash
export PYTHONPATH="${pwd}:$PYTHONPATH"
Do not use the unittest
library module, instead, run test files as normal Python programs.
You would hopefully only need to go through this step once. In order to create a map, it's important to following the following instructions.
- In the first terminal window, launch Robile in simulation
ros2 launch robile_gazebo gazebo_4_wheel.launch.py
- In the second terminal window, start Navigation 2 stack and use the Gazebo time (simulated time)
ros2 launch nav2_bringup navigation_launch.py use_sim_time:=True
- In the third terminal window, start
slam_toolbox
, and once again, use the simulated time
ros2 launch slam_toolbox online_async_launch.py use_sim_time:=True
- In the fourth terminal window, launch RViz so that you can have an idea of how map is being created.
ros2 run rviz2 rviz2 -d /opt/ros/humble/share/nav2_bringup/rviz/nav2_default_view.rviz
- In the fifth terminal window, launch this command in order to be able to control the robot with a keyboard
ros2 run teleop_twist_keyboard teleop_twist_keyboard
- Move the robot around and attempt to create an accurate map. When done, open the sixth terminal window and enter the following command to save the map (this does it in
my_map
):
ros2 run nav2_map_server map_saver_cli -f my_map
This will create two files, the actual map file (.pgm file) and its description (YAML file). Create a folder called maps
and copy-paste them inside (we are not checking in the maps into version control).
If done properly, your map should look something like this: