[Pixhawk/PX4] development environment setup (Ubuntu 18.04) and problem summary

Keywords: Ubuntu

It mainly records the construction process and problem summary of PX4 environment under Ubuntu 18.04.

Because gazebo is generally included in ros installation, gazebo installation is not introduced.

1, Basic resource download

This is my first contact with the installation of ubuntu system, so some steps may be wrong or redundant. Please criticize and correct.

1. Download the installation scripts ubuntu.sh and requests.txt. I don't know what this is about, and it's not in many tutorials, so I tried it. It's not a loss anyway.

wget https://raw.githubusercontent.com/PX4/Firmware/master/Tools/setup/ubuntu.sh 
wget https://raw.githubusercontent.com/PX4/Firmware/master/Tools/setup/requirements.txt

2. Run ubuntu.sh installation, and restart the computer after installation.

source ubuntu.sh

3. Inspection after installation

Run command check

arm-none-eabi-gcc --version

If the following appears, Nuttx is successfully installed

2, Installation process

I have also referred to many tutorials in this section. You can directly see the article in the link, which is very detailed:

UAV Simulation setup: ROS, Gazebo, SITL, MAVROS, PX4_waitin blog - CSDN blog

Installing SITL

1. Download code

git clone https://github.com/ArduPilot/ardupilot
cd ardupilot
git submodule update --init --recursive

The third instruction is the most error prone because the GitHub website is difficult to access and is prone to connection failure. The main methods are to change the website, replace all github.com in the. gitmodules file with github.com.cnpmjs.org, or directly download the failed installation package.

However, during the installation process, I found that opening the github URL that failed to connect in the browser can improve the success rate of the connection, and then repeat the command several times.

2. Installation dependency

Tools/environment_install/install-prereqs-ubuntu.sh -y
. ~/.profile

3. Test

Execute a python script to test

cd ~/ardupilot/ArduCopter
sim_vehicle.py --map --console

No error, just see the interface. If there is any mistake, copy and search.

Install mavors


sudo apt install ros-melodic-mavros ros-melodic-mavros-extras


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

This connection takes some time. If there is a connection error, try changing the network or http.


sudo chmod a+x ./install_geographiclib_datasets.sh


sudo ./install_geographiclib_datasets.sh

It's good to have three installing here. It's said that it will take some time. It should also be a problem of the network.

PX4 configuration

There are two ways to download the source code. One is to download the source code on github, but the speed is very slow. The other is to download the source code on gitee. I will directly hang up gitee. Note that some paths of files downloaded from different tutorials may be different.


git clone https://gitee.com/robin_shaun/PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1

Then you need to modify the. gitmodules file

Backup first:

sudo cp .gitmodules .gitmodules.bak

Open file

sudo gedit .gitmodules

Replace with:

[submodule "mavlink/include/mavlink/v2.0"]
	path = mavlink/include/mavlink/v2.0
	url = https://gitee.com/robin_shaun/c_library_v2.git
	branch = master
[submodule "src/drivers/uavcan/libuavcan"]
	path = src/drivers/uavcan/libuavcan
	url = https://gitee.com/robin_shaun/uavcan.git
	branch = px4
[submodule "Tools/jMAVSim"]
	path = Tools/jMAVSim
	url = https://gitee.com/robin_shaun/jMAVSim.git
	branch = master
[submodule "Tools/sitl_gazebo"]
	path = Tools/sitl_gazebo
	url = https://gitee.com/robin_shaun/sitl_gazebo.git
	branch = master
[submodule "src/lib/matrix"]
	path = src/lib/matrix
	url = https://gitee.com/robin_shaun/Matrix.git
	branch = master
[submodule "src/lib/ecl"]
	path = src/lib/ecl
	url = https://gitee.com/robin_shaun/ecl.git
	branch = master
[submodule "boards/atlflight/cmake_hexagon"]
	path = boards/atlflight/cmake_hexagon
	url = https://gitee.com/robin_shaun/cmake_hexagon.git
	branch = px4
[submodule "src/drivers/gps/devices"]
	path = src/drivers/gps/devices
	url = https://gitee.com/robin_shaun/GpsDrivers.git
	branch = master
[submodule "src/modules/micrortps_bridge/micro-CDR"]
	path = src/modules/micrortps_bridge/micro-CDR
	url = https://gitee.com/robin_shaun/micro-CDR.git
	branch = px4
[submodule "platforms/nuttx/NuttX/nuttx"]
	path = platforms/nuttx/NuttX/nuttx
	url = https://gitee.com/robin_shaun/NuttX.git
	branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/nuttx/NuttX/apps"]
	path = platforms/nuttx/NuttX/apps
	url = https://gitee.com/robin_shaun/NuttX-apps.git
	branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/qurt/dspal"]
	path = platforms/qurt/dspal
	url = https://gitee.com/robin_shaun/dspal.git
[submodule "Tools/flightgear_bridge"]
	path = Tools/flightgear_bridge
	url = https://gitee.com/robin_shaun/PX4-FlightGear-Bridge.git
	branch = master 
[submodule "Tools/jsbsim_bridge"]
	path = Tools/jsbsim_bridge
	url = https://gitee.com/robin_shaun/px4-jsbsim-bridge.git
[submodule "src/examples/gyro_fft/CMSIS_5"]
	path = src/examples/gyro_fft/CMSIS_5
	url = https://gitee.com/mirrors/CMSIS_5

Then run

git submodule update --init --recursive

Installing python dependencies

No matter how you download the source code, you need to install dependencies to compile successfully. I compiled without installing dependencies for a long time (quote the original)

cd ~/PX4_Firmware
bash ./Tools/setup/ubuntu.sh --no-nuttx --no-sim-tools


make px4_sitl_default gazebo

Here are the most prone to problems. I'll summarize later.

After successful compilation, gazebo should be opened without error

Configuration environment

Modify the. bashrc file

sudo gedit ~/.bashrc

Add the following code at the end. Note that the paths may be different. Check that the first two source s cannot be reversed

source ~/catkin_ws/devel/setup.bash
source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware/Tools/sitl_gazebo


source ~/.bashrc


cd ~/PX4_Firmware
roslaunch px4 mavros_posix_sitl.launch

At this time, gazebo will start. Pay attention to check for errors.

Open another terminal

rostopic echo /mavros/state

connected: True, indicating that the communication between MAVROS and SITL is successful

3, Problem summary

1.github connection failed

This is a problem that has been bothered for a long time in the early stage. I wanted to climb over the wall, but ubuntu didn't know how to do it. Thinking about changing the website solved most of the problems, but one or two of them still went to github to clone, which made me angry. Elder martial brother told me that I could download and install it directly, but I found that after opening the website from the terminal, he could clone, just repeat it several times

git submodule update --init --recursive

It's done.

2. Lack of waf_light file

This problem is a bit magical, because they are all in an open source station. Why didn't others meet them? But I found this file on gitee and put it in the path: Home / ardupilot / modules / WAF / WAF master. Moreover, the version of this file can't be too high. 2.0.9 can't work. 1.9.0 can't.

3. Collection of error reports

I met a treasure blogger, wrote a problem summary, solved two big problems, and was moved to cry.

PX4 installation for building UAV Simulation Environment_ wangdongjiab's blog - CSDN blog

Here I mainly talk about my mistakes:

ninja: build stopped: subcommand failed.
Makefile:198: recipe for target 'px4_sitl_default' failed
make: *** [px4_sitl_default] Error 1

I searched a lot on the Internet for this problem, but it was 193200, which was not the same as me until I met this great God.


sudo apt-get install libgstreamer-plugins-base1.0-dev

In the final test session, I met:

RLException: [indoor1.launch] is neither a launch file in package [px4] nor is [px4] a launch file name
The traceback for the exception was written to the log file

Also searched for a long time,


source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware/Tools/sitl_gazebo

In order that you can find this error, I directly copy and paste a wave.

ninja: build stopped: subcommand failed.
Makefile:198: recipe for target 'px4_sitl_default' failed
make: *** [px4_sitl_default] Error 1

RLException: [indoor1.launch] is neither a launch file in package [px4] nor is [px4] a launch file name
The traceback for the exception was written to the log file

Posted by ant peacocke on Sat, 30 Oct 2021 23:17:00 -0700