def action(deviceName, action): global detection_mode if (deviceName == 'motor'): if action == "fwd": ctl.forward(1, 1) if action == "bwd": ctl.backward(1, 1) if action == "left": ctl.turn_left(30, 30, 1, 1, 1) if action == "right": ctl.turn_right(30, 30, 1, 1, 1) if action == "stop": ctl.detach() if action == "reset": ctl.reset() if action == "speed100": ctl.speed(100, 100) if action == "speed50": ctl.speed(50, 50) if action == "speed10": ctl.speed(10, 10) elif (deviceName == 'cam'): if action == "up": ctl.cam_up() if action == "down": ctl.cam_down_step() if action == "left": ctl.cam_left() if action == "right": ctl.cam_right_step() if action == "stop": ctl.cam_stop() if action == "reset": ctl.cam_position_reset() if action == "h_patrol": ctl.cam_h_patrol() if action == "v_patrol": ctl.cam_v_patrol() elif (deviceName == 'detection'): # Toggle detection button if action == "toggle": detection_mode = not detection_mode return '', 204
def action(deviceName, action): if action == "fwd": ctl.forward() if action == "bwd": ctl.backward() if action == "left": ctl.turn_left() if action == "right": ctl.turn_right() if action == "stop": ctl.detach() if action == "reset": ctl.reset() if action == "speed100": ctl.speed(100,100) if action == "speed50": ctl.speed(50,50) if action == "speed10": ctl.speed(10,10) return '', 204
if FORWARDING: #moving forward if allow_straight: if (TURNR or TURNL): ctl.forward() TURNL = 0 TURNR = 0 elif allow_turn_right: ctl.turn_right() TURNR = 1 elif allow_turn_left: ctl.turn_left() TURNL = 1 else: #turn 180 degreens back. ctl.backward() BACKWARDING = 1 FORWARDING = 0 if BACKWARDING: #moving backward if allow_turn_left: ctl.turn_left() ctl.forward() BACKWARDING = 0 FORWARDING = 1 elif allow_turn_right: ctl.turn_right() ctl.forward() BACKWARDING = 0 FORWARDING = 1 else:
if FORWARDING:#moving forward if allow_straight: #keep forward if (TURNR or TURNL): #change to forward if it was from forward->turn ctl.forward(1,1) TURNL = 0 TURNR = 0 elif allow_turn_right: #turn whenever allowed, right first. After turn, speed at 1,1 #tl=30,tr=30,t=0.5,al=1,ar=1 ctl.turn_right(30,30,2,1,1) TURNR = 1; elif allow_turn_left: #turn left when allowed. After turn, speed at 1,1 ctl.turn_left(30,30,2,1,1) TURNL = 1 else: #was moving forward, not allow straight, right and left. Turn 180 degreens back. ctl.backward(1,1) BACKWARDING=1 FORWARDING=0 if BACKWARDING: #moving backward if allow_turn_left: time.sleep(3) #wait the robot head out of the block ctl.turn_left(30,30,2,1,1) ctl.forward(1,1) BACKWARDING=0 FORWARDING=1 elif allow_turn_right: time.sleep(3) #wait the robot head out of the block ctl.turn_right(30,30,2,1,1) ctl.forward(1,1) BACKWARDING=0