PX4开发环境搭建--模拟器编译

Posted lida2003

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PX4开发环境搭建--模拟器编译相关的知识,希望对你有一定的参考价值。

PX4开发环境搭建--模拟器编译

之前我们在做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仿真环境

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功能),所以没法实际操作。后续有时间再做更新!!!

以上是关于PX4开发环境搭建--模拟器编译的主要内容,如果未能解决你的问题,请参考以下文章

PX4模块设计之八:Ubuntu 20.04搭建FlightGear模拟器

ubuntu配置px4编译环境

Android 逆向Android 进程注入工具开发 ( 总结 | 源码编译 | 逆向环境搭建使用 | 使用进程注入工具进行逆向操作 ) ★★★

OpenGL学习进程OpenGL开发环境的搭建

完整的Ubuntu20.04+ROS+PX4+Anaconda+PyTorch+GPU+CUDA+CUDNN+XTdrone配置智能无人机开发环境搭建过程

week45 无人机px4 Firmware仿真环境搭建