Ask Your Question
0

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()
        try:
            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 :
            cv2.circle(cv_image, (50,50), 10, 255)
                        x=5
                        puba.publish(x)                
        cv2.imshow("Image window", cv_image)
        cv2.waitKey(3)
def pilot():
       puba = rospy.Publisher("box_positiona", Float64)   
       bridge_opencv()
       rospy.spin()
if __name__ == '__main__':
        pilot()

Node 2 :(subscriber)

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

def ground():
    global cmd

    rospy.init_node("ground")   

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

Thanks a lot ! Looking forward for your answers

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

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
0

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: http://wiki.ros.org/rospy/Overview/In...
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

Stats

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

Seen: 1,622 times

Last updated: Jun 24 '14