CARIA.2.2
Update for the final presentation huge change with previous version
This commit is contained in:
@@ -1,38 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import sys
|
||||
import time, sys
|
||||
sys.path.append('/home/christian/WebControl/modules/')
|
||||
from AlphaBot import AlphaBot
|
||||
|
||||
Ab = AlphaBot()
|
||||
speed = 100
|
||||
DR = 16
|
||||
DL = 19
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(DR,GPIO.IN,GPIO.PUD_UP)
|
||||
GPIO.setup(DL,GPIO.IN,GPIO.PUD_UP)
|
||||
status = "initialization"
|
||||
duration = 0.1
|
||||
speed = 20
|
||||
|
||||
try:
|
||||
while True:
|
||||
DR_status = GPIO.input(DR)
|
||||
DL_status = GPIO.input(DL)
|
||||
if((DL_status == 1) and (DR_status == 1)):
|
||||
Ab.forward(speed)
|
||||
elif((DL_status == 1) and (DR_status == 0)):
|
||||
Ab.left(speed)
|
||||
elif((DL_status == 0) and (DR_status == 1)):
|
||||
Ab.right(speed)
|
||||
else:
|
||||
Ab.backward(speed)
|
||||
time.sleep(0.2)
|
||||
Ab.left(speed)
|
||||
time.sleep(0.2)
|
||||
Ab.stop()
|
||||
|
||||
start_time = time.time() # Enregistrer l'heure de début
|
||||
while time.time() - start_time < 10: # Boucle pendant 5 seconde
|
||||
OBSTACLE_PIN_status = GPIO.input(Ab.OBSTACLE_PIN)
|
||||
if OBSTACLE_PIN_status == 1:
|
||||
Ab.forward(duration, speed)
|
||||
status = "operation successful"
|
||||
else:
|
||||
Ab.emergencystop()
|
||||
status = "emergency stop successful"
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup();
|
||||
print("Interruption par l'utilisateur.")
|
||||
status = "interrupted"
|
||||
finally:
|
||||
Ab.cleanup()
|
||||
# Vérification finale et affichage du statut
|
||||
if status == "operation successful" or status == "emergency stop successful":
|
||||
print(f"Le composant fonctionne correctement: {status}.")
|
||||
fonctionnement_ok = True
|
||||
else:
|
||||
print(f"Le composant a rencontré un problème: {status}.")
|
||||
fonctionnement_ok = False
|
||||
|
||||
Ab.enregistrer_resultats(sys.argv[0], fonctionnement_ok, status)
|
||||
|
||||
Reference in New Issue
Block a user