pixhawk第一个自定义应用

自定义应用

  • 工具 qgroundcontrol ubuntu

例程 px4_simple_app

px4官方代码已经给出了一个例程
进入Firmware/cmake/configs
你可以看到px4的cmake配置,我们打开nuttx_px4fmu-v2_default.cmake文件。
有许多被’#’注释的内容,我们拉到最下方,可以看到

examples/px4_simple_app

取消注释,之后编译下载到px4中,使用qgc连接飞控,在控制台console ,键入px4_simple_app,就可以看到当前的3轴加速度数据。

自定义数据

自定义数据显示的话,就需要改动它的数据来源,最后的显示部分不需要改动。
px4使用uorb进行数据的交互

  1. 公告主题

    orb_advertise(const struct orb_metadata *meta, const void *data);

    meta:uORB元对象,可以认为是主题id,一般是通过ORB_ID(主题名)来赋值;
    data:指向一个已被初始化,发布者要发布的数据存储变量的指针;

  2. 发布数据

    orb_publish(const struct orb_metadata *meta, int handle, const void *data);

    meta:uORB元对象,可以认为是主题id,一般是通过ORB_ID(主题名)来赋值;
    handle:orb_advertise函数返回的句柄;
    data:指向待发布数据的指针;

  3. 读取数据
    *订阅

    int orb_subscribe(const struct orb_metadata *meta);

    meta:uORB元对象,可以认为是主题id,一般是通过ORB_ID(主题名)来赋值;
    *读取

    int orb_copy(const struct orb_metadata *meta, int handle, void *buffer);

    meta:uORB元对象,可以认为是主题id,一般是通过ORB_ID(主题名)来赋值
    handle:订阅主题返回的句柄;
    buffer:从主题中获取的数据;

  4. more
    检查更新

    int orb_check(int handle, bool *updated);

    发布时间戳

    int orb_stat(int handle, uint64_t *time);

    监控文件描述符(多个)

    int poll(struct pollfd fds[], nfds_t nfds, int timeout)

    输入:

    fds:struct pollfd结构类型的数组,进程可以同时等待很多个主题数据,当有数据更新时,判断一下是谁
    nfds:用于标记数组fds中的结构体元素的总数量;

    返回值:

    >0:阻塞时间内拿到了数据;
    ==0:抱歉时间都用完了,也没能拿到数据;
    -1:poll函数调用失败;

  5. 例子
    publish.cpp
    使用px4simple_app.c
    添加#include < uORB/topics/optical_flow.h>


int simple_thread_main(int argc, char *argv[])
{
    struct optical_flow_s flow_data;
    orb_advert_t flow_pub;
    /* 公告主题 */
    flow_pub = orb_advertise(ORB_ID(optical_flow), &flow_data);
    while(!thread_should_exit){
        usleep(20);

        flow_data.pixel_flow_x_integral = 1000;
        flow_data.pixel_flow_y_integral = 1000;
        flow_data.ground_distance_m = 1000;
        flow_data.quality = 255;
        ...
        orb_publish(ORB_ID(optical_flow), flow_pub, &flow_data);
    }
    return 0;
}

编译代码之后你就可以在qgc上看到optical flow的有数据且数据是你设置的值(前提是你不插光流)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值