我正在尝试创建一个Webots模拟,当Kinect摄像头检测到一个人时,我想让我的机器人说话。你知道吗
我有一个连接到USB端口的Kinect V2,它可以通过使用PyKinect2和pygame运行Python代码来检测一个人。你知道吗
下一步,我将这些代码放到Webots环境中,并添加了一个robot,当Kinect检测到它们时,它可以与用户对话。然而,当Kinect开始运行并弹出窗口时,Webots时钟停止滴答作响,机器人什么也不做。在我关闭Kinect窗口后,机器人会说出消息,但该代码应该在Kinect代码中执行,如下所示。你知道吗
我相信这可能是一个同步问题,因为Kinect和Webots有自己的时钟,但我不确定。即使是这样,我也不知道该怎么办。欢迎任何建议。你知道吗
这里是我的代码的相关部分,如果需要我可以提供完整的代码。Kinect body detection是this example的略微修改版本:
class BodyGameRuntime(object):
# ----- other functions here -----
def run(self):
# -------- Main Program Loop -----------
while not self._done:
# --- frame and window resize logic here
# --- Draw skeletons to _frame_surface
if self._bodies is not None:
# ---------- Body Found ----------
speaker.speak("User detected!", volume=1.0) # Speak to the user
for i in range(0, self._kinect.max_body_count):
body = self._bodies.bodies[i]
if not body.is_tracked:
continue
joints = body.joints
# convert joint coordinates to color space
joint_points = self._kinect.body_joints_to_color_space(joints)
self.draw_body(joints, joint_points, SKELETON_COLORS[i])
# --- copy back buffer logic here
# --- Update the screen with what we've drawn.
pygame.display.update()
pygame.display.flip()
# --- Limit to 30 frames per second
self._clock.tick(30)
# Close our Kinect sensor, close the window and quit.
self._kinect.close()
pygame.quit()
robot = Robot()
speaker = Speaker("Speaker")
#timestep = int(robot.getBasicTimeStep())
__main__ = "Kinect"
game = BodyGameRuntime()
game.run()
Webots需要您称之为机器人步进(timeStep)定期运行,以便在模拟时间上继续,否则它将停止模拟并等待下一次调用机器人步进(时间步长)。我只想给添加一个电话机器人步进(timeStep)在主循环中,就在self之前_时钟滴答声(30)并取消主程序中timeStep初始化的注释。你知道吗
请注意,如果您的Webots模拟是实时运行的,请调用机器人步进(十) 将持续大约X毫秒。所以你应该设置WorldInfo.basicTimeStep到30毫秒,然后取消对self的调用_时钟滴答声(30)。你知道吗
相关问题 更多 >
编程相关推荐