This is a re-published (not forked) repo of the original PX4-Autopilot. It also includes the settings file of PX4 for different variants of UAVs, and the relevant setup information. The main applications located in the src/modules
directory.
This repo is mainly used for:
The flow of the instructions is as follows:
graph TD
subgraph L1[Installation Step]
style L1 fill:transparent,stroke-width:0px;
subgraph PX4_Setup
px4_setup[Install PX4 Dependencies]
px4_clone[Clone PX4 Firmware]
pixhawk_pa[pixhawk_setup]
SITL_pa[Run PX4_SITL]
px4_setup --> px4_clone
px4_clone -->pixhawk_pa
px4_clone -->SITL_pa
style SITL_pa stroke-dasharray: 5,5;
style pixhawk_pa stroke-dasharray: 5,5;
end
subgraph Mavros_Setup
subgraph offboard_testing
create_ros_workspace[Create a ROS Workspace]
clone_packages[Clone MAVROS, MAVLINK,\nand Offboard Packages]
create_ros_workspace --> clone_packages
end
install_ros[Install ROS Noetic]
build_packages[Build the Packages]
install_ros --> offboard_testing
offboard_testing --> build_packages
end
end
subgraph L2[Building/Running Step]
style L2 fill:transparent,stroke-width:0px;
subgraph pixhawk[pixhawk Vx]
pixhawk_setup[pixhawk_setup]
load_firmware[Load pre-built\nfirmware to Pixhawk]
build_firmware[Build custom\nfirmware from source]
pixhawk_setup --> load_firmware
pixhawk_setup --> build_firmware
style pixhawk_setup stroke-dasharray: 5,5;
end
subgraph Run_SITL
run_sitl[Run PX4_SITL]
launch_mavros[Launch px4.launch Node]
run_offboard[Run offb Node]
run_sitl --> launch_mavros
launch_mavros --> run_offboard
style run_sitl stroke-dasharray: 5,5;
end
end
pixhawk_pa -.- pixhawk_setup
SITL_pa -.- run_sitl
build_packages --> launch_mavros
We will need to install PX4-Autopilot, Mavlink, Mavros to be able to have a communication between PX4 and ROS.
Install dependencies:
sudo apt install python3-pip -y
pip3 install kconfiglib
sudo apt install gcc-arm-none-eabi -y
pip3 install --user jinja2
pip3 install --user jsonschema
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio -y
Installation Guide (Reference):
Clone PX4-Autopilot
into home directory:
cd
git clone https://github.com/Mu99-M/PX4-Autopilot.git --recursive
Run the ubuntu.sh with no arguments (in a bash shell) to install everything:
cd
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
Restart the computer on completion.
Install ROS Noetic if not installed following this guide.
Clone and build offboard_testing repo.
Now everthing is ready to be used from companion computer side.
QGroundControl is a open-source ground control station software that let us to plan, monitor, and control vehicles. With features ranging from mission planning and telemetry monitoring to vehicle configuration and real-time control.
QGroundControl can be installed on Ubuntu LTS 20.04 (and later). Please follow the instructions in this link for QGC installation.
Build px4 in sitl
cd ~/PX4-Autopilot
make px4_sitl_default none
Launch px4.launch
node
roslaunch mavros px4.launch fcu_url:=udp://:14540@14555
Launch the starting node
roslaunch offb starting.launch
Note: You may need to change the airframe if the vehicle is not armed and there is
Preflight Fail
.cd ~/PX4-Autopilot make px4_sitl_default none param set SYS_AUTOSTART 3011
Then restart the PX4.
You can either use (1) pre-buit firmware files or (2) custom build the firmware from source. Both procedures are describe below:
You can find the files for pre-built firmware in the PX4-Autopilot/compiled firmware
directory. Upload the firmware suitabe for your FMU version to your pixhawk using QGroundControl as explained in this guide.
To build for Pixhawk 4 (FMUv5):
cd ~/PX4-Autopilot
make px4_fmu-v5_default
For any other version check this link.
Upload the firmware to your pixhawk using QGroundControl as explained in this guide.
You can refer to this guide to setup ethernet communication with you pixhawk if your pixhawk supports this (e.g. pixhawk 5x or 6x). If using the pixhawk cm4 baseboard with raspberry pi, you can refer to this guide. The process to setup ethernet comunication with pixhawk is briefly explained below in the report in 1. Using Ethernet
subsection.
To configure the PX4 parameters correctly, you can directly upload a pre-configures file to your pixhawk / SITL. You can also configure the needed parameters manually as describe later in this guide.
You can find pre-configured parameters files on this link. You can upload the pre-configured parameter file to pixhawk using QGroundControl as described in this link
You can change px4 parameters from QGroundControl as described here The major needed parameter changes are described below:
If you have already configured a static IP for your pixhawk and companion computer as explained in this guide, you can skip to step 8.
IPADDR=192.168.144.4
as the IP address of the pixhawk. The pixhawk subnet should match the subnet of the companion computer.ping 192.168.144.4
from the terminal.MAV_x_CONFIG
, where x
is the instance number. Our default configuration uses x=2
instance for ethernet communication.MAV_x_CONFIG
parameter.MAV_x_CONFIG
parameter to ethernet
.MAV_x_MODE
parameter to Custom
.MAV_x_RATE
parameter to 2000000
B/s.MAV_x_BROADCAST
parameter to 1
.MAV_x_RADIO_CTL
parameter to 0
.MAV_x_REMOTE_PRT
parameter to 14540
.MAV_x_UDP_PRT
parameter to 14540
.For using MAVROS on the companion computer to communicate with the pixhawk over ethernet, you can run the following command:
roslaunch mavros px4.launch fcu_url:=udp://@IPADDR:14540@
where IPADDR is the ip address of the pixhawk (by default 192.168.144.4).
MAV_x_CONFIG
, where x
is the instance number. Our default configuration uses x=1
instance for UART communication.MAV_x_CONFIG
parameter.MAV_x_CONFIG
parameter to the port you are using (e.g., TELEM 2
).MAV_x_MODE
parameter to Custom
.MAV_x_RATE
parameter to 2000000
B/s.After completing these steps, your MAVLink instance should be configured and ready to use.
The landing detector of the PX4 can disarm the drone if not configured properly. As such, it is recommended to disable this module by setting the below parameters in QGroundControl:
COM_DISARM_LAND
parameter to -1
.MPC_THR_HOVER
parameter to a low value (e.g. 0.25
).Set the value of the 'COM_DISARM_PRFLT' parameter to '1000.0'.
Set the value of the 'COM_OBL_RC_ACT' parameter to '7'.
We are interested in 3 topics for now (VEHICLE_ANGULAR_VELOCITY
, VEHICLE_ATTITUDE
, and VEHICLE_LOCAL_POSITION
).
First, run uorb top -1
in the Mavlink shell to check the publishing rate of each topic. Each topic of the three mentioned above should be at least 200 Hz.
To change the rate of VEHICLE_ATTITUDE
and VEHICLE_LOCAL_POSITION
:
IMU_INTEG_RATE
to be 400 Hz.EKF2_PREDICT_US
to be 2500.Note: The parameter IMU_INTEG_RATE
is to change the rate of the VEHICLE_ATTITUDE
topic.
Note: The EKF2_PREDICT_US
is to change the rate of the VEHICLE_LOCAL_POSITION
topic, however, the topic rate will be limited to the IMU_INTEG_RATE
parameter value.
Run uorb top -1
in the Mavlink shell to re-check the publishing rate of the topics after applying the changes.
Open ~/PX4-Autopilot/src/modules/mavlink/mavlink_main.cpp
Change the three lines of the topics to be:
configure_stream_local("VEHICLE_LOCAL_POSITION", 200.0f);
configure_stream_local("VEHICLE_ATTITUDE", 200.0f);
configure_stream_local("VEHICLE_ANGULAR_VELOCITY", 200.0f);
Save, build, and upload to the pixhawk 6x. To build PX4 for pixhawk 6x:
cd ~/PX4-Autopilot/
make px4_fmu-v6x_default upload
A successful run will end with this output:
Erase : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.
[100%] Built target upload
roslaunch mavros px4.launch
rostopic hz /mavros/vehicle_angular_velocity/vehicle_angular_velocity
rostopic hz /mavros/vehicle_attitude/vehicle_attitude
rostopic hz /mavros/vehicle_local_position/vehicle_local_position
The output should be like this:
average rate: 200.00
min: 0.002s max: 0.019s std dev: 0.00572s window: 100
If the rate is successfully 200 Hz, please start from step 2 again but with 400.0f Hz.