CARIA.2.2

Update for the final presentation
huge change with previous version
This commit is contained in:
ccunatbrule
2024-09-03 12:17:44 +02:00
parent ebcb596a4f
commit 2ddf2360e6
44 changed files with 7080 additions and 657 deletions

View File

@@ -1,23 +1,50 @@
import serial
import time
import sys
sys.path.append('/home/christian/WebControl/modules/')
from AlphaBot import AlphaBot
Ab = AlphaBot()
# Variable de statut pour indiquer le bon fonctionnement
status = "initialization"
# Durée limite d'exécution en secondes
time_limit = 7
start_time = time.time()
try:
ser = serial.Serial('/dev/ttyAMA0', 115200, timeout=1)
# Envoi de la commande pour initialiser le capteur
ser.write(b'\x42\x57\x02\x00\x00\x00\x01\x06')
while True:
if ser.in_waiting >= 9:
if b'Y' == ser.read() and b'Y' == ser.read():
Dist_L = ser.read()
Dist_H = ser.read()
# Vérification si le temps limite est dépassé
if time.time() - start_time > time_limit:
break
if Ab.LIDAR_MODULE.in_waiting >= 9:
if b'Y' == Ab.LIDAR_MODULE.read() and b'Y' == Ab.LIDAR_MODULE.read():
Dist_L = Ab.LIDAR_MODULE.read()
Dist_H = Ab.LIDAR_MODULE.read()
Dist_Total = (Dist_H[0] * 256) + Dist_L[0]
for i in range(0, 5):
ser.read() # Lecture et ignore des octets supplémentaires
print("Distance:", Dist_Total, "cm")
except serial.SerialException as e:
print("Erreur série:", e)
Ab.LIDAR_MODULE.read() # Lecture et ignore des octets supplémentaires
print("Distance à l'avant du véhicule:", Dist_Total, "cm")
status = "measurement successful"
time.sleep(1)
Ab.LIDAR_MODULE.reset_input_buffer()
except KeyboardInterrupt:
print("Interruption par l'utilisateur.")
status = "interrupted"
except Exception as e:
print(f"Erreur lors de l'exécution: {e}")
status = "error"
finally:
if 'ser' in locals():
ser.close() # Fermeture propre du port série
Ab.LIDAR_MODULE.close() # Fermeture propre du port série
Ab.cleanup()
# Vérification finale et affichage du statut
if status in ["measurement successful"]:
print("Le composant fonctionne correctement.")
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)