Browse Source

Dépot final

master
vandepoele.e 2 years ago
parent
commit
932981ab0e
  1. 49
      main.py

49
main.py

@ -123,20 +123,23 @@ def lectension():
return tension return tension
def autoRestart(): def autoRestart():
t = 5 """Fonction faisant repartir automatiquement la voiture ou non"""
checkDist = dist_obstacle() t = 1
print(checkDist)
while t: while t:
mins, secs = divmod(t, 60) mins, secs = divmod(t, 60)
timer = '{:02d}:{:02d}'.format(mins, secs) timer = '{:02d}:{:02d}'.format(mins, secs)
time.sleep(0.5)
t -= 1 t -= 1
if t == 0: if t == 0:
if checkDist - 2.5 < dist_obstacle() < checkDist + 2.5: t = 2
lst.append(dist_obstacle())
if len(lst) == 3:
if abs(lst[0]-lst[2]) <= 6:
backward() backward()
else: lst.clear()
pass
def checkLight(): def checkLight():
"""Fonction allumant la led selon l'intensité du milieu"""
if lectension() < 1: if lectension() < 1:
led_lum.on() led_lum.on()
else: else:
@ -151,28 +154,31 @@ def forward(speed):
return forward return forward
def backward(): def backward():
"""Fonction faisant reculer la voiture"""
sd.angle(30) sd.angle(30)
h1.backward(35) h1.backward(35)
h2.backward(35) h2.backward(35)
t = 2 tBack = 2
while t: while tBack:
mins, secs = divmod(t, 60) mins, secs = divmod(tBack, 60)
timer = '{:02d}:{:02d}'.format(mins, secs) timer = '{:02d}:{:02d}'.format(mins, secs)
time.sleep(1) time.sleep(1)
t -= 1 tBack -= 1
if t == 0: if tBack == 0:
sd.angle(30) sd.angle(30)
h1.backward(35) h1.backward(35)
h2.backward(35) h2.backward(35)
def allSpeed(speed): def allSpeed(speed):
"""Fonction appliquant la vitesse""" """Fonction faisant avancer la voiture"""
if forward(vitesse()): if forward(vitesse()):
sd.angle(0) autoRestart()
sd.angle(1)
h1.forward(speed) h1.forward(speed)
h2.forward(speed) h2.forward(speed)
else: else:
backward() backward()
lst.clear()
def vitesse(): def vitesse():
"""Fonction renvoyant la vitesse selon le terrain""" """Fonction renvoyant la vitesse selon le terrain"""
@ -211,29 +217,24 @@ def vitesse():
led_descente.off() led_descente.off()
led_montee.off() led_montee.off()
#plat #plat
if dist_obstacle() < 15: if dist_obstacle() < 25:
speed = 0 speed = 0
elif dist_obstacle() < 25:
speed = 25
elif dist_obstacle() < 35: elif dist_obstacle() < 35:
speed = 30 speed = 15
elif dist_obstacle() < 45: elif dist_obstacle() < 45:
speed = 40 speed = 25
else: else:
speed = 50 speed = 45
#print(terrain) #print(terrain)
#print(dist_obstacle(), speed)
return speed return speed
marche = True marche = True
lst_terrain = ["descente", "montee", "plat"] lst_terrain = ["descente", "montee", "plat"]
lst = []
sw = pyb.Switch() sw = pyb.Switch()
while True: while True:
"""Boucle principale""" """Boucle principale"""
#autoRestart()
checkLight()
if sw(): if sw():
marche = not marche marche = not marche
while sw(): while sw():
@ -244,4 +245,6 @@ while True:
else: else:
allSpeed(0) allSpeed(0)
checkLight()
#bug : - Détection du terrain défaillant (piste : fonctionnement du capteur accel.x()). #bug : - Détection du terrain défaillant (piste : fonctionnement du capteur accel.x()).
Loading…
Cancel
Save