Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 99

Return a value from a callback function

$
0
0
Hello ! I want to have a value to be returned when I call a callback function while subscribing to a topic. I am using ROS-Hydro I have wrote a demo code that what I want. Please also suggest some new way to achieve this if callback function can't return anything ! 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) get value of y from callback function when it is returning y = z return z 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) cv2.imshow("Image window", cv_image) return y def my_function() x=cv_bridge() if x = 1: return "true" else: perform the task def pilot(): rospy.init_node("pilot") my_value = my_function() if my_value = true: stop everything... else: do the above process again rospy.spin() if __name__ == '__main__': pilot() Thanks a lot ! Looking forward for answers !

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>