之前我们在做BetaFlight开源工程结构简明介绍的时候,有过一张开源飞控的介绍图谱。

从这张图谱我们看到基本上有5条轴线:

  1. Pixhawk // PX4
  2. Ardupilot
  3. OpenPilot
  4. MultiWii // baseflight/cleanflight/betaflight
  5. Paparazzi

BaseFlight/CleanFlight/BetaFlight目前在穿越机上的应用比较广泛。穿越机通常是小型机,比如:5寸以下。且整体起飞重量都比较轻,置空时间通常也就10分钟~30分钟范围。

航拍,无人巡航的角度,不是仅仅RC控制,更多功能需要通过地面站的接入处理。从这个角度来说,PX4就有很好的优势(这篇文章主要是介绍PX4,其他当然也有很好的Paparazzi等)。
飞控开源代码历史进程

1. PX4开发环境介绍

整个PX4开发环境可以用于非常多的实例:

  • Pixhawk和NuttX-based硬件
  • jMAVSim 仿真
  • Gazebo 仿真
  • Raspberry Pi
  • ROS (Robotics Operating System)
  • Fast DDS - Required for ROS2

注:这里主要介绍基于Ubuntu 20.04 LTS (Focal Fossa)的搭建。

2. PX4开发环境搭建

2.1代码下载

$ git clone https://github.com/PX4/PX4-Autopilot.git --recursive

2.2 国内环境调整

这些东西都是国外的,国内整体情况(比如:网络等)不理想,因此需要做一些调整。

  • 调整ubuntu本地apt升级路径:aliyun
$ sudo vi /etc/apt/sources.list
# deb cdrom:[Ubuntu 20.04.2.0 LTS _Focal Fossa_ - Release amd64 (20210209.1)]/ focal main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ focal universe
# deb-src http://hk.archive.ubuntu.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
# deb-src http://hk.archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
# deb-src http://hk.archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://hk.archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
# deb-src http://security.ubuntu.com/ubuntu focal-security universe
# deb-src http://security.ubuntu.com/ubuntu focal-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

  • 调整python3本地pip升级路径:tsinghua
diff --git a/Tools/setup/ubuntu.sh b/Tools/setup/ubuntu.sh
index 25c12cb170..8bdc7ae910 100755
--- a/Tools/setup/ubuntu.sh
+++ b/Tools/setup/ubuntu.sh
@@ -105,10 +105,10 @@ echo
 echo "Installing PX4 Python3 dependencies"
 if [ -n "$VIRTUAL_ENV" ]; then
        # virtual envrionments don't allow --user option
-       python -m pip install -r ${DIR}/requirements.txt
+       python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r ${DIR}/requirements.txt
 else
        # older versions of Ubuntu require --user option
-       python3 -m pip install --user -r ${DIR}/requirements.txt
+       python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --user -r ${DIR}/requirements.txt
 fi

 # NuttX toolchain (arm-none-eabi-gcc)

2.3 建立ubuntu开发环境

$ bash ./PX4-Autopilot/Tools/setup/ubuntu.sh

注:如果缺少2.2步骤,将会遇到非常多莫名其妙的问题,大体还是网络问题。

2.4 构建jMAVSim仿真

$ make px4_sitl jmavsim

2.5 补充版本信息

目前,使用git最新版本:

commit ffb0097052227e1b7dc2665463b6b9de33bbf835 (HEAD -> master, origin/master, origin/HEAD)
Author: CR <christopher.ruwisch@tu-berlin.de>
Date:   Wed Jun 22 21:50:30 2022 +0200

    removed unused code - _constrainOneSide and _constrainAbs

这个版本在实际使用过程存在一个问题,当2.4编译成功后,无法看到模拟GUI界面,主要是缺少ant组件,导致脚本jmavsim_run.sh的73行代码无法执行。

PX4-Autopilot/Tools/jmavsim_run.sh +73

ant create_run_jar copy_res

所以请确认ant是否已经安装:

$ sudo apt-get install ant

3. jmavsim仿真环境

jmavsim

3.1 仿真命令集

仿真环境下支持的命令列表如下:

pxh> help
Builtin Commands:
  actuator_test
  airship_att_control
  airspeed_selector
  attitude_estimator_q
  battery_simulator
  camera_feedback
  camera_trigger
  cdev_test
  commander
  commander_tests
  control_allocator
  controllib_test
  dataman
  dyn
  ekf2
  ex_fixedwing_control
  failure
  fake_gps
  fake_imu
  fake_magnetometer
  flight_mode_manager
  fw_att_control
  fw_autotune_attitude_control
  fw_pos_control_l1
  gimbal
  gps
  gyro_calibration
  gyro_fft
  hello
  hrt_test
  land_detector
  landing_target_estimator
  led_control
  list_files
  list_tasks
  listener
  load_mon
  local_position_estimator
  logger
  mag_bias_estimator
  manual_control
  mavlink
  mavlink_tests
  mc_att_control
  mc_autotune_attitude_control
  mc_hover_thrust_estimator
  mc_pos_control
  mc_rate_control
  mixer
  motor_test
  navigator
  param
  perf
  pwm
  pwm_out_sim
  px4_mavlink_debug
  px4_simple_app
  rc_tests
  rc_update
  replay
  rover_pos_control
  rover_steering_control
  rpm_simulator
  sd_bench
  send_event
  sensor_baro_sim
  sensor_gps_sim
  sensor_mag_sim
  sensors
  shutdown
  sih
  simulator
  sleep
  system_time
  temperature_compensation
  tests
  tone_alarm
  tune_control
  uorb
  uorb_tests
  uuv_att_control
  uuv_example_app
  uuv_pos_control
  ver
  vtol_att_control
  work_item_example
  work_queue
  wqueue_test

3.2 命令实例

举例:
commander takeoff //起飞
commander land //降落

注:由于我的遥控器距离有问题,去维修了(四轴飞控DIY集成FPV功能),有兴趣的朋友可以跑下QGroundControl。后续有时间再做更新!!!

4. QGroundControl & RC遥控模拟配置

上次我们说过要做后续更新,更新就是如何基于模拟器来简单实现一些基本飞控操作。这个主要还是在于PX4模块设计之一:SITL & HITL模拟框架。这里主要还是基于SITL这个框架做了一个QGroundControl远程连接,以及QGroundControl上连接一个模拟遥控器(采用BetaFlight KakuteF7 + ELRS遥控,真实设备)

注:BetaFlight固件(4.2.11)是支持作为模拟器输入,便于更好的使用仿真软件来学习手动飞行。

SITL

4.1 QGroundControl配置

新建一个连接,并将配置接到SITL的18570端口上。这样PX4 SITL软件可以跑在一台电脑(通常大家习惯Windows系统)上,而编译系统(Ubuntu 20.4)编译PX4 SITL跑在编译机器上做仿真。
Application Settings具体QGroundControl的配置如下,记得使用前一定要Connect哦!!!
18570 SITL端口注:QGroundControl使用

4.2 RC遥控器配置

首先,要根据4.1章节,先Connect;这样Vehicle Setup才会出来。出来以后接上自己的模拟遥控器咯,把USB插上去就OK了。
遥控器配置界面看到设备以后,第一次一定要校准。
遥控器校准

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐