예제 #1
0
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)
        time.sleep(1)
        motordevice.stop(A, brake=1)
        motordevice.speed(both, 20)

    distance = cur_distance

motordevice.stop(both, brake=1)
예제 #2
0
 def tearDown(self):
     motordevice.stop(PORTS,brake=1)
     pass
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)
    time.sleep(1)
    motordevice.stop(A, brake=1)
    motordevice.speed(both,20)

  distance = cur_distance

motordevice.stop(both, brake=1)