class BowPrimitive(pypot.primitive.LoopPrimitive): def __init__(self, robot, steps, freq=1000): self.robot = robot self.left_right_controller = EasingController(robot.left_right, SinusoidalEase, steps) self.left_right_controller.goal = 55 self.left_right_controller.__iter__() self.knee_controller = EasingController(robot.knee, SinusoidalEase, steps) self.knee_controller.goal = 25 self.knee_controller.__iter__() self.anticipate = True #hacky hack pypot.primitive.LoopPrimitive.__init__(self, robot, freq) # The update function is automatically called at the frequency given on the constructor def update(self): try: print("moves motor") self.robot.left_right.goal_position = self.left_right_controller.__next__() self.robot.knee.goal_position = self.knee_controller.__next__() except StopIteration: print("Stops iterator") if self.anticipate: self.left_right_controller.goal = 5 self.left_right_controller.__iter__() self.knee_controller.goal = -10 self.knee_controller.__iter__() self.anticipate = False else: self.stop()
def __init__(self, robot, steps, freq=0.5, goal=0): self.robot = robot self.freq = freq self.controller = EasingController(robot.left_right, BounceEase(), steps) self.controller.goal = goal self.controller.__iter__() pypot.primitive.LoopPrimitive.__init__(self, robot, freq)
def __init__(self, robot, motor_id, action, steps, freq=1000): self.robot = robot self.motor = getattr(self.robot, motor_id) print('motor position:', self.motor.present_position) self.state = action settings = { -1: { 'pos': self.motor.angle_limit[0], 'controller': EasingController(self.motor, SinusoidalEase, steps) }, 0: { 'pos': self.calculate_stop(), 'controller': EasingController(self.motor, SinusoidalEaseOut, steps) }, 1: { 'pos': self.motor.angle_limit[1], 'controller': EasingController(self.motor, SinusoidalEase, steps) } }[action] print('Pos:', settings['pos']) self.freq = freq self.controller = settings['controller'] self.controller.goal = settings['pos'] self.controller.__iter__() print('Go to posisiont: ', motor_id, settings['pos']) pypot.primitive.LoopPrimitive.__init__(self, robot, freq)
def dry_run(self): motor = self.robot.m4 controller = EasingController(motor, BounceEase()) controller.goal = 50 for move in controller: print(move) time.sleep(0.002)
def config_controller_test_array(self): res = {} for motor in self.robot.motors: key = motor.name controller = EasingController(motor) controller.goal = 70 controller.__iter__() res[key] = controller return res
def __init__(self, robot, motor_id, pos, steps, freq=1000): self.robot = robot self.motor = getattr(self.robot, motor_id) self.freq = freq self.controller = EasingController(self.motor, BounceEase(), steps) #self.controller = EasingController(self.motor, BackEase(), steps) #self.controller = EasingController(self.motor, SinusoidalEase, steps) self.controller.goal = pos self.controller.__iter__() print('Go to posisiont: ', motor_id, pos) pypot.primitive.LoopPrimitive.__init__(self, robot, freq)
def __init__(self, robot, steps, freq=1000): self.robot = robot self.left_right_controller = EasingController(robot.left_right, SinusoidalEase, steps) self.left_right_controller.goal = 70 self.left_right_controller.__iter__() self.knee_controller = EasingController(robot.knee, SinusoidalEase, steps) self.knee_controller.goal = -10 self.knee_controller.__iter__() pypot.primitive.LoopPrimitive.__init__(self, robot, freq)
def __init__(self, robot, steps, freq=1000): self.robot = robot self.left_right_controller = EasingController(robot.left_right, SinusoidalEase, steps) self.left_right_controller.goal = 55 self.left_right_controller.__iter__() self.knee_controller = EasingController(robot.knee, SinusoidalEase, steps) self.knee_controller.goal = 25 self.knee_controller.__iter__() self.anticipate = True #hacky hack pypot.primitive.LoopPrimitive.__init__(self, robot, freq)
class EasePrimitive(pypot.primitive.LoopPrimitive): def __init__(self, robot, steps, freq=0.5, goal=0): self.robot = robot self.freq = freq self.controller = EasingController(robot.left_right, BounceEase(), steps) self.controller.goal = goal self.controller.__iter__() pypot.primitive.LoopPrimitive.__init__(self, robot, freq) # The update function is automatically called at the frequency given on the constructor def update(self): try: print("moves motorrr") next_step = self.controller.__next__() self.robot.left_right.goal_position = next_step except StopIteration: print("Stops iterator") self.stop()
class GoToPositionPrimitive(pypot.primitive.LoopPrimitive): def __init__(self, robot, motor_id, pos, steps, freq=1000): self.robot = robot self.motor = getattr(self.robot, motor_id) self.freq = freq self.controller = EasingController(self.motor, BounceEase(), steps) #self.controller = EasingController(self.motor, BackEase(), steps) #self.controller = EasingController(self.motor, SinusoidalEase, steps) self.controller.goal = pos self.controller.__iter__() print('Go to posisiont: ', motor_id, pos) pypot.primitive.LoopPrimitive.__init__(self, robot, freq) # The update function is automatically called at the frequency given on the constructor def update(self): try: print("moves motor") next_step = self.controller.__next__() self.motor.goal_position = next_step except StopIteration: print("Stops iterator") self.stop()
def move_first(self): motor = self.robot.m5 controller = EasingController(motor, LinearEase(), 5000) controller.goal = -50 for move in controller: motor.goal_position = move time.sleep(0.0002) else: print("Move done") controller.goal = -70 time.sleep(2) for move in controller: motor.goal_position = move time.sleep(0.0002) else: print("Move done") self.robot.stop_sync()
def __init__(self, robot, refresh_freq): self.robot = robot self.up_down_controller = EasingController(robot.up_down, SinusoidalEase) self.up_down_controller.goal = 0 self.up_down_controller.__iter__() self.left_right_controller = EasingController(robot.left_right, SinusoidalEase) self.left_right_controller.goal = 0 self.left_right_controller.__iter__() self.rotation_controller = EasingController(robot.rotation, SinusoidalEase) self.rotation_controller.goal = 0 self.rotation_controller.__iter__() self.knee_controller = EasingController(robot.knee, SinusoidalEase) self.knee_controller.goal = 25 self.knee_controller.__iter__() pypot.primitive.LoopPrimitive.__init__(self, robot, refresh_freq)
class MainPositionPrimitive(pypot.primitive.LoopPrimitive): def __init__(self, robot, refresh_freq): self.robot = robot self.up_down_controller = EasingController(robot.up_down, SinusoidalEase) self.up_down_controller.goal = 0 self.up_down_controller.__iter__() self.left_right_controller = EasingController(robot.left_right, SinusoidalEase) self.left_right_controller.goal = 0 self.left_right_controller.__iter__() self.rotation_controller = EasingController(robot.rotation, SinusoidalEase) self.rotation_controller.goal = 0 self.rotation_controller.__iter__() self.knee_controller = EasingController(robot.knee, SinusoidalEase) self.knee_controller.goal = 25 self.knee_controller.__iter__() pypot.primitive.LoopPrimitive.__init__(self, robot, refresh_freq) # The update function is automatically called at the frequency given on the constructor def update(self): try: print("moves motor") self.robot.up_down.goal_position = self.up_down_controller.__next__( ) self.robot.left_right.goal_position = self.left_right_controller.__next__( ) self.robot.rotation.goal_position = self.rotation_controller.__next__( ) self.robot.knee.goal_position = self.knee_controller.__next__() except StopIteration: print("Stops iterator") self.stop()