1.在虚拟机上安装Ubuntu20.04
需注意内存选20G不够,后续很麻烦,建议选50-80G
!!!建议不要在VM下安,后续很麻烦。需要在WSL下安ubuntu系统
2.安装PX4
参考:Ubuntu20.04+MAVROS+PX4+Gazebo保姆级安装教程_ubuntu20.04安装px4-CSDN博客
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot/
git submodule update --init --recursive
将GeographicLib安装包放在usr/share下 再进行下一步:
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
3.安装ROS(20.04对于ros-noetic版本)
参考: Ubuntu20.04+ROS1+PX4+Gazebo仿真(三)环境配置 - 哔哩哔哩
wget http://fishros.com/install -O fishros && sudo bash fishros
选择1:一键安装
选择1:更换系统源
选择1:仅更换系统源
选择3:noetic(对应ubuntu20.04)
选择1:桌面版
再次运行:
wget http://fishros.com/install -O fishros && sudo bash fishros
选择3:一键安装:rosden
根据提示选择rosdeoc update
测试:(打开三个终端)
第一个:
roscore
第二个:
rosrun turtlesim turtlesim_node
成功的话会打开小乌龟
第三个:
rosrun turtlesim turtle_teleop_key
添加环境:
gedit ~/.bashrc
在底部添加一行:
export PATH="$PATH:/home/gb/.local/bin"
更新numpy:
pip install --upgrade numpy
安装ant:
sudo apt install ant
安装OpenJDK:
sudo apt install default-jdk
4.测试(gazebo或jmavsim)
cd PX4-Autopilot
make px4_sitl gazebo
或者
cd PX4-Autopilot
make px4_sitl jmavsim
终端输入:(控制无人机起飞和降落)
commander takeoff
commander land
5.安装QGC地面站
参考官方给的教程
Download and Install | QGC Guide (master)
终端输入:
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 libfuse2 -y
sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor-dev -y
初次使用AppImage需加入权限:
sudo chmod +x ./QGroundControl.AppImage
启动QGC
./QGroundControl.AppImage
再打开一个终端启动gazebo或jmavsim:
cd PX4-Autopilot
make px4_sitl gazebo
cd PX4-Autopilot
make px4_sitl jmavsim
在QGC中起飞无人机,滑动解锁
6.安装MAVROS
sudo apt-get install ros-noetic-mavros ros-noetic-mavros-extras
安装 GeographicLib 的数据集:
wget https://gitee.com/robin_shaun/XTDrone/raw/master/sitl_config/mavros/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh
环境变量的配置:
sudo gedit ~/.bashrc
将下面的内容添加到底部并保存
source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot/ ~/PX4-Autopilot/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/sitl_gazebo
运行以下命令测试:
roslaunch mavros px4.launch
此时会报错:
是没有连接硬件所致。
7.AirSim环境(与UE4)搭建
参考:
Airsim自动驾驶仿真 - 01:Airsim下载安装与运行_airsim安装-CSDN博客
8.联动Ubuntu系统(QGC+PX4)与Windows(AirSim)系统
1)建立WSL连接如下
步骤1:在Ubuntu系统查询IP地址并修改虚拟网络编辑器的VMnet8的DHCP设置
步骤2:windows控制面板-网络和Internet-更改适配器选项-双击Internet协议版本4-
Ubuntu输入
ping 192.168.181.129
Windows 输入:
ping 192.168.181.129
已ping通
2)软件模拟:
步骤1:Windows端:
修改settings.json文件为:
{
"SettingsVersion": 1.2,
"SimMode": "Multirotor",
"ClockType": "SteppableClock",
"Vehicles": {
"PX4": {
"VehicleType": "PX4Multirotor",
"UseSerial": false,
"LockStep": true,
"UseTcp": true,
"TcpPort": 4560,
"ControlIp": "remote",
"ControlPortLocal": 14540,
"ControlPortRemote": 14580,
"LocalHostIp": "172.19.160.1",
"Sensors":{
"Barometer":{
"SensorType": 1,
"Enabled": true,
"PressureFactorSigma": 0.0001825
},
"Imu": {
"SensorType": 2,
"Enabled" : true,
"AngularRandomWalk": 0.3,
"GyroBiasStabilityTau": 500,
"GyroBiasStability": 4.6,
"VelocityRandomWalk": 0.24,
"AccelBiasStabilityTau": 800,
"AccelBiasStability": 36
},
"Gps": {
"SensorType": 3,
"Enabled" : true,
"EphTimeConstant": 0.9,
"EpvTimeConstant": 0.9,
"EphInitial": 25,
"EpvInitial": 25,
"EphFinal": 0.1,
"EpvFinal": 0.1,
"EphMin3d": 3,
"EphMin2d": 4,
"UpdateLatency": 0.2,
"UpdateFrequency": 50,
"StartupDelay": 1
},
"Distance": {
"SensorType": 5,
"Enabled" : true,
"MinDistance": 0.2,
"MaxDistance": 40,
"X": 0, "Y": 0, "Z": -1,
"Yaw": 0, "Pitch": 0, "Roll": 0,
"DrawDebugPoints": true
},
"Lidar": {
"SensorType": 6,
"Enabled": true,
"NumberOfChannels": 16,
"RotationsPerSecond": 10,
"PointsPerSecond": 100000,
"X": 1, "Y": 0, "Z": 0,
"Roll": 0, "Pitch": 0, "Yaw": 0,
"VerticalFOVUpper": 10,
"VerticalFOVLower": -10,
"HorizontalFOVStart": -20,
"HorizontalFOVEnd": 20,
"DrawDebugPoints": true,
"DataFrame": "SensorLocalFrame"
}
},
"Parameters": {
"NAV_RCL_ACT": 0,
"NAV_DLL_ACT": 0,
"COM_OBL_RC_ACT": 2,
"COM_OBS_AVOID": 0,
"LPE_LAT": 47.641468,
"LPE_LON": -122.140165
}
}
}
}
启动airsim
步骤2:Ubuntu 端:
首次使用PX4需要进.bashrc操作一下,修改为windows的WSL的ip:
gedit ~/.bashrc
export PX4_SIM_HOST_ADDR=172.19.160.1
source ~/.bashrc
sudo ufw allow 4560
sudo ufw allow 10049
cd PX4-Autopilot
make px4_sitl_default none_iris
(启动AirSim 之后才能PX4启动成功,否则就会显示未建立4560连接)
打开QGroundcontrol
语言改为英文,不然设置不了航点
成功:可以通过虚拟摇杆操控无人机
存在问题:windows与Ubuntu ping通 但建立WSL连接建立不成功:
在windows的cmd中打开Ubuntu:ping 192.168.181.129
再返回发输入ipconfig则发现:WSL连接成功
3)硬件在环
此时需要用Ubuntu下的PX4,windows下的AirSim和QGC
步骤一,二如前面;
步骤三:QGC中:
在ubuntu中查看IP(可能跟之前不一样)
在PX4和AirSim都打开后连接
PX4后面显示mavlink则表示连接成功
步骤四:连接游戏手柄
由于之前试过连接Pixhawk和QGC,成功更新固件,但是隔了半年就不行了:
浪费好大功夫,准备下载MP地面站时发现驱动没更新,更新驱动后回来发现QGC也好了: