Python-RRT is an Rapidly-exploring Random Tree (RRT) algorithm implemented in Python3 that can generate paths to reach one or more user-specified goalpoints in 3D space. This algorithm can be used to simulate unmanned aerial vehicles in various 3D environments with multiple obstacles. It has multiple improvements over the most basic form of the algorithm, such as path smoothing, node pruning, goal bias, failure detection, and bidirectional path generation. See writeup.docx for more details.
/src/offboard_py/scripts/rrt.py contains the main algorithm, plus a matplotlib extension for visualizing the generated paths (visualization will be in 2D and omit the path coordinates representing height).
/src/offboard_py/scripts/CONFIG.py contains the primary variables the algorithm uses, and serves as a configuration file for easy adjustments of those variables.
/src/offboard_py/scripts/maps.py contains sample maps used for path generation.
The above 3 files are all that is necessary for non-simulation usage.
/src/offboard_py/scripts/offboard_node.py is an example of how the algorithm can be connected to a simulation like Gazebo. Additional setup may be required (see Installation).
/src/offboard_py/src/launch/start_offboard.launch is the launch file used for simulating the algorithm in Gazebo. Again, additional setup may be required (see Gazebo Installation and Setup).
/src/devel/setup.bash, /src/devel/set_location.sh, and /src/.bashrc are also required for simulation.
At the bottom of the code in rrt.py there are two lines of code in quotation marks. Removing the quotation marks and running the code will plot a graph in matplotlib visualizing the generated path. If you want to use the code alongside other simulator applications, put those two lines back in quotation marks or as comments, and other files will handle everything.
This code was tested and simulated on Gazebo with a PX4 model of an Iris Quadcopter. Of course, other simulators and applications can also be utilized. This doc will guide you through instructions for Gazebo on Ubuntu 18.04 and 20.04.
You will need to install the following dependencies: ROS (either ROS Melodic for Ubuntu 18.04, or ROS Noetic for Ubuntu 20.04), PX4, and Gazebo. Instructions can be found in simulation_setup.docx. Additional instructions for installing PX4 and MAVROS can be found at https://docs.px4.io/v1.14/en/dev_setup/dev_env_linux_ubuntu.html#ros-gazebo-classic and https://docs.px4.io/v1.14/en/ros/mavros_installation.html, as some parts of simulation_setup.docx may be obsolete.
NOTE: Many tutorials will have you create a folder called catkin_ws, but that is not necessary; just treat this repo as the catkin_ws folder without renaming anything.
Next you will need to install MAVROS and use it to connect the algorithm to Gazebo. /src/offboard_py/scripts/offboard_node.py offers the necessary code plus some additional logic to make it compatible with this repo's code. Additional instructions and help can be found here: https://docs.px4.io/main/en/ros/mavros_offboard_python.html.
1) Clone this repo into your home directory with git clone https://github.com/Pr0gram-Creat0r-1/Python-RRT.git.
2) cd into your PX4 directory which you cloned from here (the directory is probably going to be called PX4-Autopilot; if not then modify this repo's launch files and shell files with the correct name) and run make px4_sitl_default gazebo. You may need to run it with root privileges.
3) cd back into this repo's src folder and run catkin build to create a catkin workspace.
4) Run source .bashrc in src.
5) Run catkin_create_pkg offboard_py in src to create the package ROS will use to launch everything.
6) cd into /offboard_py/scripts and run chmod +x offboard_node.py to make offboard_node.py an executable.
7) Open a new terminal window and run roslaunch mavros px4.launch fcu_url:=udp://:14540@localhost:14557 in the src folder. This will start MAVROS, which will allow the path generated by the algorithm to be broadcast to the simulated UAV.
8) Switch back to the first terminal window, cd to the src folder, and run roscd offboard_py to cd into the offboard_py directory. If this command doesn't work it means you haven't created an ROS package for this repo; retry the first few steps.
9) Run roslaunch offboard_py start_offboard.launch.
If done correctly, a Gazebo window should appear with a model of an Iris Quadcopter and multiple boxes representing map obstacles, and the terminal will return info on path generation and drone status. Once the path has finished generating, red dots will start to appear in Gazebo, representing the waypoints. After a few seconds, the drone will automatically take off.
If errors occur, you may need to modify the PX4-Autopilot launch files (px4.launch, mavros_posix_sitl.launch, posix_sitl.launch).
Once you've followed all these steps and fixed any errors that may occur, then in the future you will only need to do steps 4, 7, 8, and 9.