Changing subscriber topic

asked 2016-06-21 09:08:40 -0600

Thalaiva gravatar image

I have three different objects that all have their own topic of /path_finished, so at any time there is /obj1/path_finished, /obj2/path_finished, and /obj3/path_finished. I want to only subscribe to the topic when my code is assessing a certain object. I have these three objects in a list, so as I iterate through each object, I want the subscriber to subscribe to the topic name relating to that object. Is there an elegant way to do this with only one subscriber or do I just have to have three different subscribers?

Here is code below to illustrate my question:

self.path_name = ""
self.pub_wpt_queue_done = rospy.Subscriber(self.path_name, QuadWaypointQueueComplete, self.isFinished, queue_size=100)

def isFinished(self, wpt_done_msg):
    self.isFinished = veh_list_msg.is_queue_complete

def managerLoop(self,event):
    for veh_name in self.ducky_dict.keys():
        cur_ducky = self.ducky_dict[veh_name]
        self.path_name = "/"+cur_ducky+"/path_finished"
        if (self.isFinished): 
            rospy.loginfo("[%s][managerLoop] Successfully finished wpt, going to next wpt if available." %(cur_ducky.veh_name))
            pubWptQueueComplete(cur_ducky.veh_name)

Any help is much appreciated, thanks!

edit retag flag offensive close merge delete