Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9140234
  • 博文数量: 1725
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19840
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1725)

文章存档

2024年(1)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2020-03-10 16:05:28

Q: 有时候, 通过launch文件会 include 几个 launch文件, 而其中的几个node之间需要有先后关系, 那么怎么办呢. 
A: 例如: node A 发布topic, service, 然后启用 node B. 那么可以采用 rostopic list 检测 node A是否已经完成了 topic, 然后启动 node B. 用程序实现.

点击(此处)折叠或打开

  1. bool waitfor_topic_ok(const char *topic_wait, uint32_t timeout_sec)
  2. {
  3.     uint32_t iCnt = 0;

  4.     iCnt = 0;
  5.     std::string wait_topic(topic_wait);

  6.     ros::master::V_TopicInfo master_topics;
  7.     while (1) {
  8.         ros::master::getTopics(master_topics);
  9.         ros::master::V_TopicInfo::iterator master_it = master_topics.begin();
  10.         ros::master::V_TopicInfo::iterator master_end = master_topics.end();
  11.         for ( ; master_it != master_end; ++master_it )
  12.         {
  13.             const ros::master::TopicInfo& info = *master_it;
  14.             if ( wait_topic == info.name )
  15.             {
  16.                 return true;
  17.                 break;
  18.             }
  19.         }
  20.         if (timeout_sec == 0) { //用户检测是否存在
  21.             break; //
  22.         }
  23.         else { //没有发现, 则延迟等待
  24.             sleep(1);
  25.             if ((timeout_sec > 0) && (timeout_sec <= iCnt++)) break;
  26.         }
  27.     }

  28.     return false;
  29. }
同理. 其他如 service action 等等.

2. 查看自己的topic是否被订阅.

点击(此处)折叠或打开

  1. //查看 pub_mytopic 是否被订阅
  2. if (pub_mytopic.getNumSubscribers() == 0){
  3.   //还没有订阅的人
  4. }
阅读(1593) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~