Webots 机器人在尝试与外部 Kinect 一起使用时不说话

Webots robot doesn't speak while trying to use it with an external Kinect

我正在尝试创建 Webots 模拟,我希望我的机器人在 Kinect 摄像头检测到人时说话。

我有一个连接到 USB 端口的 Kinect V2,它可以通过 运行 我的 Python 代码使用 PyKinect2 和 pygame 自行检测到一个人。

作为下一步,我将该代码放入 Webots 环境中,并添加了一个机器人,以便在 Kinect 检测到用户时与用户对话。但是,当 Kinect 启动 运行 并弹出 window 时,Webots 时钟停止滴答,机器人什么也不做。在我关闭 Kinect window 后,机器人会说出消息,但该代码应该在 Kinect 代码中执行,如下所示。

我认为这可能是同步问题,因为 Kinect 和 Webots 有自己的时钟,但我不确定。即便如此,我也不知道如何进行。欢迎任何建议。

这是我的代码的相关部分,如果需要我可以提供完整的代码。 Kinect body 检测是 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 需要您定期调用 robot.step(timeStep) 函数,以便在模拟时间上取得进展,否则它会简单地停止模拟并等到下一次调用 robot.step(timeStep)。我只是在主循环中添加对 robot.step(timeStep) 的调用,就在 self._clock.tick(30) 之前并在主程序中取消注释 timeStep 的初始化。

请注意,如果您的 Webots 模拟是实时 运行,调用 robot.step(X) 将持续大约 X 毫秒。所以你应该在你的世界文件中将 WorldInfo.basicTimeStep 设置为 30 毫秒并摆脱对 self._clock.tick(30)[= 的调用23=].