def main(): s_controller = ServoController() smart_lock = SmartLock() functions = {} functions["cw"] = s_controller.rotate_clockwise functions["ccw"] = s_controller.rotate_counterclockwise functions["ct"] = s_controller.centerlize option = get_options("--operation") if option == "lock": while not smart_lock.is_locked(): functions["ccw"]() print("locked") return elif option == "unlock": while smart_lock.is_locked(): functions["cw"]() print("unlocked") return while True: print("時計回:cw, 反時計回:ccw, 静止位置キャリブレーション:ct") cmd = input() try: functions[cmd]() print("is_locked: %s" % smart_lock.is_locked()) except: del s_controller break
def _setup_controllers(self, robot): self.log.debug("Setup controllers") self.left_wheel = MotorController(robot, type='wheel', id='LEFT') self.right_wheel = MotorController(robot, type='wheel', id='RIGHT') self.camera = VisionController(robot) self.grabber = ServoController(robot, type='grabber') self.arm = ServoController(robot, type='arm') self._setup_switch_sources(robot) #self.bump_FrL = RuggeduinoController(robot, type='bump', id='FRONT_L') #self.bump_FrR = RuggeduinoController(robot, type='bump', id='FRONT_R') #self.bump_BkL = RuggeduinoController(robot, type='bump', id='BACK_L') #self.bump_BkR = RuggeduinoController(robot, type='bump', id='BACK_R') self.token_sensL = RuggeduinoController(robot, type='sensor', id='TOKEN_L') self.token_sensR = RuggeduinoController(robot, type='sensor', id='TOKEN_R')
def serv1(port): try: from servo_controller import ServoController servo = ServoController() except Exception as e: log.debug("Failed to use ServoController: {0}".format(e)) from standins import StandinServoController servo = StandinServoController() try: from motor_controller import MotorController motors = MotorController() except Exception as e: log.debug("failed to use MotorController: {0}".format(e)) from standins import StandinMotorController, StandinMotorDefinition motors = StandinMotorController() motors.defineMotor("right", (14, 15), servo, 0) motors.defineMotor("left", (17, 18), servo, 1) motors.setSignedPWM("left", 0) motors.setSignedPWM("right", 0) time.sleep(0.1) motors.setDirection("left", "B") time.sleep(0.1) motors.setDirection("left", "A") time.sleep(0.1) motors.setDirection("right", "B") time.sleep(0.1) motors.setDirection("right", "A") time.sleep(0.1) addr = ('', port) server = HTTPServer(addr, PyServ) server.servo = servo server.motors = motors server.autodriver = None os.chdir("content") log.debug("Serving on port {0} in {1}".format(port, os.getcwd())) server.serve_forever()
def dispense(): ServoController().dispense() return 'Yiiiisss I very good doggo!'
port=config.APA102_PORT, device=config.APA102_DEVICE, bus_speed_hz=config.APA102_BUS_SPEED_HZ) apa102.set_contrast(config.APA102_DEFAULT_CONTRAST) apa102_controller = APA102Controller(apa102=apa102) servo = Servo( servo_gpio=config.SERVO_GPIO, pulse_left_ns=config.SERVO_PULSE_LEFT_NS, pulse_right_ns=config.SERVO_PULSE_RIGHT_NS) servo_controller = ServoController(servo) mqtt_listener = MQTTListener(config) mqtt_listener.connect() if __name__ == '__main__': try: pause() except KeyboardInterrupt: apa102.clear() servo.idle() mqtt_listener.disconnect() print("Bye")