Développeur>Tutoriels>Suivie de mur

Voici un programme d’exemple pour faire un suivi de mur :

from mrpi1_lib import *
import time

#----------------------------------------------
#-------------[ main program ]-----------------

print "Start wall follow"

speed_turn = 30
speed_forward = 40

zone_hight = 600

while 1:

  # lecture des capteurs de proximite
  pr1 = proxSensor(3)
  pr2 = proxSensor(4)
  pr3 = proxSensor(3)
  pr4 = proxSensor(4)
  pr5 = proxSensor(5)
  pr6 = proxSensor(6)
 
  print "Proximity sensors = %d" %(pr6)
  time.sleep(0.1)
  
  if (pr6 > zone_hight):
    print "Turn left"
    turnLeft(speed_turn)
  if pr6 < 300:
    print "Turn right"
    motorRight(0,30)
    motorLeft(0,80)
  if pr6 > 300 and pr6 < zone_hight:
    forward(speed_forward)
    print "forward"
  if pr3 > zone_hight and pr4 > zone_hight:
    turnLeft(speed_turn)
    print "Turn left"
  if pr1 < 300 and pr2 < 300 and pr3 < 300 and pr4 < 300 and pr5 < 300 and pr6 < 300:
    motorRight(0,20)
    motorLeft(0,80)
    print "turnRight - nothing !!"
  if (pr3 > zone_hight) or (pr4 > zone_hight):
    print "Turn left"
    turnLeft(speed_turn)