PX4中自定义MAVLink消息(记录)

简单记录一下这个过程。

一、自定义uORB消息

这一步比较简单,首先在msg/中新建ca_trajectory.msg文件

uint64 timestamp		# time since system start (microseconds)

uint64 time_start_usec
uint64 time_stop_usec
uint32 coefficients
uint16 seq_id

在CMakeList.txt中加入
在这里插入图片描述
经过编译,生成了/uORB/topics/ca_trajectory.h,具体路径是/Firmware/build/px4_fmu-v2_default/uORB/topics/ca_trajectory.h

具体路径取决于你的编译命令

二、自定义MAVLink消息

新建custom_messages.xml
内容:(不需要引用common.xml)

<?xml version="1.0"?>
<mavlink>
    <include>common.xml</include>
    <!-- NOTE: If the included file already contains a version tag, remove the version tag here, else uncomment to enable. -->
    <!--<version>3</version>-->
    <enums>
    </enums>
    <messages>
        <message id="315" name="CA_TRAJECTORY">
            <description>This message encodes all of the raw rudder sensor data from the USV.</description>
            <field type="uint64_t" name="timestamp">Timestamp in milliseconds since system boot</field>
            <field type="uint64_t" name="time_start_usec">start time, unit usec.</field>
            <field type="uint64_t" name="time_stop_usec">stop time, unit usec.</field>
            <field type="uint32_t" name="coefficients">as it says.</field>
            <field type="uint16_t" name="seq_id">can not cheat any more.</field>
        </message>
    </messages>
</mavlink>

使用python -m mavgenerate 打开,生成文件
在这里插入图片描述将custom_messages文件夹拷入下图所示
在这里插入图片描述
这样按照官网后面的操作就可以了

不过在官网介绍中

#include <uORB/topics/ca_trajectory.h>
#include <v2.0/custom_messages/mavlink.h>

会出现引用错误,我就直接这样搞了

#include <uORB/topics/ca_trajectory.h>
#include <v2.0/custom_messages/mavlink_msg_ca_trajectory.h>
#include <v2.0/custom_messages/mavlink.h>

这样再编译,可能还有小错误,但是很简单改个变量名就好了。

因为没有硬件,我在jMAVSim中看了一下

在这里插入图片描述
更详细的步骤参考:
FatasyJXF
https://blog.csdn.net/oqqENvY12/article/details/56849572 Pixhawk原生固件PX4之自定义MAVLink消息

以及想学技术的萌新 https://blog.csdn.net/weixin_43485969/article/details/104136205 这篇文章

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值