Java教程

PX4_STU -DAY1 -uORB

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!