• +4917626969472
  • info@ur-techpartner.de

Drone(QuardCopters) Simulation with PX4 Autopilot and Ground Control,Gazebo and ROS Comprehensive guide


What is Blog covers?

  • How to configure and test PX4 autopilot for flying drone and all other robots using simulator?
  • What are different types of simulation option available?
  • How to configure simulation based on different operating system .i.e., Ubuntu ROS supported versions.
  • How to control Drones via ground control
  • How to control drone via ROS1 and ROS2.
  • How to integrate AI and other pipelines with existing environment? 


PX4 flight control is world renowned and, very kind of, one of the very few open source flight controllers available for drones and robots. 

If you are into robotic and drones, you might have to interact with either raw px4 based flight controls or extended flight controller advanced upon basic firmware. 

This section is especially focused upon  Drones and copters.

PX4 supported many different Software in the Loop (SILT) simulations ,Hardware In Loop (HITL)  For example Gazebo, Flight Gear, JMavSim, JBSSim , AirSIM

Important to note: different version of Ubuntu/Linux have different ways/method to configure the Development environment and simulation. Since ROS officially supported only up to 20.04 focal, here we stick to that Ubuntu version.

figure 01

PX4 SITL overview

Source: https://px4.io/


Configuration setps:

step:1 QC ground Control


To configure the Ground control, you have to first configure your Ground Control station

To do so, we have to change the permission right to allow UDP and TCP ports to communicate with ground control. Please see .the diagram figure01  to get the feeling how the overall process works.

1.1 write the code below in the terminal 


					sudo usermod -a -G dialout $USER
sudo apt-get remove modemmanager -y
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y
sudo apt install libqt5gui5 -y
sudo apt install libfuse2 -y
  • Explanation what this code is doing?

sudo usermod -a -G dialout $USER: This command adds the current user to the “dialout” group, which grants permission to access serial ports. The $USER variable is replaced with the current username.

  • sudo apt-get remove modemmanager -y: This command removes the “modemmanager” package, which can interfere with serial port communication.
  • sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y: This command installs several GStreamer plugins, which are used for multimedia processing.
  • sudo apt install libqt5gui5 -y: This command installs the Qt5 GUI library, which is used for creating graphical user interfaces.
  • sudo apt install libfuse2 -y: This command installs the FUSE library, which is used for implementing file systems in user space.

1.2 Here>> Download QC Control software

Make the software executable inserting command below

					chmod +x ./QGroundControl.AppImage
(or double click)

This should open QC ground control.

2. PX4 setup with Gazebo

This is classic simulation step which need not any installation of ROS or MAVlink beforehand.

Which means you have testing space for px4 flight controller and all the functionalities of QC ground control, follow the following steps to set up for Gazebo classic.

Note: If you have ROS noetic full desktop installed on your system, Gazebo installed automatically with that. Otherwise, you have to first Install the Gazebo.x version on your system.

Secondly, You have to installed and run the QC ground control to run this step.

 2.1 Download the source code for px4 flight controller and other submodule important of multiple different type of robot

If you’re working with ROS Noetic on Ubuntu 20.04:

					git clone https://github.com/PX4/PX4-Autopilot.git --recursive

2.2 Go run this command to install the bash script to configure the workspace.

					bash ./PX4-Autopilot/Tools/setup/ubuntu.sh --no-sim-tools --no-nuttx

Restart the system to get imapct . 

Might be you need additional dependencies as follows , run the command below

					sudo apt-get install protobuf-compiler libeigen3-dev libopencv-dev -y

Cd into the downloaded directory PX4-Autopilot

cd /path/to/PX4-Autopilot
make px4_sitl gazebo-classic

3. PX4 setup with Gazebo ROS noetic [offboard APIs] and MAVROS

These are steps of running px4 offboard, meaning, with ROS1 and ROS2. To create communication with ROS rather on-board or off board we need a package of ROS called MAVROS.

3.1 follow the instruction below to install the ROSMAV

					sudo apt-get install ros-noetic-mavros

3.2 after installing mavros on board, you have to install GegraphisLib using command below.

After installing ROSMAV, GeographicLib may be included as a dependency or recommended package, as it is used in various ROS packages for geospatial calculations and mapping. For example, the MAVROS package, which provides communication drivers for MAVLink-based drones in ROS, uses GeographicLib for coordinate conversions between GPS, local ENU (East-North-Up), and local NED (North-East-Down) frames.

					wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
sudo bash ./install_geographiclib_datasets.sh   

3.4 Starting MOVROS node and communication with real or simulated environment. 

You have to supply command below to launch the mavros on a computer attached to flight controller. When you launch MAV ROS it starts the node and wait for simulation or real hardware to initiate

For simulating based.

You can test it with simulation first.

3.4.1  Run quadcopter simulation following above-mentioned instructions.

3.4.2 Run QC ground control, see. Instructions above.

Make sure they are connected. To make sure go to ground control and see if topleft buttong is green.

					roslaunch mavros px4.launch fcu_url:="udp://:14540@"

Go back to the terminal where you have run MAVROS and see if you are getting a message from flight controller. 

Note the UDP port is right now localhost, which mean everything is on the same one computer. But practically you might want to connect to the computer which is attached to the drone and connected to the same Wi-Fi. You can configure the port and IP address of that remote computer and process the data at ground computer or make an app from it, or whatever you want to do with the data.

Alternatively, you can connect to your drone’s computer with ssh shell and give commands as it was a  localhost. But his method is not very effective and efficient for use case, if you want to build up sort of front end for drone to controls it  and give it path to navigate and so on. In such case, you should have connection node from ground computer to drone’s computer and get the  data callbacks from camera of drone or any other sensor for further processing. 

That is the reason offboard APIs are mostly used to control the drone rather than with QC or RC

For more interesting video guides and tutorial, watch our YouTube channel 

No comments