PX4源码学习
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; }