def handle_command(args): now = datetime.datetime.now() now_time = now.time() # if it's late, make the robot slower if now_time >= datetime.time(21, 30) or now_time <= datetime.time(9, 30): #print "within the late time interval" drivingSpeedActuallyUsed = nightTimeDrivingSpeedActuallyUsed else: drivingSpeedActuallyUsed = dayTimeDrivingSpeedActuallyUsed global drivingSpeed global handlingCommand if 'robot_id' in args and args['robot_id'] == robotID: print "received message:", args # Note: If you are adding features to your bot, # you can get direct access to incomming commands right here. if handlingCommand: return handlingCommand = True #if 'robot_id' in args: # print "args robot id:", args['robot_id'] #if 'command' in args: # print "args command:", args['command'] if 'command' in args and 'robot_id' in args and args['robot_id'] == robotID: print('got command', args) command = args['command'] if command == 'LOUD': handleLoudCommand() if commandArgs.type == 'adafruit_pwm': moveAdafruitPWM(command) if commandArgs.type == 'gopigo2': moveGoPiGo2(command) if commandArgs.type == 'gopigo3': moveGoPiGo3(command) if commandArgs.type == 'owi_arm': owi_arm.handleOwiArm(command) if commandArgs.type == 'serial': robot_util.sendSerialCommand(ser, command) if commandArgs.type == 'motor_hat' and motorsEnabled: motorA.setSpeed(drivingSpeed) motorB.setSpeed(drivingSpeed) if command == 'F': drivingSpeed = drivingSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, forward[motorIndex]) time.sleep(straightDelay) if command == 'B': drivingSpeed = drivingSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, backward[motorIndex]) time.sleep(straightDelay) if command == 'L': drivingSpeed = turningSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, left[motorIndex]) time.sleep(turnDelay) if command == 'R': drivingSpeed = turningSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, right[motorIndex]) time.sleep(turnDelay) if command == 'U': #mhArm.getMotor(1).setSpeed(127) #mhArm.getMotor(1).run(Adafruit_MotorHAT.BACKWARD) incrementArmServo(1, 10) time.sleep(0.05) if command == 'D': #mhArm.getMotor(1).setSpeed(127) #mhArm.getMotor(1).run(Adafruit_MotorHAT.FORWARD) incrementArmServo(1, -10) time.sleep(0.05) if command == 'O': #mhArm.getMotor(2).setSpeed(127) #mhArm.getMotor(2).run(Adafruit_MotorHAT.BACKWARD) incrementArmServo(2, -10) time.sleep(0.05) if command == 'C': #mhArm.getMotor(2).setSpeed(127) #mhArm.getMotor(2).run(Adafruit_MotorHAT.FORWARD) incrementArmServo(2, 10) time.sleep(0.05) if commandArgs.type == 'motor_hat': turnOffMotors() if command == 'WALL': handleLoudCommand() os.system("aplay -D plughw:2,0 /home/pi/wall.wav") if commandArgs.type == 'l298n': runl298n(command) #setMotorsToIdle() if commandArgs.type == 'motozero': runmotozero(command) if commandArgs.type == 'pololu': runPololu(command) if commandArgs.led == 'max7219': if command == 'LED_OFF': SetLED_Off() if command == 'LED_FULL': SetLED_On() SetLED_Full() if command == 'LED_MED': SetLED_On() SetLED_Med() if command == 'LED_LOW': SetLED_On() SetLED_Low() if command == 'LED_E_SMILEY': SetLED_On() SetLED_E_Smiley() if command == 'LED_E_SAD': SetLED_On() SetLED_E_Sad() if command == 'LED_E_TONGUE': SetLED_On() SetLED_E_Tongue() if command == 'LED_E_SUPRISED': SetLED_On() SetLED_E_Suprised() handlingCommand = False
def sendSettings(ser, args): if args.right_wheel_forward_speed is not None: robot_util.sendSerialCommand( ser, "rwfs " + str(args.right_wheel_forward_speed)) if args.right_wheel_backward_speed is not None: robot_util.sendSerialCommand( ser, "rwbs " + str(args.right_wheel_backward_speed)) if args.left_wheel_forward_speed is not None: robot_util.sendSerialCommand( ser, "lwfs " + str(args.left_wheel_forward_speed)) if args.left_wheel_backward_speed is not None: robot_util.sendSerialCommand( ser, "lwbs " + str(args.left_wheel_backward_speed)) if args.straight_delay is not None: robot_util.sendSerialCommand( ser, "straight-distance " + str(int(args.straight_delay * 255))) if args.turn_delay is not None: robot_util.sendSerialCommand( ser, "turn-distance " + str(int(args.turn_delay * 255))) if args.led_max_brightness is not None: robot_util.sendSerialCommand( ser, "led-max-brightness " + str(args.led_max_brightness))
def handle_command(args): now = datetime.datetime.now() now_time = now.time() # if it's late, make the robot slower if now_time >= datetime.time(21, 30) or now_time <= datetime.time(9, 30): #print "within the late time interval" drivingSpeedActuallyUsed = nightTimeDrivingSpeedActuallyUsed else: drivingSpeedActuallyUsed = dayTimeDrivingSpeedActuallyUsed global drivingSpeed global handlingCommand if 'robot_id' in args and args['robot_id'] == robotID: print "received message:", args # Note: If you are adding features to your bot, # you can get direct access to incomming commands right here. if handlingCommand: return #if 'robot_id' in args: # print "args robot id:", args['robot_id'] #if 'command' in args: # print "args command:", args['command'] if 'command' in args and 'robot_id' in args and args['robot_id'] == robotID: print('got command', args) command = args['command'] if tablemode == 1: if command == "F": return if command == "B": return # don't turn set handlingCommand true for # commands that persist for a while and are not exclusive # so others are allowed to run if command not in ("SOUND2", "WALL", "LOUD", "MAXSPEED"): handlingCommand = True if command == 'LOUD': handleLoudCommand(25) if command == 'MAXSPEED': handleMaxSpeedCommand() if commandArgs.type == 'mdd10': if maxSpeedEnabled: print "AT MAX....................." print maxSpeedEnabled moveMDD10(command, 100) else: print "NORMAL................." print maxSpeedEnabled moveMDD10(command, int(float(drivingSpeedActuallyUsed) / 2.55)) if commandArgs.type == 'adafruit_pwm': moveAdafruitPWM(command) if commandArgs.type == 'mebo2': if command == 'SI': incrementMSpeed(10) time.sleep(0.05) if command == 'SD': incrementMSpeed(-10) time.sleep(0.05) if command == 'TI': incrementTSpeed(10) time.sleep(0.05) if command == 'TD': incrementTSpeed(-10) time.sleep(0.05) handle_mebo_command(command) if commandArgs.type == 'gopigo2': moveGoPiGo2(command) if commandArgs.type == 'gopigo3': moveGoPiGo3(command) if commandArgs.type == 'owi_arm': owi_arm.handleOwiArm(command) if commandArgs.type == 'serial': try: robot_util.sendSerialCommand(ser, command) except Exception as exception: print exception setup_serial() if commandArgs.type == 'motor_hat' and motorsEnabled: motorA.setSpeed(drivingSpeed) motorB.setSpeed(drivingSpeed) if command == 'F': drivingSpeed = drivingSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, forward[motorIndex]) time.sleep(straightDelay) if command == 'B': drivingSpeed = drivingSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, backward[motorIndex]) time.sleep(straightDelay) if command == 'L': drivingSpeed = turningSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, left[motorIndex]) time.sleep(turnDelay) if command == 'R': drivingSpeed = turningSpeedActuallyUsed for motorIndex in range(4): runMotor(motorIndex, right[motorIndex]) time.sleep(turnDelay) if command == 'U': #mhArm.getMotor(1).setSpeed(127) #mhArm.getMotor(1).run(Adafruit_MotorHAT.BACKWARD) incrementArmServo(1, 10) time.sleep(0.05) if command == 'D': #mhArm.getMotor(1).setSpeed(127) #mhArm.getMotor(1).run(Adafruit_MotorHAT.FORWARD) incrementArmServo(1, -10) time.sleep(0.05) if command == 'O': #mhArm.getMotor(2).setSpeed(127) #mhArm.getMotor(2).run(Adafruit_MotorHAT.BACKWARD) incrementArmServo(2, -10) time.sleep(0.05) if command == 'C': #mhArm.getMotor(2).setSpeed(127) #mhArm.getMotor(2).run(Adafruit_MotorHAT.FORWARD) incrementArmServo(2, 10) time.sleep(0.05) if commandArgs.type == 'mdd10': turnOffMotorsMDD10() if commandArgs.type == 'motor_hat': turnOffMotors() if command == 'WALL': handleLoudCommand(25) os.system("aplay -D plughw:2,0 /home/pi/wall.wav") if command == 'SOUND2': handleLoudCommand(25) os.system("aplay -D plughw:2,0 /home/pi/sound2.wav") if commandArgs.type == 'l298n': runl298n(command) #setMotorsToIdle() if commandArgs.type == 'motozero': runmotozero(command) if commandArgs.type == 'pololu': runPololu(command) if commandArgs.led == 'max7219': if command == 'LED_OFF': SetLED_Off() if command == 'LED_FULL': SetLED_On() SetLED_Full() if command == 'LED_MED': SetLED_On() SetLED_Med() if command == 'LED_LOW': SetLED_On() SetLED_Low() if command == 'LED_E_SMILEY': SetLED_On() SetLED_E_Smiley() if command == 'LED_E_SAD': SetLED_On() SetLED_E_Sad() if command == 'LED_E_TONGUE': SetLED_On() SetLED_E_Tongue() if command == 'LED_E_SUPRISED': SetLED_On() SetLED_E_Suprised() handlingCommand = False
def set_eeprom(command, args): if is_authed(args['name']) == 1: # Owner if len(command) >= 2: try: if command[1] == 'left': setting = int( command[3]) # This is here to catch NAN errors if command[2] == 'forward': robot_util.sendSerialCommand(ser, "lwfs " + str(setting)) log.info("left_wheel_forward_speed set to %d", setting) elif command[2] == 'backward': robot_util.sendSerialCommand(ser, "lwbs " + str(setting)) log.info("left_wheel_backward_speed set to %d", setting) elif command[1] == 'right': setting = int( command[3]) # This is here to catch NAN errors if command[2] == 'forward': robot_util.sendSerialCommand(ser, "rwfs " + str(setting)) log.info("right_wheel_forward_speed set to %d", setting) elif command[2] == 'backward': robot_util.sendSerialCommand(ser, "rwbs " + str(setting)) log.info("right_wheel_backward_speed set to %d", setting) elif command[1] == 'straight': setting = int(command[2]) robot_util.sendSerialCommand( ser, "straight-distance " + str(int(setting * 255))) log.info("straigh_delay set to %d", setting) elif command[1] == 'turn': setting = int(command[2]) robot_util.sendSerialCommand( ser, "turn-distance " + str(int(setting * 255))) log.info("turn_delay set to %d", setting) elif command[1] == 'brightness': setting = int( command[2]) # This is here to catch NAN errors robot_util.sendSerialCommand( ser, "led-max-brightness " + str(setting)) log.info("led_man_brightness to %d", setting) except ValueError: pass