Example #1
0
 def start_move_recorder(self, move_name, motors_name):
     motors = [getattr(self.robot, m) for m in motors_name]
     recorder = MoveRecorder(self.robot, 50, motors)
     # for m in motors:
     #     m.compilant = True
     self.robot.attach_primitive(recorder, move_name)
     recorder.start()
Example #2
0
class Record(LoopPrimitive):
    properties = ['record_name']
    path = '/tmp/{}.json'

    def __init__(self, robot):
        LoopPrimitive.__init__(self, robot, 1)
        self.record_name = "demo_example"

    def setup(self):
        for m in self.robot.motors:
            m.compliant = True

        self.recorder = MoveRecorder(self.robot, 50.0, self.robot.motors)
        self.recorder.start()

    def update(self):
        pass

    def teardown(self):
        self.recorder.stop()

        for m in self.robot.motors:
            m.compliant = False

        with open(self.path.format(self.record_name), 'w') as f:
            self.recorder.move.save(f)
Example #3
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)
Example #4
0
 def start_move_recorder(self, move_name, motors_name=None):
     if not hasattr(self.robot, '_{}_recorder'.format(move_name)):
         if motors_name is not None:
             motors = [getattr(self.robot, m) for m in motors_name]
         else:
             motors = getattr(self.robot, 'motors')
         recorder = MoveRecorder(self.robot, 50, motors)
         self.robot.attach_primitive(recorder, '_{}_recorder'.format(move_name))
         recorder.start()
     else:
         recorder = getattr(self.robot, '_{}_recorder'.format(move_name))
         recorder.start()
Example #5
0
    def learn(cls):
        move = MoveRecorder(cls.robot, 100, cls.robot.motors)
        cls.robot.compliant = True
        raw_input("Press enter to start recording a Move.")

        for x in xrange(3, 0, -1):
            print x
            time.sleep(1)

        move.start()
        raw_input("Press again to stop the recording.")
        move.stop()

        for m in cls.robot.motors:
            m.compliant = False
            m.goal_position = 0

        print "List of already taken primitives : "

        os.chdir('./moves')
        for file in glob.glob("*.move"):
            print(os.path.splitext(file)[0])
        os.chdir('../')

        move_name = raw_input("Enter the name of this sick move : ")
        move_name = move_name + ".move"

        with open("./moves/" + move_name, 'w') as f:
            try:
                move.move.save(f)
            except:
                print "Unable to save this move, sorry"
            else:
                print "Move successfully saved !"
        try:
            cls.robot.attach_primitive(PlayMove(cls.robot, movement=move_name),
                                       move_name)
        except Exception as e:
            raise
        else:
            print "Move successfully attached to the robot !"
        finally:
            pass
Example #6
0
    m.goal_position = 0.0

time.sleep(3)
#~ for m in poppy.motors:
#~ m.compliant = True

from pypot.primitive.move import Move, MoveRecorder, MovePlayer

record_frequency = 20.0  # This means that a new position will be recorded 50 times per second.
recorded_motors = poppy.r_leg
# You can also use alias for the recorded_motors
# e.g. recorder = MoveRecorder(poppy, record_frequency, poppy.tip)
# or even to record all motors position
# recorder = MoveRecorder(poppy, record_frequency, poppy.motors)

recorder = MoveRecorder(poppy, record_frequency, recorded_motors)

for m in recorded_motors:
    m.compliant = True

print "start recording"
recorder.start()

time.sleep(4)

print "stop recording"
recorder.stop()

recorded_move = recorder.move

with open('rlegstep.json', 'w') as f:
Example #7
0
 def attach_move_recorder(self, move_name, motors_name):
     motors = [getattr(self.robot, m) for m in motors_name]
     recorder = MoveRecorder(self.robot, 50, motors)
     self.robot.attach_primitive(recorder, '_{}_recorder'.format(move_name))
Example #8
0
  
time.sleep(3)    
#~ for m in poppy.motors:
    #~ m.compliant = True
    
from pypot.primitive.move import Move, MoveRecorder, MovePlayer


record_frequency = 20.0 # This means that a new position will be recorded 50 times per second.
recorded_motors = poppy.r_leg
# You can also use alias for the recorded_motors
# e.g. recorder = MoveRecorder(poppy, record_frequency, poppy.tip)
# or even to record all motors position
# recorder = MoveRecorder(poppy, record_frequency, poppy.motors)

recorder = MoveRecorder(poppy, record_frequency, recorded_motors)

for m in recorded_motors:
    m.compliant = True
  
print "start recording"    
recorder.start()

time.sleep(4)

print "stop recording" 
recorder.stop()

recorded_move = recorder.move

Example #9
0
    def setup(self):
        for m in self.robot.motors:
            m.compliant = True

        self.recorder = MoveRecorder(self.robot, 50.0, self.robot.motors)
        self.recorder.start()
Example #10
0
import time
import pypot.robot

from pypot.primitive.move import MoveRecorder, Move, MovePlayer
#  Todo: Import is not working in runtime
from configs.ergo_config import ergo_config

robot = pypot.robot.from_config(ergo_config)

move_recorder = MoveRecorder(robot, 50, robot.motors)

robot.compliant = True
print("start recording..")
move_recorder.start()
time.sleep(5)
print("Recording end.")
move_recorder.stop()

with open('my_nice_move.move', 'w') as f:
    move_recorder.move.save(f)

with open('my_nice_move.move') as f:
    m = Move.load(f)

robot.compliant = False

print("Play recording")
move_player = MovePlayer(robot, m)
move_player.start()
time.sleep(10)
print("recording played")