def __init__(self, left_motor, right_motor, polarity='inversed'): Tank.__init__(self, left_motor, right_motor, polarity) self.remote = RemoteControl(channel=1) if not self.remote.connected: log.error("%s is not connected" % self.remote) sys.exit(1) self.remote.on_red_up = self.make_move(self.left_motor, self.speed_sp) self.remote.on_red_down = self.make_move(self.left_motor, self.speed_sp * -1) self.remote.on_blue_up = self.make_move(self.right_motor, self.speed_sp) self.remote.on_blue_down = self.make_move(self.right_motor, self.speed_sp * -1)
def __init__(self, left_motor_port, right_motor_port, polarity='inversed', speed=400): LargeMotorPair.__init__(self, left_motor_port, right_motor_port) self.set_polarity(polarity) left_motor = self.motors[left_motor_port] right_motor = self.motors[right_motor_port] self.speed_sp = speed self.remote = RemoteControl(channel=1) self.remote.on_red_up = self.make_move(left_motor, self.speed_sp) self.remote.on_red_down = self.make_move(left_motor, self.speed_sp * -1) self.remote.on_blue_up = self.make_move(right_motor, self.speed_sp) self.remote.on_blue_down = self.make_move(right_motor, self.speed_sp * -1)
def __init__(self, left_motor, right_motor, polarity='inversed'): Tank.__init__(self, left_motor, right_motor, polarity) self.remote = RemoteControl(channel=1) if not self.remote.connected: log.error("%s is not connected" % self.remote) sys.exit(1) self.remote.on_red_up = self.make_move(self.left_motor, self.duty_cycle_sp) self.remote.on_red_down = self.make_move(self.left_motor, self.duty_cycle_sp * -1) self.remote.on_blue_up = self.make_move(self.right_motor, self.duty_cycle_sp) self.remote.on_blue_down = self.make_move(self.right_motor, self.duty_cycle_sp * -1)
class RemoteControlledTank(LargeMotorPair): def __init__(self, left_motor_port, right_motor_port, polarity='inversed', speed=400): LargeMotorPair.__init__(self, left_motor_port, right_motor_port) self.set_polarity(polarity) left_motor = self.motors[left_motor_port] right_motor = self.motors[right_motor_port] self.speed_sp = speed self.remote = RemoteControl(channel=1) self.remote.on_red_up = self.make_move(left_motor, self.speed_sp) self.remote.on_red_down = self.make_move(left_motor, self.speed_sp * -1) self.remote.on_blue_up = self.make_move(right_motor, self.speed_sp) self.remote.on_blue_down = self.make_move(right_motor, self.speed_sp * -1) def make_move(self, motor, dc_sp): def move(state): if state: motor.run_forever(speed_sp=dc_sp) else: motor.stop() return move def main(self): try: while True: self.remote.process() time.sleep(0.01) # Exit cleanly so that all motors are stopped except (KeyboardInterrupt, Exception) as e: log.exception(e) self.stop()
class RemoteControlledTank(Tank): def __init__(self, left_motor, right_motor, polarity='inversed'): Tank.__init__(self, left_motor, right_motor, polarity) self.remote = RemoteControl(channel=1) if not self.remote.connected: log.error("%s is not connected" % self.remote) sys.exit(1) self.remote.on_red_up = self.make_move(self.left_motor, self.speed_sp) self.remote.on_red_down = self.make_move(self.left_motor, self.speed_sp * -1) self.remote.on_blue_up = self.make_move(self.right_motor, self.speed_sp) self.remote.on_blue_down = self.make_move(self.right_motor, self.speed_sp * -1) def make_move(self, motor, dc_sp): def move(state): if state: motor.run_forever(speed_sp=dc_sp) else: motor.stop() return move def main(self): try: while True: self.remote.process() time.sleep(0.01) # Exit cleanly so that all motors are stopped except (KeyboardInterrupt, Exception) as e: log.exception(e) for motor in list_motors(): motor.stop()
class RemoteControlledTank(Tank): def __init__(self, left_motor, right_motor, polarity='inversed'): Tank.__init__(self, left_motor, right_motor, polarity) self.remote = RemoteControl(channel=1) if not self.remote.connected: log.error("%s is not connected" % self.remote) sys.exit(1) self.remote.on_red_up = self.make_move(self.left_motor, self.duty_cycle_sp) self.remote.on_red_down = self.make_move(self.left_motor, self.duty_cycle_sp * -1) self.remote.on_blue_up = self.make_move(self.right_motor, self.duty_cycle_sp) self.remote.on_blue_down = self.make_move(self.right_motor, self.duty_cycle_sp * -1) def make_move(self, motor, dc_sp): def move(state): if state: motor.run_forever(duty_cycle_sp=dc_sp) else: motor.stop() return move def main(self): try: while True: self.remote.process() time.sleep(0.01) # Exit cleanly so that all motors are stopped except (KeyboardInterrupt, Exception) as e: log.exception(e) for motor in list_motors(): motor.stop()