Пример #1
0
    def __init__(self, knowledge_base):
        # this knowledge base reference is used for updating the robot state
        self.knowledge_base = knowledge_base

        # create the viewer
        self.viewer = Viewer()

        BaseJob.__init__(self, None, None)
Пример #2
0
    def _handler(self):
        logger.debug('child {} start'.format(self.child.pid))

        # hold a reference to the world so that it is not garbage collected
        self.world = WorldModel()
        # create the robot model for the controller
        self.robot = self.world.loadRobot(os.path.join('klampt_models', baxter.klampt_model_name))
        logger.debug('robot model loaded from {}'.format(baxter.klampt_model_name))
        self.controller = LowLevelController(self.robot, baxter.klampt_model_name)
        logger.debug('controller low-level controller initialized')

        # send the initial controller state
        self.child_pipe.send((None, RobotState(self.controller)))

        while True:
            # get the call information
            try:
                # update the viewer while waiting for a command
                while not self.child_pipe.poll():
                    self._update_viewer()
                    sleep(interval)

                # receive the command
                (self.knowledge_base, self.method, self.args, self.kwargs) = self.child_pipe.recv()
            except EOFError:
                logger.info('child {} shutdown requested'.format(self.child.pid))
                # signal to shut down
                break

            # distinguish between pure knowledge base updates and method calls
            if not self.method:
                self._update_viewer()
                self._send_result(None)
                continue

            # route remote calls
            self.init_args = (self.controller, self.knowledge_base)
            # hook the sleep method to update the viewer during execution
            self.kwargs['sleep'] = lambda n: self._sleep(n)
            BaseJob._handler(self)

        # clean up
        # need to call the superclass since this class overrides with empty method
        BaseJob._close()
        # TODO: shutdown the controller
        #controller.motion.shutdown()

        self.viewer.close()
Пример #3
0
 def _send_result(self, result):
     # attach the robot state to the job result
     BaseJob._send_result(self, (result, RobotState(self.controller)))