Ejemplo n.º 1
0
    def run(self):
        while not self.should_stop():
            if self.should_pause(): self.wait_to_resume()

            while not (self.posture_is(self.defaut_posture)):
                time.sleep(0.1)
            for m in self.robot.motors:
                m.led = "green"
                m.compliant = True

            my_record = MoveRecorder(self.robot, 50, self.robot.motors)
            my_record.start()

            sleep = int(self.record_time + (self.record_time / 5.))
            for i in range(sleep):
                if not self.should_stop():
                    if self.should_pause(): self.wait_to_resume()
                    for m in self.robot.motors:
                        m.led = "green"
                    time.sleep(0.5)
                    for m in self.robot.motors:
                        m.led = "off"
                    time.sleep(0.5 - ((0.5 / sleep) * i))

            my_record.stop()
            #my_record.wait_to_stop()

            if not self.should_stop():
                if self.should_pause(): self.wait_to_resume()

                self.robot.tinsel.colors = ['red']
                self.robot.tinsel.freq = 1
                self.robot.tinsel.start()

                self.robot._primitive_manager.remove(self)
                # patch pour passer des fake moteurs de la primitive ProgByDemo aux moteurs reel de l ergo

                my_play = MovePlayer(self.robot, my_record.move)
                my_play.start()

                for t in range(self.record_time * 2):
                    if not self.should_stop():
                        if self.should_pause(): self.wait_to_resume()
                        time.sleep(0.5)

                if my_play.is_alive(): my_play.stop()

                self.robot.tinsel.stop()

                self.robot._primitive_manager.add(
                    self
                )  # on redonne le control des moteurs a la primitive ProgByDemo

                duration = int(max(self.distance_with(
                    self.defaut_posture))) / 100.
                for m in self.robot.motors:
                    m.compliant = False
                    m.goto_position(self.defaut_posture[m.id - 1], duration)
                time.sleep(duration)