Publishing a list, and echo its topic duplicate item problem
Hello, I publish to a list by looping through recognized people on camera. Even though 2 people display action 0 and action 1 respectively, topic either says they both display 0 or 1. Do you see what is wrong with it?
My code and topic echo is below:
def callback(self, msg):
human_list_length = len(msg.human_list)
self.publisher_msg.num_humans = human_list_length
self.publisher_msg.gesture_list = [GestureDetectorHuman()] * human_list_length
rospy.loginfo("Visible humans:" + str(human_list_length))
for human in msg.human_list:
ind = msg.human_list.index(human)
rospy.loginfo("Gesture from Human: " + str(ind))
self.publisher_msg.gesture_list[ind].human_index = ind
# Check gesture published by current human and publish respective message
if self.hand_raise(human):
self.publisher_msg.gesture_list[ind].gesture = str(0)
elif self.wait_a_minute(human):
self.publisher_msg.gesture_list[ind].gesture = str(1)
rostopic echo output:
num_humans: 2
gesture_list:
-
human_index: 1
gesture: "0"
-
human_index: 1
gesture: "0"
---
num_humans: 2
gesture_list:
-
human_index: 1
gesture: "1"
-
human_index: 1
gesture: "1"
---
num_humans: 2
gesture_list:
-
human_index: 1
gesture: "0"
-
human_index: 1
gesture: "0"
---
num_humans: 2
gesture_list:
-
human_index: 1
gesture: "0"
-
human_index: 1
gesture: "0"
---
I don't understand how the two snippets you posted are related. The second is the Output of
rostopic echo
, I guess. But what about the first? Is this supposed to be the callback reacting to the data in the topic? I don't see ahuman_list
field in the Output below. Or should this produce the ...posted message? I'm guessing the second. But there is the question, what do the
hand_raise
andwait_a_minute
functions do. My guess, your problem is in there.Maybe describe in more Detail what you expect to happen where, and post the code of the publishers and relevant functions...
I can post the full code but its too long. The problem is message published is instead of adding new element inside for loop, it makes all list elements the last added element. wait_a_minute and hand_raise are the functions called they work just fine as the return is true or false.
Whoops, missed that the
human_index
is actually the same to. This is the crucial part!