0
$\begingroup$

Rosanswers logo

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.


Originally posted by kidpaul on ROS Answers with karma: 38 on 2021-10-25

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I had to use data from rostopics which get generated by built-in ros driver. So, what I did was declaring another node which subscribes both topics using message filter and decides to process the data based on the condition.


Originally posted by kidpaul with karma: 38 on 2021-11-21

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.