PX4_STU -DAY1 -uORB
2021/7/24 6:10:54
本文主要是介绍PX4_STU -DAY1 -uORB,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
PX4源码学习
UORB
订阅消息
int px4_simple_app_main(int argc, char *argv[]) { PX4_INFO("Hello Sky!"); /* subscribe to vehicle_acceleration topic */ int sensor_sub_fd = orb_subscribe(ORB_ID(vehicle_acceleration)); int sensor_sub_fd2=orb_subscribe(ORB_ID(sensor_combined)); /* limit the update rate to 5 Hz */ //dingyue orb_set_interval(sensor_sub_fd, 200); orb_set_interval(sensor_sub_fd2, 200); /* advertise attitude topic */ struct vehicle_attitude_s att; memset(&att, 0, sizeof(att)); // struct airspeed_s asp; orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude), &att); // orb_advert_t asp_pub = orb_advertise(ORB_ID(vehicle_attitude), &att); /* one could wait for multiple topics with this technique, just using one here */ px4_pollfd_struct_t fds[] = { { .fd = sensor_sub_fd, .events = POLLIN }, { .fd = sensor_sub_fd2, .events = POLLIN }, /* there could be more file descriptors here, in the form like: * { .fd = other_sub_fd, .events = POLLIN }, */ };
利用uORB 进行通讯时,需要在msg中定义消息的类型,并在CMakeLists中添加该消息。
在borad/px4/下的CMAKELISTS 里面可以添加编译每个版本固件时需要编译的文件 及 注册模块
int px4_uorb_subs_thread_main(int argc,char *argv[]){ warnx("px4_uorb_subs string\n"); int test_sub_fd=orb_subscribe(ORB_ID(test_uorb)); //订阅消息 struct test_sub_s test_uorb_sub; memset(test_uorb_sub,0,sizeof(test_uorb_sub)); int test1=0,test2=0; thread_runing=true; while(!thread_should_exit){ warnx("HELLO px4_uorb_subs\n"); bool updated; orb_check((test_uorb_sub,&updated));//确认消息是否更新 if(updated){ orb_copy(ORB_ID(test_uorb),test_sub_fd,&test_uorb_sub); test1=test_uorb_sub.test1; test2=test_uorb_sub.test2; } warnx("test1=%d,\t test2=%d",test1,test2) } warnx("[px4_uorb_subs] exiting. \n"); thread_running=false; return 0; }
这篇关于PX4_STU -DAY1 -uORB的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22项目:远程温湿度检测系统
- 2024-12-21《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》简介
- 2024-12-21后台管理系统开发教程:新手入门全指南
- 2024-12-21后台开发教程:新手入门及实战指南
- 2024-12-21后台综合解决方案教程:新手入门指南
- 2024-12-21接口模块封装教程:新手必备指南
- 2024-12-21请求动作封装教程:新手必看指南
- 2024-12-21RBAC的权限教程:从入门到实践
- 2024-12-21登录鉴权实战:新手入门教程
- 2024-12-21动态权限实战入门指南