0

阿木币

0

精华

182 小时

在线时间

技术大V

Rank: 4

发表于 2022-5-11 16:16:00 1892 浏览 1 回复

[入门教程] PX4 混控部分分析

本帖最后由 chasing 于 2022-5-11 16:19 编辑

PX4的混控部分大体思路和ardupilot是一致的, 更多的PX4采用的是脚本读取的形式完成其中的读取,转换以及最后的应用.
首先从机型选择后,对应为toml文件, 如下图所示:

                               
登录/注册后可看大图

采用对应的px_generate_mixers.py来自动生成对应的文件, 该脚本提取toml中的参数, 进行生成, 脚本如下图所示

                               
登录/注册后可看大图

对应python代码中的主函数是通过解析附带的输入参数完成识别, 具体可以参看同级路径下的CMakeLists.txt完成

  1. if __name__ == '__main__':
  2.     import argparse
  3.     import glob
  4.     import os

  5.     # Parse arguments
  6.     parser = argparse.ArgumentParser(
  7.         description='Convert geometry .toml files to mixer headers')
  8.     parser.add_argument('-d', dest='dir',
  9.                         help='directory with geometry files')
  10.     parser.add_argument('-f', dest='files',
  11.                         help="files to convert (use only without -d)",
  12.                         nargs="+")
  13.     parser.add_argument('-o', dest='outputfile',
  14.                         help='output header file')
  15.     parser.add_argument('--verbose', help='Print details on standard output',
  16.                         action='store_true')
  17.     parser.add_argument('--normalize', help='Use normalized mixers (compatibility mode)',
  18.                         action='store_true')
  19.     parser.add_argument('--sixdof', help='Use 6dof mixers',
  20.                         action='store_true')
  21.     args = parser.parse_args()
复制代码
生成文件为mixer_multirotor_normalized.generated.h, 部分截图保存如下
  

                               
登录/注册后可看大图

随后, 在使用阶段, 全局搜索关键词 from_text, 可以看到如下内容

                               
登录/注册后可看大图

继续顺藤摸瓜, 创建MultirotorMixer的对象

                               
登录/注册后可看大图

上图中 _rotors(_config_index[]), 则对应生成的系数矩阵.
在程序的循环使用中, (只测试了对应的jmavsim仿真程序) , airmode = 0

                               
登录/注册后可看大图


最后附上mix_airmode_rp的函数内容
  1. void MultirotorMixer::mix_airmode_rp(float roll, float pitch, float yaw, float thrust, float *outputs)
  2. {
  3.         // Airmode for roll and pitch, but not yaw

  4.         // Mix without yaw
  5.         for (unsigned i = 0; i < _rotor_count; i++) {
  6.                 outputs = roll * _rotors.roll_scale +
  7.                              pitch * _rotors.pitch_scale +
  8.                              thrust * _rotors.thrust_scale;

  9.                 // Thrust will be used to unsaturate if needed
  10.                 _tmp_array = _rotors.thrust_scale;
  11.         }

  12.         minimize_saturation(_tmp_array, outputs, _saturation_status);

  13.         // Mix yaw independently
  14.         mix_yaw(yaw, outputs);
  15. }
复制代码
Remark: 最终的PWM输出口是在px4.io中完成.


扫一扫浏览分享
回复

使用道具 举报

131

阿木币

0

精华

272 小时

在线时间

管理员

Rank: 9Rank: 9Rank: 9

发表于 2022-5-31 08:46:44
我不为己,谁人为我,但我只为己,那我又是谁?
回复

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表