Robotics StackExchange | Archived questions

Stopping and re-initializing a node or stopping spin without shutting down node

Hi,

I'm trying to write a ROS program where I initialize a server node, but once it receives one service request, it shuts down the node, and does other things, and at some later time, re-initializes the node and waits for another service request.

In my server's callback function I'm using rospy.signal_shutdown('Intentional shutdown'), but when I try and initialize the node again at some later point to wait for another service call and use rospy.spin() again, it doesn't work and seems to ignore rospy.spin(), just continuing in the program instead of waiting for another service call as I'm trying to get it to.

Anyone know why this would be happening or a different way of doing what I'm attempting here? I've tried shutting down and both the node as well as the rospy.Service object and restarting them when I'm ready to wait for the service call again from my client. I've also tried only stopping the service but then the rospy.spin() doesn't exit.

I need either a way to re-initialize the node after it's been shutdown in a single script or a way to exit the rospy.spin() loop without shutting down the node.

Any help or comments are very much appreciated.

Asked by lwoiceshyn on 2017-01-20 18:36:54 UTC

Comments

Why do you want to shutdown your node? This somehow looks like there is a better solution. What do you really want to achieve?

Asked by NEngelhard on 2017-01-21 02:17:05 UTC

I agree with @NEngelhard: this might be an xy-problem. Could you perhaps give us some more context?

Also: is this (somehow) a duplicate of #q252545?

Asked by gvdhoorn on 2017-01-21 04:20:46 UTC

Duplicate: http://answers.ros.org/question/249986/any-way-to-re-rospyinit_node/

Asked by tfoote on 2017-01-22 12:53:47 UTC

I'm just trying to write a service node where I go into a waiting state and wait for a client node to request that service, and once it's been requested, break out of that state and continue doing other things.

Asked by lwoiceshyn on 2017-01-22 18:36:56 UTC

As @gvdhoorn mentioned this is an xy-problem. If that's all you want you don't need to shutdown or start the node. You can either manage spinning in your own main thread using spin_once, or run your main processing in a thread. Please ask a new question after trying it out.

Asked by tfoote on 2017-01-22 19:20:44 UTC

Thanks for your help @tfoote. There's no spin once equivalent for rospy, right?

Asked by lwoiceshyn on 2017-01-22 20:09:01 UTC

Answers

Reinitialization is not supported in the same process: https://github.com/ros/ros_comm/issues/185

I'd recommend using a subprocess.

Asked by tfoote on 2017-01-22 02:49:56 UTC

Comments