PX4模块设计之四十五:param模块

2023-05-16

PX4模块设计之四十五:param模块

  • 1. param模块简介
  • 2. 模块入口函数param_main
  • 3 重要函数列表
  • 4. 总结
  • 5. 参考资料

1. param模块简介

### Description
Command to access and manipulate parameters via shell or script.

This is used for example in the startup script to set airframe-specific parameters.

Parameters are automatically saved when changed, eg. with `param set`. They are typically stored to FRAM
or to the SD card. `param select` can be used to change the storage location for subsequent saves (this will
need to be (re-)configured on every boot).

If the FLASH-based backend is enabled (which is done at compile time, e.g. for the Intel Aero or Omnibus),
`param select` has no effect and the default is always the FLASH backend. However `param save/load <file>`
can still be used to write to/read from files.

Each parameter has a 'used' flag, which is set when it's read during boot. It is used to only show relevant
parameters to a ground control station.

### Examples
Change the airframe and make sure the airframe's default parameters are loaded:
$ param set SYS_AUTOSTART 4001
$ param set SYS_AUTOCONFIG 1
$ reboot

param <command> [arguments...]
 Commands:
   load          Load params from a file (overwrite all)
     [<file>]    File name (use default if not given)

   import        Import params from a file
     [<file>]    File name (use default if not given)

   save          Save params to a file
     [<file>]    File name (use default if not given)

   dump          Dump params from a file
     [<file>]    File name (use default if not given)

   select        Select default file
     [<file>]    File name

   select-backup Select default file
     [<file>]    File name

   show          Show parameter values
     [-a]        Show all parameters (not just used)
     [-c]        Show only changed params (unused too)
     [-q]        quiet mode, print only param value (name needs to be exact)
     [<filter>]  Filter by param name (wildcard at end allowed, eg. sys_*)

   show-for-airframe Show changed params for airframe config

   status        Print status of parameter system

   set           Set parameter to a value
     <param_name> <value> Parameter name and value to set
     [fail]      If provided, let the command fail if param is not found

   set-default   Set parameter default to a value
     [-s]        If provided, silent errors if parameter doesn't exists
     <param_name> <value> Parameter name and value to set
     [fail]      If provided, let the command fail if param is not found

   compare       Compare a param with a value. Command will succeed if equal
     [-s]        If provided, silent errors if parameter doesn't exists
     <param_name> <value> Parameter name and value to compare

   greater       Compare a param with a value. Command will succeed if param is
                 greater than the value
     [-s]        If provided, silent errors if parameter doesn't exists
     <param_name> <value> Parameter name and value to compare
     <param_name> <value> Parameter name and value to compare

   touch         Mark a parameter as used
     [<param_name1> [<param_name2>]] Parameter name (one or more)

   reset         Reset only specified params to default
     [<param1> [<param2>]] Parameter names to reset (wildcard at end allowed)

   reset_all     Reset all params to default
     [<exclude1> [<exclude2>]] Do not reset matching params (wildcard at end
                 allowed)

   index         Show param for a given index
     <index>     Index: an integer >= 0

   index_used    Show used param for a given index
     <index>     Index: an integer >= 0

   find          Show index of a param
     <param>     param name

注:print_usage函数是具体对应实现。

2. 模块入口函数param_main

该模块纯C语言风格,没有C++类继承或者C/C++混合的编码风格,整体看起来就很清爽。

注:C++设计一定要建模,一定要做好概念抽象。至于C/C++那种混合的编程风格,笔者是不建议的。

param_main
 ├──> <argc < 2>  // 参数不够,直接提供打印帮助!!!
 │   └──> print_usage()
 ├──> <!strcmp(argv[1], "save")> // save 子命令
 │   ├──> <argc >= 3>
 │   │   └──> do_save(argv[2])
 │   └──> <else>
 │       └──> do_save_default()
 ├──> <!strcmp(argv[1], "dump")> // dump 子命令
 │   ├──> <argc >= 3>
 │   │   └──> do_dump(argv[2])
 │   └──> <else>
 │       └──> do_dump(param_get_default_file())
 ├──> <!strcmp(argv[1], "load")> // load 子命令
 │   ├──> <argc >= 3>
 │   │   └──> do_load(argv[2])
 │   └──> <else>
 │       └──> do_load(param_get_default_file())
 ├──> <!strcmp(argv[1], "import")> // import 子命令
 │   ├──> <argc >= 3>
 │   │   └──> do_import(argv[2])
 │   └──> <else>
 │       └──> do_import()
 ├──> <!strcmp(argv[1], "select")> // select 子命令
 │   ├──> <argc >= 3>
 │   │   └──> param_set_default_file(argv[2])
 │   ├──> <else>
 │   │   └──> param_set_default_file(nullptr)
 │   ├──> const char *default_file = param_get_default_file()
 │   └──> <default_file> PX4_INFO("selected parameter default file %s", default_file)
 ├──> <!strcmp(argv[1], "select-backup")> // select-backup 子命令
 │   ├──> <argc >= 3>
 │   │   └──> param_set_backup_file(argv[2])
 │   ├──> <else>
 │   │   └──> param_set_backup_file(nullptr)
 │   ├──> const char *backup_file = param_get_backup_file()
 │   └──> <backup_file> PX4_INFO("selected parameter backup file %s", backup_file)
 ├──> <!strcmp(argv[1], "show")>  // show 子命令
 │   ├──> <argc >= 3>
 │   │   ├──> <!strcmp(argv[2], "-c")>  // optional argument -c to show only non-default params
 │   │   │    ├──> <argc >= 4>
 │   │   │    │   └──> do_show(argv[3], true)
 │   │   │    └──> <else>
 │   │   │        └──> do_show(nullptr, true)
 │   │   ├──> <!strcmp(argv[2], "-a")>
 │   │   │    └──> do_show_all()
 │   │   ├──> <!strcmp(argv[2], "-q")>
 │   │   │    └──> <argc >= 4> do_show_quiet(argv[3])
 │   │   └──> <else>
 │   │        └──> do_show(argv[2], false)
 │   └──> <else>
 │       └──> do_show(nullptr, false)
 ├──> <!strcmp(argv[1], "show-for-airframe")>  // show-for-airframe 子命令
 │   └──> do_show_for_airframe()
 ├──> <!strcmp(argv[1], "status")>  // status 子命令
 │   └──> param_print_status()
 ├──> <!strcmp(argv[1], "set")>  // set 子命令
 │   ├──> <argc >= 5>
 │   │   ├──> bool fail = !strcmp(argv[4], "fail")  //if the fail switch is provided, fails the command if not found
 │   │   └──> return do_set(argv[2], argv[3], fail)
 │   └──> <argc >= 4> do_set(argv[2], argv[3], false)
 ├──> <!strcmp(argv[1], "set-default")>  // set-default 子命令
 │   ├──> <argc >= 5 && !strcmp(argv[2], "-s")> do_set_custom_default(argv[3], argv[4], true)
 │   └──> <argc == 4> do_set_custom_default(argv[2], argv[3])
 ├──> <!strcmp(argv[1], "compare")> // compare 子命令
 │   ├──> <argc >= 5 && !strcmp(argv[2], "-s")> do_compare(argv[3], &argv[4], argc - 4, COMPARE_OPERATOR::EQUAL, COMPARE_ERROR_LEVEL::SILENT)
 │   └──> <argc >= 4> do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR::EQUAL, COMPARE_ERROR_LEVEL::DO_ERROR)
 ├──> <!strcmp(argv[1], "greater")>  // greater 子命令
 │   ├──> <argc >= 5 && !strcmp(argv[2], "-s")> do_compare(argv[3], &argv[4], argc - 4, COMPARE_OPERATOR::GREATER, COMPARE_ERROR_LEVEL::SILENT)
 │   └──> <argc >= 4> do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR::GREATER, COMPARE_ERROR_LEVEL::DO_ERROR)
 ├──> <!strcmp(argv[1], "reset")>  //reset 子命令
 │   └──> <argc >= 3> do_reset_specific((const char **) &argv[2], argc - 2)
 ├──> <!strcmp(argv[1], "reset_all")>  //reset_all 子命令
 │   ├──> <argc >= 3>
 │   │   └──> do_reset_all((const char **) &argv[2], argc - 2)
 │   └──> <else>
 │       └──> do_reset_all(nullptr, 0)
 ├──> <!strcmp(argv[1], "touch")>  // touch 子命令
 │   └──> <argc >= 3> do_touch((const char **) &argv[2], argc - 2)
 ├──> <!strcmp(argv[1], "index_used")>  // index_used 子命令
 │   └──> <argc >= 3> do_show_index(argv[2], true)
 ├──> <!strcmp(argv[1], "index")>  // index 子命令
 │   └──> <argc >= 3> do_show_index(argv[2], false)
 └──> <!strcmp(argv[1], "find")>  // find 子命令
     └──> <argc >= 3> do_find(argv[2])

3 重要函数列表

所有参数相关操作都是使用了Parameters API,关于全局参数存储 Parameters API这里不做展开,详见:src/lib/Parameters, param.h

  1. do_save
  2. do_save_default
  3. do_dump
  4. do_load
  5. do_import
  6. param_set_default_file
  7. param_set_backup_file
  8. do_show
  9. do_show_for_airframe
  10. param_print_status
  11. do_set
  12. do_set_custom_default
  13. do_compare
  14. do_reset_specific
  15. do_reset_all
  16. do_touch
  17. do_show_index
  18. do_find

4. 总结

该模块主要提供了系统参数的动态更新/固化保存,以及提供了参数修正的底层操作方法。

5. 参考资料

【1】PX4开源软件框架简明简介
【2】PX4模块设计之十一:Built-In框架
【3】PX4模块设计之十二:High Resolution Timer设计
【4】PX4模块设计之十三:WorkQueue设计
【5】PX4模块设计之十七:ModuleBase模块
【6】PX4模块设计之三十:Hysteresis类
【7】PX4 modules_main
【8】PX4模块设计之四十一:I2C/SPI Bus Instance基础知识

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PX4模块设计之四十五:param模块 的相关文章

  • 编译PX4固件

    PX4编译 文章目录 PX4编译疑难杂症bug1bug2catkin build isolated 官方脚本Step1Step2 安装常用依赖Step3 创建并运行脚本Step4 补全代码子模块Step5 验证仿真 官方offboard 例
  • 【2020-8-9】APM,PX4,GAZEBO,MAVLINK,MAVROS,ROS之间的关系以及科研设备选型

    0 概述 无人机自主飞行平台可以分为四个部分 xff1a 动力平台 xff0c 飞行控制器 xff0c 机载电脑和模拟平台 动力平台 xff1a 负责执行飞行任务 xff0c 包括螺旋桨 电机 机架等 xff0c 用于科研的一般都是F380
  • 【8-12】树莓派部署t265+px4飞控实现无人机视觉定位

    在之前的文章中 xff0c 我们已经成功在树莓派 xff08 ubuntu mate 18 04 xff09 上部署了T265的追踪摄像头 本文将利用MAVROS协议 xff0c 将T265测量的位姿信息发送给px4固件 xff0c 实现室
  • PX4位置控制offboard模式说明

    offboard模式的开发及应用 一 px4固件的模式 px4固件支持10几种飞行模式 xff0c 从代码结构上分析 xff0c 分为基本模式 自定义模式和自定义子模式 1 基本模式 基本模式又分为 xff0c 位置控制模式 自稳模式 手动
  • PX4+Offboard模式+代码控制无人机起飞(Gazebo)

    参考PX4自动驾驶用户指南 https docs px4 io main zh ros mavros offboard cpp html 我的另一篇博客写了 键盘控制PX4无人机飞行 PX4无人机 键盘控制飞行代码 可以先借鉴本篇博客 xf
  • 从Simulink到PX4——Simulink-PX4插件安装与环境搭建

    从Simulink到PX4 Simulink PX4插件安装与环境搭建 前言0 准备工作1 安装WSL2 Setting up the PX4 Toolchain on Windows3 Setting up the PX4 Tool Ch
  • PX4模块设计之三:自定义uORB消息

    PX4模块设计之三 xff1a 自定义uORB消息 1 新增自定义uORB消息步骤2 应用ext hello world消息示例3 编译执行结果4 参考资料 基于PX4开源软件框架简明简介和PX4模块设计之二 xff1a uORB消息代理
  • PX4模块设计之四:MAVLink简介

    PX4模块设计之四 xff1a MAVLink简介 1 MAVLink PX4 应用简介2 MAVLink v2 0新特性3 MAVLink协议版本4 MAVLink通信协议帧4 1 MAVLink v1 0 帧格式4 2 MAVLink
  • PX4模块设计之三十三:Sensors模块

    PX4模块设计之三十三 xff1a Sensors模块 1 Sensors模块简介2 模块入口函数2 1 主入口sensors main2 2 自定义子命令custom command2 3 模块状态print status 重载 3 Se
  • PX4模块设计之四十六:dataman模块

    PX4模块设计之四十六 xff1a dataman模块 1 dataman模块简介2 模块入口函数dataman main3 dataman模块重要函数3 1 start3 2 stop3 3 status3 4 task main 4 A
  • @Param注解的用法解析

    实例一 64 Param注解单一属性 dao层示例 Public User selectUser 64 param userName String name 64 param userpassword String password xml
  • PX4-4-任务调度

    PX4所有的功能都封装在独立的模块中 xff0c uORB是任务间数据交互和同步的工具 xff0c 而管理和调度每个任务 xff0c PX4也提供了一套很好的机制 xff0c 这一篇我们分享PX4的任务调度机制 我们以PX4 1 11 3版
  • PX4 OffBoard Control

    终于还是走上了这一步 xff0c 对飞控下手 xff0c 可以说是一张白纸了 记录一下学习的过程方便以后的查阅 目录 一 ubuntu18 04配置px4编译环境及mavros环境 二 PX4的OffBoard控制 1 搭建功能包 2 编写
  • 步骤八:PX4使用cartographer与move_base进行自主建图导航

    首先老样子硬件如下 飞控 HOLYBRO PIXHAWK V4 PX4 机载电脑 jetson nano b01 激光雷达 思岚a2 前提 你已经完成了cartographer建图部分 能够正常输出map话题 前言 由于要参加中国机器人大赛
  • PX4项目学习::(五)模块代码启动流程

    54条消息 PX4 模块代码启动流程 zhao23333的博客 CSDN博客
  • 飞行姿态解算(三)

    继之前研究了一些飞行姿态理论方面的问题后 又找到了之前很流行的一段外国大神写的代码 来分析分析 第二篇文章的最后 讲到了文章中的算法在实际使用中有重大缺陷 大家都知道 分析算法理论的时候很多情况下我们没有考虑太多外界干扰的情况 原因是很多情
  • 将 urlencoded URL 作为参数传递给 CakePHP 的控制器/操作

    我对 CakePHP 相当陌生 因此 我以前用 Zend Framework 做的一些基本事情被 Cake 打败了 我正在开发一个项目 我必须将命名参数传递给控制器 操作 设置路由并传递参数相当简单 我的问题是当参数是 urlencoded
  • Struts2将参数传递给不同webapp中的action

    我使用Struts 2 3 16 3 我希望 webapp 1 中的操作将参数传递给 webapp 2 中的操作 在 webapp 1 的 struts xml 中 我定义了以下结果
  • 为什么 jsp:include 参数不可见

    我有完全相同的基本问题关于访问 jsp param 值 https stackoverflow com questions 3698068 jsp include with parameters usage simple question正
  • 在 angularjs 中转换 $.param

    在我使用 JQuery 之前 我使用它来发送带有参数的 URL window location myUrl param paramName ok anotherParam hello 但对于 angularjS 来说 这并不以同样的方式工作

随机推荐