Ubuntu builds APM firmware compilation environment

foreword

Ubuntu20.04
APM 4.2.3
reference link:
https://ardupilot.org/dev/docs/building-setup-linux.html

APM unmanned ship effect display (welcome to pay attention to station B, continue to update the video)

Open source unmanned ship autonomous obstacle avoidance demonstration

Attach the link of the virtual machine that has already configured the environment
: https://pan.baidu.com/s/1mKAFPeBwnH-qw-t4DR0vPQ?pwd=2tyf
Extraction code: 2tyf
– share from Baidu Netdisk super member V6

1. Download the source code

git clone https://github.com/ArduPilot/ardupilot.git

after downloading

cd ardupilot
git submodule init
git submodule update

If an error occurs during execution git submodule updateand the submodule has not been updated, continue to execute the command until the update is completed.

Attached is the fully downloaded source code:
Link: https://pan.baidu.com/s/1TQxyEM6PtStOkCGekGWCZw?pwd=u04f
Extraction code: u04f
– share from Baidu Netdisk super member V6

2. Configure the compilation environment

Execute the following command to install the environment in the ardupilot directory:

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

If an error occurs, re-execute the above command until the following prompt appears to indicate that the environment installation is successful:
Please add a picture description
Execute after the configuration is successful:

. ~/.profile

It is recommended to use the latest version of the apm firmware environment installation script, because the installation script of the old version of the firmware can compile the old version of the firmware after the environment is installed, but not necessarily the new version of the firmware. For example, the author uses the 4.3.1 version of the firmware script to configure the
environment Afterwards, the 4.3.1 version of the firmware can be compiled, but when compiling the 4.3.7 version of the firmware, an error is reported: the
insert image description here
solution is relatively simple, that is, use the script of the 4.3.7 version of the firmware to execute it again, and the 4.3.7 version can be compiled The firmware is gone.

If the firmware of the master version is compiled normally, but after switching to the Copter 4.3.7 tag, the execution ./waf configure --board fmuv3reports the following error.
insert image description here
The solution is to switch to the Copter 4.3.7 tag and then execute the script for configuring the environment.

3. Compile the firmware

Before compiling the firmware, you need to configure the target hardware of the compiled firmware.
I am using the pix2.4.8 flight controller here, so I use the fmuv3 firmware, and the configuration is as follows:

./waf configure --board fmuv3

Please add a picture description
Then compile the quadcopter firmware with the following command

./waf copter

The compilation is successful as follows:
Please add a picture description
The firmware generated after compilation is
Please add a picture description
cleared and compiled in the directory shown in the figure below:

./waf copter clean

Download automatically after compiling:

./waf copter --upload

Set the git tag.
The default git branch is master. This branch is the developer branch. For normal use, it is recommended to use the stable version branch. The
following commands view all tags

git tag

My latest copter branch here is 4.3.1
insert image description here
Use the following command to switch

git checkout Copter-4.3.1

After the switch is successful, use git branch to view the following:
insert image description here
Then compile and download, and see the firmware version as follows: If you use the master branch, you will see that the firmware version is the dev version
insert image description here

4. Simulation

Take the multi-rotor as an example, ardupilot/ArduCopterexecute in the directory:

sim_vehicle.py -w

After the execution is completed, the following page will pop up, and then open the ground station to link to the simulated drone.
insert image description here
Gazebo simulation
gazebo installation:

sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt update
sudo apt install gazebo9 libgazebo9-dev

Execute after successful installation:

gazebo --verbose

If an empty gazebo interface can pop up, the installation is successful

Install the gazebo plugin:

git clone https://github.com/khancyr/ardupilot_gazebo
cd ardupilot_gazebo
mkdir build
cd build
cmake ..
make -j4
sudo make install

After success, it is as follows:
insert image description here
modify the environment variable:
add it in .bashrc (my ardupilot_gazebo is in the current user directory, if you make corresponding changes in other directories):

source /usr/share/gazebo/setup.sh
export GAZEBO_MODEL_PATH=~/ardupilot_gazebo/models:${GAZEBO_MODEL_PATH}
export GAZEBO_MODEL_PATH=~/ardupilot_gazebo/models_gazebo:${GAZEBO_MODEL_PATH}
export GAZEBO_RESOURCE_PATH=~/ardupilot_gazebo/worlds:${GAZEBO_RESOURCE_PATH}
export GAZEBO_PLUGIN_PATH=~/ardupilot_gazebo/build:${GAZEBO_PLUGIN_PATH}

Then start the simulation:

gazebo --verbose worlds/iris_arducopter_runway.world

You can see that a gazebo page pops up, and there is a drone in it (if there is no drone, check the environment variable settings), but at this time the drone cannot connect to the ground station
insert image description here
and then start the software-in-the-loop simulation:
enter ~/ardupilot/ The ArduCopter directory executes:

../Tools/autotest/sim_vehicle.py -f gazebo-iris --console --map

After the startup is successful, it is as follows. At this time, you can connect to the ground station. At this time, you can plan the route like a real drone, but you need to push the virtual joystick to the lowest level before unlocking, otherwise an error will be reported.
insert image description here

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_38768959/article/details/131133686