APM新添加UAVCAN设备

简介

UAVCAN是一种轻量级协议,旨在通过CAN总线在航空航天和机器人应用中实现可靠通信。要实现通信,最基本需要data_type_ id, signature、数据结构、设备程序初始化。

添加设备数据结构文件(.uavcan格式)

1.在以下路径添加设备数据结构文件,根据设备类型选择对应的文件夹。这里使用actuator示例。

/ardupilot/modules/DroneCAN/DSDL/uavcan/equipment/actuator

2.新添加2018.HimarkServos.uavcan(发布功能)和2019.HimarkStatus.uavcan(订阅功能)
在这里插入图片描述
3.在2018.HimarkServos.uavcan和2019.HimarkStatus.uavcan中添加数据类型:(参考其他uavcan文件格式)
在这里插入图片描述
!](https://img-blog.csdnimg.cn/d7639dd3bcc94717904cb09daf01db76.png)

使用libuavcan_dsdlc生成.hpp头文件

1.要生成.hpp文件,需要使用libuavcan_dsdlc编译生成,基于python,可以在wscript文件配置自动生成。(生成.hpp文件后可以注释这段代码)

参考路径:Ardupilot/ArduCopter/wscript
在文件内添加以下代码:
bld(
        # build libcanard headers
        source=bld.path.ant_glob("modules/DroneCAN/DSDL/**/*.uavcan"),
        rule="python3 ${SRCROOT}/modules/uavcan/libuavcan/dsdl_compiler/libuavcan_dsdlc --outdir ${BUILDROOT}/modules/DroneCAN/libcanard/dsdlc_generated ${SRCROOT}/modules/DroneCAN/DSDL/uavcan ${SRCROOT}/modules/DroneCAN/DSDL/ardupilot ${SRCROOT}/modules/DroneCAN/DSDL/com ${SRCROOT}/modules/DroneCAN/DSDL/dronecan",
        group='dynamic_sources',
)

2.配置board类型 (以雷迅CUAVv5为例)

./waf configure --board CUAVv5

3.根据机架类型编译工程

./waf copter

4.在以下路径可以找到生成.hpp文件
在这里插入图片描述
5.复制对应的HimarServos.hpp与HimarkStatus.hpp文件到以下路径

/Ardupilot/libraries/AP_UAVCAN/dsdl/

6.如果需要自定义签名,则需要在HimarkServos.hpp\HimarkStatus.hpp文件中修改
在这里插入图片描述

UAVCAN新设备调用

1.包含新设备头文件

#include <AP_UAVCAN/dsdl/HimarkServos.hpp>
#include <AP_UAVCAN/dsdl/HimarkStatus.hpp>

2.新添加发布信息接口

// himark servo
static uavcan::Publisher<uavcan::equipment::actuator::HimarkServos>* srv_out_array[HAL_MAX_CAN_PROTOCOL_DRIVERS];

3.新添加订阅服务接口

// handler Himark servo status
UC_REGISTRY_BINDER(HimarkStatusCb, uavcan::equipment::actuator::HimarkStatus);
static uavcan::Subscriber<uavcan::equipment::actuator::HimarkStatus, HimarkStatusCb> *himark_srv_status_listener[HAL_MAX_CAN_PROTOCOL_DRIVERS];

4.在void AP_UAVCAN::init()函数中添加设备初始化

//servo
srv_out_array[driver_index] = new uavcan::Publisher<uavcan::equipment::actuator::HimarkServos>(*_node);
srv_out_array[driver_index]->setTxTimeout(uavcan::MonotonicDuration::fromMSec(2));
srv_out_array[driver_index]->setPriority(uavcan::TransferPriority::OneLowerThanHighest);
himark_srv_status_listener[driver_index] = new uavcan::Subscriber<uavcan::equipment::actuator::HimarkStatus, HimarkStatusCb>(*_node);
if (himark_srv_status_listener[driver_index]) {
    himark_srv_status_listener[driver_index]->start(HimarkStatusCb(this, &handle_himark_srv_status));
}

5.发布服务实现
在这里插入图片描述
6.订阅服务实现
在这里插入图片描述
7.在AP_UAVCAN.H添加HimarkStatusCb类
在这里插入图片描述
8.在uavcan类里添加函数接口

public:
/ himark srv output /
void himark_srv_send_actuator(void);
static void handle_himark_srv_status(AP_UAVCAN* ap_uavcan, uint8_t node_id, const HimarkStatusCb &cb);

结束

UAVCAN新设备已经添加完成,可通信测试。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值