Ask Your Question

Could a node can be stoped by another node ?

asked 2014-06-24 04:52:25 -0500

jashanvir gravatar image

Hello guys ! I want to stop a node, once its published message is subscribe by another node. For example

Node 1(publisher)

def bridge_opencv():
        image_pub = rospy.Publisher("quadrotor/videocamera1/camera_info",Image)

            cv2.namedWindow("Image window", 1)

        image_sub = rospy.Subscriber("quadrotor/videocamera1/image",Image, callback)

def callback(data):

        bridge = CvBridge()
            cv_image = bridge.imgmsg_to_cv2(data, "bgr8")
        except CvBridgeError, e:
            print e
        (rows,cols,channels) = cv_image.shape
        if cols > 60 and rows > 60 :
  , (50,50), 10, 255)
        cv2.imshow("Image window", cv_image)
def pilot():
       puba = rospy.Publisher("box_positiona", Float64)   
if __name__ == '__main__':

Node 2 :(subscriber)

def where1(msg):
    global x1
    x1 =
    print x1

def ground():
    global cmd


    rospy.Subscriber("/box_positiona", Float64, where1)
        >>once i subscribe to that topic,stop node 1 immediatley
if __name__ == '__main__':

Thanks a lot ! Looking forward for your answers

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-06-24 06:11:07 -0500

dornhege gravatar image

Are you sure you want to stop once subscribed? You do NOT have a message then.

This whole thing also goes against usual ROS usage patterns. For one time things a service call might be better suited. It might be a good idea to state what you want to actually achieve with this.

If you want to stop a node there are some possibilities.

  • Nodes are binaries, you can just kill them with a normal system command (you'll need to know the pid/name or figure it out)
  • rosnode kill <node> kills the node with name <node>.
  • If you don't know the node's name for the setup, but have some kind of ROS configurable connection you can send a shutdown service/message that would trigger that node to end itself manually.
edit flag offensive delete link more

answered 2014-06-24 07:33:12 -0500

ct2034 gravatar image

updated 2014-06-24 07:52:50 -0500

I think the most secure way would be to for the node to kill itself. You can find some info here:
But as @dornhege said, it seems to be useless, as you won't get any messages from it then.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-06-24 04:52:25 -0500

Seen: 1,622 times

Last updated: Jun 24 '14