0
私は、複数のエージェントがそれぞれの位置とそれぞれのIDを発行するトピックに登録されているROSノードを持っています。私はカメのようなエージェントを描き、それに応じてポジションを更新できるようにしたい。ROSコールバック関数からの入力に基づいてカメの配列を更新する方法
私は、次のしている:
class Visualizer():
def __init__(self):
self.turtles = list()
#Of the form: [[id, pos], ...]
#[[1, [2, 3]],[2, [6, 7]],[3, [1, 1]],[4, [9, 8]], ...]
self.logistics = []
self.colors = []
rospy.init_node('visualizer', anonymous=True)
rospy.Subscriber('/environment/agent_position', Protocol_Msg, self.draw_agents)
turtle.Screen()
def is_it_new(self, data):
----> check if broadcast received by new agent
if new:
self.turtles.append(turtle.Turtle())
self.colors.append([random.random(), random.random(), random.random()])
print self.colors
self.logistics.append([turtle_id, pos])
else:
#only update position
for x in self.logistics:
if x[0] == turtle_id:
x[1] = pos
print self.logistics
def draw_agents(self, data):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.content)
self.is_it_new(data)
for x in self.logistics:
if x[0] == int(data.sender):
turtles[self.logistics.index(x)].setx(x[1][0])
turtles[self.logistics.index(x)].sety(x[1][1])
if __name__=='__main__':
try:
visualize = Visualizer()
rospy.spin()
except rospy.ROSInterruptException:
pass
しかし、これは私を除くと
RuntimeError: main thread is not in main loop
を生産するが、私は更新が中に発生するようにコードを書き換えする方法がわからないですしないようメインスレッド。 (私は前にそのようなGUIで作業していない)。
コードにもう少しコンテキストを追加してください。[最小限の完全で検証可能な例にしてください](http://stackoverflow.com/help/mcve)。今のところ、例えば、変数「カメ」がどこから来るのかはわかりません。また、エラーが発生した場所を正確に追加してください。 – luator