您的位置:首页 > 其它

pixhawk第一个自定义应用

2018-03-05 20:31 197 查看

自定义应用

工具 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进行数据的交互

公告主题

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

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

data:指向一个已被初始化,发布者要发布的数据存储变量的指针;

发布数据

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

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

handle:orb_advertise函数返回的句柄;

data:指向待发布数据的指针;

读取数据

*订阅

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:从主题中获取的数据;

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函数调用失败;

例子

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的有数据且数据是你设置的值(前提是你不插光流)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  px4 pixhawk-编译