Subscriber providing condition for another subscriber to subscribe a topic
I'm trying to generate a node which subscribes 2 topics and uses one topic as a condition to subscribe another topic:
class odom2obj(object):
def __init__(self):
self._pose_sub = rospy.Subscriber('/chatter', Pose, self._check_obj)
def _check_obj(self):
if self._pose_sub.num_object > 0:
# subscribe another topic #
# self._odom_sub = rospy.Subscriber('/chatter2', Pose, self._callback) #
def _callback(self):
if __name__ == '__main__':
rospy.init_node('hsr_odom2obj')
odom2obj()
rospy.spin()
I was initially thinking of setting 2nd subscriber into 1st subscriber's callback function. However, I now wonder whether this is an efficient approach when the callback function of the 1st subscriber is called often. I appreciate if someone can tell any better way.