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

Node is not shutting down on ros::ok()

asked 2014-07-21 04:15:21 -0500

RagingBit gravatar image

updated 2014-07-21 06:00:46 -0500

Hi all,

Mine is just a noob question about the expected behaviour of ros::ok() function. I've written this very simple piece of code :

int main(int argc, char **argv)
{
    ros::init(argc, argv, "bot");
    ros::NodeHandle nh("~");

    ros::Publisher odo_pub = nh.advertise<sensor_msgs::JointState>("odometry", 1000);
    ros::Subscriber cmd_sub = nh.subscribe(sub.c_str(), 1000, chatterCallback);

    // Define the odometry msg
    sensor_msgs::JointState msg;
    msg.header.frame_id="bot";
    msg.position.resize(4);
    msg.velocity.resize(4);
    msg.effort.resize(4);

    while( ros::ok())
    {
        ROS_INFO("In loop %d",ros::ok());

        msg.header.stamp=ros::Time::now();
        odo_pub.publish(msg);
        ros::spinOnce();
    }
    ROS_INFO("Exit");

    return 0;
}

Should the node exit when I Ctrl-c the ros framework (by killing the terminal on which roscore has been started)? Thanks!

P.S. I'm running ROS hydro on Ubuntu 12.04.2 LTS

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-07-21 06:16:42 -0500

bvbdort gravatar image

updated 2014-07-21 07:26:09 -0500

do Ctrl-c on terminal where your node is running (not roscore terminal).

you need to call ros::shutdown() to shutdown your node.

you use ros::master::check() in code to check.

thanks to http://answers.ros.org/question/36733...

edit flag offensive delete link more

Comments

That works. Anyway, I was wondering if there is a way to check from my node if roscore has been turned off, in order to terminate the node as well. Checking on ros::ok() seems not to be working like that...

RagingBit gravatar image RagingBit  ( 2014-07-21 06:45:39 -0500 )edit
1

Yes, that was what I was looking for. Thanks!

RagingBit gravatar image RagingBit  ( 2014-07-21 06:55:14 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-21 04:15:21 -0500

Seen: 1,445 times

Last updated: Jul 21 '14