分享

PX4模块设计之二十九:RCUpdate模块

 netouch 2023-07-03 发布于北京

1. RCUpdate模块简介

### Description

The rc_update module handles RC channel mapping: read the raw input channels (`input_rc`),
then apply the calibration, map the RC channels to the configured channels & mode switches
and then publish as `rc_channels` and `manual_control_input`.

### Implementation

To reduce control latency, the module is scheduled on input_rc publications.

rc_update <command> [arguments...]
 Commands:
   start

   stop

   status        print status info

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

class RCUpdate : public ModuleBase<RCUpdate>, public ModuleParams, public px4::WorkItem

注:RCUpdate模块采用了ModuleBaseWorkQueue设计。

2. 模块入口函数

2.1 主入口rc_update_main

同样继承了ModuleBase,由ModuleBase的main来完成模块入口。

rc_update_main
 └──> return rc_update::RCUpdate::main(argc, argv)

2.2 自定义子命令custom_command

模块仅支持start/stop/status命令,不支持其他自定义命令。

RCUpdate::custom_command
 └──> return print_usage("unknown command");

2.3 模块状态print_status【重载】

RCUpdate::print_status
 ├──> PX4_INFO_RAW("Running\n");
 ├──> <_channel_count_max > 0>
 │   ├──> PX4_INFO_RAW(" #  MIN  MAX TRIM  DZ REV\n");
 │   └──> <for (int i = 0; i < _channel_count_max; i++>
 │       └──> PX4_INFO_RAW("%2d %4d %4d %4d %3d %3d\n", i, _parameters.min[i], _parameters.max[i], _parameters.trim[i], _parameters.dz[i], _parameters.rev[i])
 ├──> perf_print_counter(_loop_perf);
 ├──> perf_print_counter(_loop_interval_perf);
 ├──> perf_print_counter(_valid_data_interval_perf);
 └──> return 0;

3. RCUpdate模块重要函数

3.1 task_spawn

这里主要初始化了RCUpdate对象,后续通过WorkQueue来完成触发RCUpdate::Run。

RCUpdate::task_spawn
 ├──> RCUpdate *instance = new RCUpdate();
 ├──> <instance>
 │   ├──> _object.store(instance);
 │   ├──> _task_id = task_id_is_work_queue;
 │   └──> <instance->init()>
 │       └──> return PX4_OK;
 ├──> <else>
 │   └──> PX4_ERR("alloc failed");
 ├──> delete instance;
 ├──> _object.store(nullptr);
 ├──> _task_id = -1;
 └──> return PX4_ERROR;

3.2 instantiate

注:鉴于该模块不采用任务(线程),所以ModuleBase::run_trampoline无需执行,所以可以不实现。

3.3 init

在task_spawn中使用,对_input_rc_sub成员变量进行事件回调注册(当有input_rc消息时,会调用SubscriptionCallbackWorkItem::ScheduleNow,再触发RCUpdate::Run过程)。

RCUpdate::init
 ├──> !_input_rc_sub.registerCallback()> 
 │   ├──> PX4_ERR("callback registration failed");
 │   └──> return false;
 └──> return true;

注1:这里真正调用ScheduleNow的不是RCUpdate类,而是该类内部成员变量_input_rc_sub。

uORB::SubscriptionCallbackWorkItem _input_rc_sub{this, ORB_ID(input_rc)};

注2:这里订阅的input_rc来自前面的分析:PX4模块设计之二十八:RCInput模块

3.4 Run

每次RCInput更新发布后,RCInput模块检测RC信号丢失并决策signal_lost,发布manual_control_input/manual_control_switches/actuator_controls_3/rc_channels消息。

RCUpdate::Run
 ├──> [优雅退出处理]
 ├──> <_parameter_update_sub.updated()>
 │   ├──> _parameter_update_sub.copy(&pupdate);
 │   ├──> updateParams();
 │   └──> parameters_updated();
 ├──> rc_parameter_map_poll  //更新rc_parameter_map_s
 └──> <_input_rc_sub.update(&input_rc)>
     ├──> [未检测到RC信号丢失,当信号源异常(_channel_count_previous/_input_source_previous与当前控制报文不一致)时,进行告警]
     ├──> [判别当前报文signal_lost状态,并记录到_rc_signal_lost_hysteresis]
     ├──> <input_source_stable && channel_count_stable && !_rc_signal_lost_hysteresis.get_state()>
     │   └──> [only publish manual control if the signal is present and regularly updating]
     └──> <else>
         └──> [RC input unstable or lost, clear any previous manual_switches]

4. 总结

RCInput和RCUpdate模块整体上处理了和RC(遥控器)相关的控制操作,检测/判断/决策控制状态,并将控制信号转换成内部的uORB消息进行发布。

5. 参考资料

【1】PX4开源软件框架简明简介
【2】PX4模块设计之十一:Built-In框架
【3】PX4模块设计之十二:High Resolution Timer设计
【4】PX4模块设计之十三:WorkQueue设计
【5】PX4模块设计之十七:ModuleBase模块
【6】PX4 modules_main
【7】PX4模块设计之二十八:RCInput模块

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多