ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Check master ros node is started C++

asked 2016-06-10 08:51:03 -0600

arennuit gravatar image

Hello,

Is there a way in C++ to check whether the master ros node is setup? I initially believed ros::init() would return false, but the return type is false...

I have quickly looked on the internet and could find nothing...

Thanks ;)

edit retag flag offensive close merge delete

Comments

Anyone for this question?

arennuit gravatar image arennuit  ( 2016-06-13 04:51:32 -0600 )edit

Please don't post comments or updates as answers. It can be confusing when looking at the questions list (it appears as if the question has already at least one answer). I've moved your answer to the comment section, but please keep it in mind for next time.

gvdhoorn gravatar image gvdhoorn  ( 2016-06-13 07:10:49 -0600 )edit

got it, thanks.

arennuit gravatar image arennuit  ( 2016-06-13 11:54:59 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-06-13 09:43:33 -0600

You can use ros::master::check().

#include "ros/ros.h"
#include <iostream>

int main(int argc, char *argv[])
{
    ros::init(argc, argv, "master_test");
    ros::Time::init();
    while (!ros::master::check())
    {
        std::cout << "waiting..." << std::endl;
        ros::Duration(0.5).sleep();
    }
    std::cout << "master started!" << std::endl;
    return 0;
}
edit flag offensive delete link more

Comments

That works fine, thanks!

arennuit gravatar image arennuit  ( 2016-06-14 02:25:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-10 08:51:03 -0600

Seen: 2,035 times

Last updated: Jun 13 '16