示例#1
0
 def test_speed(self):
     motordevice.speed(PORTS,20)        
     test_util.wait(5, print_motor_info )
示例#2
0
def ir_control(speed):
	remote_control_map = {
	0: {'label': 'off', 'motor': both, 'value': 0},
	1: {'label': 'left_up', 'motor': D, 'value': speed},
	2: {'label': 'left_down', 'motor': D, 'value': MAX_VALUE-speed},
	3: {'label': 'right_up', 'motor': A, 'value': speed},
	4: {'label': 'right_down', 'motor': A, 'value': MAX_VALUE-speed},
	5: {'label': 'both_up', 'motor': both, 'value': speed},
	6: {'label': 'left_up_right_down', 'motor': both, 'value': 0},
	7: {'label': 'left_down_right_up', 'motor': both, 'value': 0},
	8: {'label': 'both_down', 'motor': both, 'value': MAX_VALUE-speed},
	9: {'label': 'top', 'motor': both, 'value': 0},
	10:{'label': 'both_left', 'motor': both, 'value': 0},
	11:{'label': 'both_right', 'motor': both, 'value': 0}
}
	print "ir_control mode"
	ir_sensor = EV3IRSensor(ev3.SENSOR_2)
	print "setting remote control mode"
	ir_sensor.set_remote_control_mode()
	#motordevice.stop(both,brake=0)    	
	while True:
	    ir_sensor_command = ir_sensor.get_remote_control_command(channel=1)
	    ir_sensor_command_dict = remote_control_map.get(ir_sensor_command)
	    if ir_sensor_command == 6:
	    	motordevice.speed(D, speed)
	    	motordevice.speed(A,MAX_VALUE-speed)
	    elif ir_sensor_command == 7:
	    	motordevice.speed(D, MAX_VALUE-speed)
	    	motordevice.speed(A,speed)
	    elif ir_sensor_command != 0:
	        print "command: {0} - {1}".format(
	        	ir_sensor_command,
	        	ir_sensor_command_dict.get('label')
	        )
	        motordevice.speed(
	        	ir_sensor_command_dict.get('motor'),
	    		ir_sensor_command_dict.get('value')
	        )
	    else:
	    	motordevice.speed(both,0)
			#motordevice.stop(both,brake=1)    	
	    time.sleep(.1)
示例#3
0
uartdevice.open_device()

A = 0x01
B = 0x02
C = 0x04
D = 0x08

right = A
left = D
both = A + D

touch = lego.EV3TouchSensor(0)
ir = lego.EV3IRSensor(3)
ir.set_prox_mode()

motordevice.speed(both, 20)

distance = 101

while True:
    time.sleep(1)
    if touch.is_pressed() == 1:
        motordevice.stop(both, brake=1)
        print "stopping\n"
        break

    cur_distance = ir.get_distance()
    if cur_distance > distance:
        print "searching\n"
        motordevice.stop(both, brake=1)
        motordevice.speed(A, 20)
uartdevice.open_device() 

A = 0x01
B = 0x02
C = 0x04
D = 0x08

right = A
left = D
both = A+D

touch = lego.EV3TouchSensor(0)
ir = lego.EV3IRSensor(3)
ir.set_prox_mode()

motordevice.speed(both,20)

distance = 101

while True:
  time.sleep(1)
  if touch.is_pressed() == 1:
    motordevice.stop(both, brake=1)
    print "stopping\n"
    break

  cur_distance = ir.get_distance()
  if cur_distance > distance:
    print "searching\n"
    motordevice.stop(both, brake=1)
    motordevice.speed(A, 20)