ROS2 and Gazebo
This page explains how to get started using ROS2 to fly the quadrotor and perform simulations
Learn ROS2
There are lots of available resources for learning ROS2
- MAGICC Lab tutorials
- ROS 2 from Scratch by Edouard Renard
- ROS2 Official tutorials
- ROS2 Docker tutorial
- ROS2 For Beginners
Learn Gazebo
As long as Gazebo is installed properly, it should work pretty well and easily with ROS2
- MAGICC Lab tutorials
- Multi-Vehicle Simulation with Gazebo
- Gazebo Simulation
- ros_gz_project_template (A template project integrating ROS 2 and Gazebo simulator)
Multi-Quadcopter Control with PX4 and ROS2
The following set-up information explains how to use the code in the src
directory of this repository. It explains how to set up the proper environment and utilize the provided ROS2 package. The src
directory is designed to be the source directory for a standard ROS2 workspace. Each subdirectory is a seperate package with different purposes.
An overview of each package is provided as well as instructions for setting up the environment.
px4_offboard
Multi-agent quadrotor simulation using ROS2, PX4, Gazebo, QGroundControl, MicroXRCEAgent, and RViz.
Much of the intial code is based off work from:
I've used their examples to expand functionalities such as multi-agent control. It may be helpful to start with their examples first.
Explanation of launch files
Launch File | Description |
---|---|
circle.launch |
Launch a quadrotor to fly in a circle |
square.launch |
Launch a quadrotor to fly in a square |
waypoint.launch |
Launch a quadrotor to fly to a set of user-supplied waypoints |
HITL_offboard_velocity_control.launch |
Run on a real quadrotor for keyboard control |
multi_waypoint_swarm.launch |
Launch a swarm of quadrotors to follow supplied waypoints |
offboard_velocity_control.launch |
Launch a quadrotor controlled by keyboard inputs |
swarm_control.launch |
Launch a swarm of quadrotors to be controlled by keyboard inputs |
Run a launch file
Make sure you have built the ROS2 workspace and sourced the environment
Then you can start the launch file of your choice (assuming have already completed the set-up for PX4, Gazebo, MicroXRCEAgent, and the ROS2 workspace)
Several launch files support multiple vehicles with a launch configuration parameter called 'num_vehicles'
Notes on circle.launch.py
and square.launch.py
launch files
These launch files do not call on the processes.py
node. Therefore you need to start the different processes manually in different terminals.
Terminal 1
Terminal 2 Terminal 3 Terminal 4After everything has started, arm the drone in QGroundControl and switch it into offboard mode.
Set-up
Install PX4 Autopilot
To Install PX4 run this code
Run this script in a bash shell to install everything
You will now need to restart your computer before continuing
Install ROS2 Jazzy
To install ROS2 Jazzy follow the steps here
Install Dependencies
Install Python dependencies as mentioned in the PX4 Docs with this code
Build Micro DDS
As mentioned in the PX4 Docs run this code in order to build MicroDDS on your machine
git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
cd Micro-XRCE-DDS-Agent
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib/
Clone in Repo and Packages
Run this code to clone the repo
We need the px4_msgs package. Our ROS2 nodes rely on the message definitions in this package in order to communicate with PX4. Read here for more information.
Be sure you're in the src directory of the workspace and run this code to clone in the px4_msgs repo
For some reason I couldn't get this to work in ROS2 Jazzy without also including px4_msgs_old
and the translation_node
packages. To copy these packages, make sure you are in your workspace directory and have installed PX4-Autopilot in your root directory. Run the following code
Clone in all required packages before building the workspace
Build the Workspace
Source the ROS2 installation, build the workspace within the workspace directory (not in src
), and source the workspace
Your workspace directory should now look similar to the following
.
├── .github
├── build
├── docs
├── install
├── log
├── src
│ ├── other_ros_packages
│ ├── px4_offboard
│ ├── px4_msgs
│ ├── px4_msgs_old
│ ├── translation_node
├── .gitignore
├── mkdocs.yml
├── README.md
Running the code
Follow the instructions for each package to run the code