PX4源码开发人员文档(三)——进程间通讯的开发者指南.doc

PX4源码开发人员文档(三)——进程间通讯的开发者指南.doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
PX4源码开发人员文档(三)——进程间通讯的开发者指南

进程/应用之间的通信(例如将传感器应用的传感器数据发送到姿态滤波应用)是PX4软件架构的关键部分。进程(通常又被叫做节点(node))通过命名为总线(buses)进行消息交换的过程被称作订阅主题(topics)。 在PX4中,一个订阅主题仅包含一个消息类型,比如vehicle_attitude订阅主题传输一个包含姿态结构(滚转、俯仰和偏航估计)的消息。?? 节点可以在总线/订阅主题上发布(publish)一个消息(发送数据)或者订阅(subscribe)一个总线/订阅主题(接收数据)?。应用并不知道在与谁通信,1个订阅主题可以有多个发布器和订阅器。 这种设计模式阻止了锁定的问题(locking issues),在机器人领域非常常见。为了使这更为高效,通常在总线上只有一个消息,并且不会有队列。 这种发布/订阅机制由微对象请求处理器microobject request broker (uORB)实现。 快速开始 这是一个简单但是完整的发布器(publisher)?/订阅器(subscriber)组合,发布器发布一个叫做random_integer?的订阅主题,并使用随机的整数更新订阅主题。订阅器检查并打印这些更新。 topic.h /*?declare?the?topic?*/?? ORB_DECLARE(random_integer);?? /*?define?the?data?structure?that?will?be?published?where?subscribers?cansee?it?*/?? struct?random_integer_data{?? ??????????int?r;?? };?? publisher.c #include?topic.h?? ?/*?create?topic?metadata?*/?? ORB_DEFINE(random_integer);??? /*?file?handle?that?will?be?used?for?publishing?*/?? staticint?topic_handle;??? int?init()?? {?? ??????????/*?generate?the?initial?data?for?first?publication*/?? ??????????struct?random_integer_data?rd={?.r=?random(),};?? ??????????/*?advertise?the?topic?and?make?the?initialpublication?*/?? ??????????topic_handle?=?orb_advertise(ORB_ID(random_integer),rd);?? }?? int?update_topic()?? {?? ??????????/*?generate?a?new?random?number?forpublication?*/?? ??????????struct?random_integer_data?rd={?.r=?random(),};?? ??????????/*?publish?the?new?data?structure?*/?? ??????????orb_publish(ORB_ID(random_integer),?topic_handle,rd);?? }?? subscriber.c #include?topic.h?? ?/*?file?handle?that?will?be?used?forsubscribing?*/?? staticint?topic_handle;?? int?init()?? {?? ??????????/*?subscribe?to?the?topic?*/?? ??????????topic_handle?=?orb_subscribe(ORB_ID(random_integer));?? }?? ?voidcheck_topic()?? {?? ??????????bool?updated;?? ??????????struct?random_integer_data?rd;??? ??????????/*?check?to?see?whether?the?topic?has?updatedsince?the?last?time?we?read?it?*/?? ??????????orb_check(topic_handle,updated);?? ??????????if(updated){?? ????????????????????/*?make?a?local?copy?of?the?updated?d

您可能关注的文档

文档评论(0)

159****0071 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档