ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Subscriber providing condition for another subscriber to subscribe a topic

asked 2021-10-25 18:09:21 -0600

kidpaul gravatar image

updated 2021-10-26 09:18:07 -0600

lucasw gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-21 19:10:47 -0600

kidpaul gravatar image

updated 2021-12-09 19:02:54 -0600

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-10-25 18:09:21 -0600

Seen: 113 times

Last updated: Dec 09 '21