Esempio n. 1
0
def forever():
  global Ref, Left, Mid, Right
  if getGrayscaleValue() != [0, 0, 0]:
    backward(50)
    delay(500)
    set_dir_servo_angle(30)
    forward(30)
    delay(500)
    set_dir_servo_angle(0)
  else:
    forward(20)
Esempio n. 2
0
def outHandle():
  global sta, value, direction, Ref, Left, Mid, Right, lastSta, currentSta
  if lastSta == 'LEFT':
    set_dir_servo_angle((-30))
    backward(10)
  elif lastSta == 'RIGHT':
    set_dir_servo_angle(30)
    backward(10)
  while True:
    currentSta = getDirection()
    if currentSta != lastSta:
      break
  delay(1)
Esempio n. 3
0
def forever():
    global x_axis, width, pan_angle
    x_axis = Vilib.color_detect_object('x')
    width = Vilib.color_detect_object('width')
    delay(5)
    if x_axis == -1:
        pan_angle = pan_angle - 1
        pan_angle = constrain(pan_angle, -90, 90)
        set_camera_servo1_angle(pan_angle)
        pan_angle = constrain(pan_angle, -45, 45)
        set_dir_servo_angle(pan_angle)
    elif x_axis == 1:
        pan_angle = pan_angle + 1
        pan_angle = constrain(pan_angle, -90, 90)
        set_camera_servo1_angle(pan_angle)
        pan_angle = constrain(pan_angle, -45, 45)
        set_dir_servo_angle(pan_angle)
    if width > 50:
        forward(50)
    else:
        stop()
Esempio n. 4
0
def forever():
    forward(50)
    delay(1000)
    backward(50)
    delay(1000)
    forward(50)
    set_dir_servo_angle((-30))
    delay(1000)
    forward(50)
    set_dir_servo_angle(30)
    delay(1000)
    set_dir_servo_angle(0)
    stop()
    delay(2000)
Esempio n. 5
0
def forever():
  global value, direction, status, Ref, Left, Mid, Right
  status = getDirection()
  if status == 'FORWARD':
    set_dir_servo_angle(0)
    forward(10)
  elif status == 'LEFT':
    set_dir_servo_angle(20)
    forward(10)
  elif status == 'RIGHT':
    set_dir_servo_angle((-20))
    forward(10)
  elif status == 'OUT':
    stop()
Esempio n. 6
0
def forever():
    global Ref1, distance, Ref2
    distance = Ultrasonic(pin_D0, pin_D1).read()
    if distance >= Ref1:
        set_dir_servo_angle(0)
        forward(50)
    elif distance >= Ref2:
        set_dir_servo_angle(40)
        forward(50)
        delay(500)
    else:
        set_dir_servo_angle((-40))
        backward(50)
        delay(500)
Esempio n. 7
0
def forever():
  global sta, value, direction, Ref, Left, Mid, Right, lastSta, currentSta
  sta = getDirection()
  if sta != 'OUT':
    lastSta = sta
  if sta == 'FORWERD':
    set_dir_servo_angle(0)
    forward(10)
  elif sta == 'LEFT':
    set_dir_servo_angle(20)
    forward(10)
  elif sta == 'RIGHT':
    set_dir_servo_angle((-20))
    forward(10)
  elif sta == 'OUT':
    outHandle()
Esempio n. 8
0
def forever():
    global sta, value, direction, Ref, Left, Mid, Right, lastSta, currentSta
    sta = getDirection()
    print(adc_A1.read())
    if sta != 'OUT':
        lastSta = sta
    if sta == 'FORWARD':
        set_dir_servo_angle(0)
        forward(Speed)
    elif sta == 'LEFT':
        set_dir_servo_angle(25)
        forward(Speed)
    elif sta == 'RIGHT':
        set_dir_servo_angle((-25))
        forward(Speed)
    elif sta == 'OUT':
        #outHandle()
        forward(0)
Esempio n. 9
0
def forever():
  global distance
  distance = Ultrasonic(pin_D0, pin_D1).read()
  print("%s"%distance)
  delay(100)

  forward(50)
  delay(1000)
  backward(50)
  delay(1000)
  forward(50)
  set_dir_servo_angle((-30))
  delay(1000)
  forward(50)
  set_dir_servo_angle(30)
  delay(1000)
  set_dir_servo_angle(0)
  stop()
  delay(2000)