The basic configuration of drone simulation platform based on ROS and PX4 under Ubuntu 18.04

The basic configuration of drone simulation platform based on ROS and PX4 under Ubuntu 18.04

Reference materials:
https://www.yuque.com/xtdrone/manual_cn/basic_config_1.11
https://blog.csdn.net/qq_42585108/article/details/106781596
https://blog.csdn.net/qq_44830040/article /details/106049992
https://blog.csdn.net/abc869788668/article/details/78323395?locationNum=8&fps=1

Xiao Kun’s XTDrone project was used for the construction of the UAV simulation platform. Thank you very much. The related webpage: https://gitee.com/robin_shaun/XTDrone. Here I am just a summary of the construction of the simulation UAV platform.
This article is just a summary and personal installation experience based on these articles. There may be many quotes in the middle. If it constitutes an infringement, please contact me to delete it.

System Ubuntu18.04, I started installing from a freshly installed Ubuntu, step by step, and integrated some network construction methods and problems encountered in it, and record these for your reference. If there is any mistake, please correct me.

One, dependent installation

1、

sudo apt install -y \
ninja-build \
exiftool \
python-argparse \
python-empy \
python-toml \
python-numpy \
python-yaml \
python-dev \
python-pip \
ninja-build \
protobuf-compiler \
libeigen3-dev \
genromfs \
xmlstarlet \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev

2、

pip install \
pandas \
jinja2 \
pyserial \
cerberus \
pyulog \
numpy \
toml \
pyquaternion

If the following error occurs, you can update setuptools and pip first

Collecting pandas
  Using cached https://files.pythonhosted.org/packages/64/f1/8fdbd74edfc31625d597717be8c155c6226fc72a7c954c52583ab81a8614/pandas-1.1.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-qtvsjq8t/pandas/setup.py", line 349
        f"{extension}-source file '{sourcefile}' not found.\n"
                                                             ^
    SyntaxError: invalid syntax
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qtvsjq8t/pandas/
pip install --upgrade setuptools
#若未报错不需要输入这两行命令
python -m pip install --upgrade pip

Two, ROS installation

For installation, please
refer to the official ROS website: http://wiki.ros.org/Installation/Ubuntu or refer to the tutorial: https://blog.csdn.net/qq_44830040/article/details/106049992 (this tutorial is a domestic source installation, Although ros can be used, there may be problems when using it with other ones such as darknet_ros. Although the download from domestic sources will be much faster, it is still recommended to download from the official website)

Note: Ubuntu 18.04 can be installed directly (that is, the command sudo apt-get install ros-melodic-desktop, that is, for ROS Melodic, choose desktop-full installation, which will install Gazebo9 and perception related libraries at the same time), but I personally recommend 18.04 The installation of gazebo9.0 directly has defects and problems may occur later. It is recommended to install desktop, and then install gazebo9.13 or above
Ubuntu16.04 (ROS Kinetic) in the following steps. Select destop or install. Gazebo7 cannot perform subsequent simulations.
Here is also the installation of ROS (taking melodic as an example):

1. Configure the Ubuntu repository
. Click the source code in the software and update.
Insert picture description here
2. Set the sources.list. The
following are Tsinghua Mirror, Zhongke University Mirror and the official default choice. However, I personally recommend the domestic mirror, the download will be much faster

Tsinghua Mirror:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

Chinese University of Science and Technology Mirror:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

The official default:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

3. Set the key

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

4. Installation

sudo apt update
sudo apt install ros-melodic-desktop

If you install ROS normally, you can sudo apt install ros-melodic-desktop-full, here I am sudo apt install ros-melodic-desktop, the reason has been mentioned before

5. Set the environment

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

6. Build dependencies

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init

If an error occurs:
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
Execute the following command :

cd /etc
sudo gedit hosts

Add at the end: 151.11.84.133 raw.githubusercontent.com and then save the file and exit.

If an error occurs: ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize the
solution, execute the following command:

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

Then execute againsudo rosdep init

7. Perform rosdep update

rosdep update

If the following error occurs:
ERROR: error loading sources list:
('The read operation timed out',) is
probably a network problem, just execute the rosdep update command repeatedly

Start ROS after installation:

roscore

The following output indicates that the installation was successful:

... logging to /home/robin/.ros/log/a5118af0-5474-11ea-8b86-e454e828c524/r
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://robin-G3-3590:34223/
ros_comm version 1.12.14
SUMMARY
========
PARAMETERS
* /rosdistro: kinetic
* /rosversion: 1.12.14
NODES
auto-starting new master
process[master]: started with pid [30244]
ROS_MASTER_URI=http://robin-G3-3590:11311/
setting /run_id to a5118af0-5474-11ea-8b86-e454e828c524
process[rosout-1]: started with pid [30261]
started core service [/rosout]

To create a new workspace, it is recommended to use catkin-tools to manage the workspace. After that, except for the startup of the PX4 simulation environment, the remaining ROS-related projects are managed in this workspace.

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash

Three, Gazebo installation

Whether it is ros Kinetic or Melodic, the built-in Gazebo has defects. If gazebo has been installed when ros is installed, it is recommended to uninstall and reinstall. It is recommended that the version of gazebo be above 9.13.
Please refer to the official website for Gazebo installation:
http://gazebosim.org/tutorials?tut=install_ubuntu&cat=install
Note:
1. Choose Alternative installation: step-by-step installation
2. Install Gazebo9.13 Or above

The installation of gazebo is also listed here for convenience

1. Set up your computer to accept software from package.osrfoundation.org

sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
cat /etc/apt/sources.list.d/gazebo-stable.list
#如果出现deb http://packages.osrfoundation.org/gazebo/ubuntu-stable xenial main表示没问题

2. Set the key

wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update

3. Install gazebo9.1 instructions:

sudo apt-get install gazebo9=9.1*

After installation, terminal input, gazeboif Gazebo is opened, the installation is successful

4.Gazebo itself is independent of ROS, so you also need to install the Gazebo plugin for ROS

sudo apt install ros-melodic-gazebo9-*
sudo apt install ros-melodic-gazebo-*

test

roscore  
rosrun gazebo_ros gazebo 

If Gazebo can be opened, the plug-in between Gazebo and ROS has also been installed successfully. You can also check the version of gazebo by
typinggazebo --version

Four, MAVROS installation

sudo apt install ros-melodic-mavros ros-melodic-mavros-extras
roscd mavros
sudo wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh 

The final sudo ./install_geographiclib_datasets.sh This step takes a while to install, please be patient

Five, PX4 configuration (version 1.11)

git clone https://github.com/PX4/Firmware
mv Firmware PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1
git submodule update --init --recursive

Since downloading the source code and updating the submodule is too slow, I have provided the downloaded and updated PX4_Firmware link here. After downloading, unzip and extract it in the main directory: https://download.csdn.net/download/qq_45067735/12713464

Install the necessary python dependencies:

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

Compile

make px4_sitl_default gazebo

If the compilation error prompts the ignition::math::Matrix4 xformV(vq); statement in PX4_Firmware/Tools/sitl_gazebo/src/gazebo_usv_dynamics_plugin.cpp; in the statement, xformV did not define the type before,
modify it to ignition::math::Matrix4 xformV( vq); Recompile after saving.

Modify ~/.bashrc in PX4_Firmware, add the following code, pay attention to the path matching

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

Then run the following command, Gazebo will start at this time, as shown in the figure below.

cd ~/PX4_Firmware
roslaunch px4 mavros_posix_sitl.launch

Insert picture description here
And run

rostopic echo /mavros/state

If connected: True, it means MAVROS and SITL communicate successfully.

---
header:
seq: 11
stamp:
secs: 1827
nsecs: 173000000
frame_id: ''
connected: True
armed: False
guided: False
manual_input: True
mode: "MANUAL"
system_status: 3
---

Note:
1. It is recommended to download scientifically online. The download speed on GitHub is relatively slow, and it may fail. I have also tried to modify the network and the effect is almost no. It is recommended to put the PX4 source code on GitHub on gitee before git clone. Please use the code cloud yourself. search for.
If you download the code on the code cloud, downloading from GitHub in the update submodule (git submodule update --init --recursive) is also very slow. This seems to need to modify the submodule, but I still don’t know how to operate , If there is a great god who wants to give some guidance.

2. The process of make px4_sitl_default gazebo may test the computer memory. Several times on my computer, the CPU is running at 100%, and the
situation may be as follows:

Insert picture description here
You can try to increase the temporary swap space first, and then execute the make px4_sitl_default gazebo command, or directly execute the make px4_sitl_default gazebo command again, which may require multiple executions.

#注释:of=/home/swap,放置swap的空间; count的大小就是增加的swap空间的大小,64M就是块大小,这里是64MB,所以总共空间就是bs*count=1024MB.这里分配空间的时候需要一点时间,等待执行完毕。
sudo dd if=/dev/zero of=/home/swap bs=64M count=16  

#注释:把刚才空间格式化成swap各式
sudo mkswap /home/swap (可能会提示warning: don't erase bootbits sectorson whole disk. Use -f to force,不用理会)


#注释:使刚才创建的swap空间
sudo swapon /home/swap

3. The following error may occur when the last command (make px4_sitl_default gazebo) is run:
Insert picture description here
Solution:

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

4. The following conditions may occur during operation:
Insert picture description here
Insert picture description herethese errors and warnings do not affect the use and can be ignored.

5. The process is slow when it runs for the first time. Gazebo may have a black screen for a while. In fact, this is initializing. Please wait patiently, as it will be the case later.

6. It is recommended to modify the ./bashrc file directly in the main directory, use control + h to view hidden files, copy the three lines above directly to the bottom and enter to source ~/.bashrcrestart barshc, so that it will be done once and for all, but after the modification, open the command every time The line will appear just added
Insert picture description here

6. QGC ground station installation (optional)

Installation link: https://docs.qgroundcontrol.com/en/getting_started/download_and_install.html After
startup, the screen shown below will appear. Note that Ubuntu16.04 cannot directly use QGroundcontrol version 4 series (version 3 series can be used). Ubuntu16.04 requires source code compilation version 4 series. Please check the installation link carefully.
Insert picture description here

Seven, XTDrone source download

git clone https://gitee.com/robin_shaun/XTDrone.git
cd XTDrone
cp sitl_config/init.d-posix/rcS ~/PX4_Firmware/ROMFS/px4fmu_common/init.d-posix/
cp sitl_config/worlds/* ~/PX4_Firmware/Tools/sitl_gazebo/worlds/
cp -r sitl_config/models/* ~/PX4_Firmware/Tools/sitl_gazebo/models
cp -r sitl_config/models/* ~/.gazebo/models/
cp sitl_config/launch/* ~/PX4_Firmware/launch/
#如果之前没有catkin_ws,需要建立一下,之后的教程会用到
mkdir -p ~/catkin_ws/src
mkdir -p ~/catkin_ws/scripts

Note: cp -r sitl_config/models/* ~/.gazebo/models/ This step may have the following situation:
Insert picture description here
you can leave it alone for now, continue with the following steps, and try again after compilation, or you may go to the corresponding manually Create a folder and then operate

8. Use keyboard to control drone flight

Run in a terminal

cd ~/PX4_Firmware
roslaunch px4 indoor1.launch

When running roslaunch px4 indoor1.launch for the first time, gazebo may take a while to load, please be patient

After Gazebo is started, run it in another terminal

cd ~/XTDrone/communication/
python multirotor_communication.py iris 0

After establishing communication with iris 0, run in another terminal

cd ~/XTDrone/control/
python multirotor_keyboard_control.py iris 1 vel

After success, as shown in the figure,
you can control the unlock/lock of an iris through the keyboard, modify the flight mode, aircraft speed, etc. Use the takeoff flight mode to take off with t, and the relevant parameters (takeoff speed, altitude) should be set in rcS. Generally, offboard mode can be used to take off. At this time, the take-off speed must be greater than 0.3m/s to take off. (Takeoff method: first press the t key to unlock, then press the i key to make the upward velocity greater than or equal to 0.3. At this time, you can see the rotor turning up, and finally press the b key to take off. The interval between the keys should be faster, otherwise the time If the interval is too long, the drone will automatically lock, and you have to repeat the steps just now) At
Insert picture description herethis point, the basic configuration of the simulation platform is completed.
Note: The
following errors may occur when roslaunch px4 indoor1.launch:
1.
Insert picture description here
See the solution: https://blog .csdn.net/abc869788668/article/details/78323395?locationNum=8&fps=1 Then
enter the following command:

sudo /opt/ros/melodic/lib/mavros/install_geographiclib_datasets.sh

It may take a long time and you need to wait patiently
. 2. The
Insert picture description here
original author said that it may be a 3D lidar problem, but after a few days of trying, I found that the installed gazebo9.0 will have the above error, and gazebo9.13 can run, you can try to install gazebo Change the version to 9.13 to try. This is why I recommend choosing melodic-desktop when installing ros and gazebo, and installing gazebo 9.13 or later.

Reference webpage:
[1]: https://www.yuque.com/xtdrone/manual_cn/basic_config_1.11
[2]: https://blog.csdn.net/qq_42585108/article/details/106781596
[3]: https ://blog.csdn.net/qq_44830040/article/details/106049992
[4]: https://blog.csdn.net/abc869788668/article/details/78323395?locationNum=8&fps=1

Guess you like

Origin blog.csdn.net/qq_45067735/article/details/107303796
Recommended