CARIA.2.2
Update for the final presentation huge change with previous version
This commit is contained in:
@@ -1,26 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import time, sys
|
||||
sys.path.append('/home/christian/WebControl/modules/')
|
||||
from AlphaBot import AlphaBot
|
||||
Ab = AlphaBot()
|
||||
|
||||
ObstaclePin = 16
|
||||
status = "initialization"
|
||||
DURATION_LIMIT = 5
|
||||
|
||||
def setup():
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(ObstaclePin, GPIO.IN)
|
||||
|
||||
def loop():
|
||||
while True:
|
||||
if GPIO.input(ObstaclePin) == GPIO.LOW:
|
||||
print("Obstacle détecté")
|
||||
else:
|
||||
print("Aucun obstacle détecté")
|
||||
time.sleep(0.5) # Attendre un peu entre les lectures pour éviter les faux positifs
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setup()
|
||||
try:
|
||||
start_time = time.time() # Enregistrer l'heure de début
|
||||
try:
|
||||
loop()
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
while time.time() - start_time < DURATION_LIMIT:
|
||||
if GPIO.input(Ab.OBSTACLE_PIN) == GPIO.LOW:
|
||||
print("Obstacle détecté")
|
||||
GPIO.output(Ab.RED_LIGHT, GPIO.HIGH)
|
||||
status = "obstacle detected"
|
||||
else:
|
||||
print("Aucun obstacle détecté")
|
||||
GPIO.output(Ab.RED_LIGHT, GPIO.LOW)
|
||||
status = "no obstacle detected"
|
||||
time.sleep(0.5) # Attendre un peu entre les lectures pour éviter les faux positifs
|
||||
except Exception as e:
|
||||
print(f"Erreur pendant l'exécution: {e}")
|
||||
status = "erreur"
|
||||
except KeyboardInterrupt:
|
||||
print("Interruption par l'utilisateur.")
|
||||
status = "interrupted"
|
||||
finally:
|
||||
GPIO.output(Ab.RED_LIGHT, GPIO.LOW)
|
||||
Ab.cleanup()
|
||||
|
||||
# Vérification finale et affichage du statut
|
||||
if status in ["obstacle detected", "no obstacle detected"]:
|
||||
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)
|
||||
@@ -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)
|
||||
@@ -1,45 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
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"
|
||||
# Test de la classe AlphaBot avec différentes vitesses pour les moteurs individuels
|
||||
def test_alphabot_speed():
|
||||
bot = AlphaBot()
|
||||
try:
|
||||
while True: # Boucle infinie
|
||||
for speed in range(20, 101, 40):
|
||||
print(f"Test de vitesse à {speed}%")
|
||||
|
||||
# Vérifier si speed est une chaîne non vide
|
||||
if speed != '':
|
||||
# Test des moteurs en avance
|
||||
bot.forward(speed)
|
||||
time.sleep(1)
|
||||
bot.stop()
|
||||
time.sleep(0.5)
|
||||
|
||||
# Test des moteurs en arrière
|
||||
bot.backward(speed)
|
||||
time.sleep(1)
|
||||
bot.stop()
|
||||
time.sleep(0.5)
|
||||
|
||||
# Test du moteur gauche en avant et moteur droit en arrière
|
||||
bot.left(speed)
|
||||
time.sleep(1)
|
||||
bot.stop()
|
||||
time.sleep(0.5)
|
||||
|
||||
# Test du moteur gauche en arrière et moteur droit en avant
|
||||
bot.right(speed)
|
||||
time.sleep(1)
|
||||
bot.stop()
|
||||
time.sleep(0.5)
|
||||
except KeyboardInterrupt:
|
||||
bot.cleanup()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_alphabot_speed()
|
||||
duration = 0.5
|
||||
try:
|
||||
for speed in range(20, 81, 30):
|
||||
print(f"Test de vitesse à {speed}%")
|
||||
# Test des moteurs en avance
|
||||
Ab.forward(duration, speed)
|
||||
Ab.stop(1)
|
||||
# Test des moteurs en arrière
|
||||
Ab.backward(duration, speed)
|
||||
Ab.stop(1)
|
||||
# Test du moteur gauche en avant et moteur droit en arrière
|
||||
Ab.left(duration, speed)
|
||||
Ab.stop(1)
|
||||
# Test du moteur gauche en arrière et moteur droit en avant
|
||||
Ab.right(duration, speed)
|
||||
Ab.stop(1)
|
||||
status = "move successful"
|
||||
except KeyboardInterrupt:
|
||||
print("Interruption par l'utilisateur.")
|
||||
status = "interrupted"
|
||||
except Exception as e:
|
||||
print(f"Erreur lors du test: {e}")
|
||||
status = "error"
|
||||
finally:
|
||||
Ab.cleanup()
|
||||
|
||||
# Vérification finale et affichage du statut
|
||||
if status == "move 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)
|
||||
48
WebControl/tests/rfid_open_door.py
Normal file
48
WebControl/tests/rfid_open_door.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import time, sys
|
||||
sys.path.append('/home/christian/WebControl/modules/')
|
||||
from SimpleMFRC522 import SimpleMFRC522
|
||||
RFID_MODULE = SimpleMFRC522()
|
||||
from AlphaBot import AlphaBot
|
||||
Ab = AlphaBot()
|
||||
|
||||
status = "initialization"
|
||||
fonctionnement_ok = False
|
||||
|
||||
# Lecture initiale du tag RFID
|
||||
try:
|
||||
print("La porte est actuellement fermée.\nVeuillez approcher votre badge RFID du capteur pour accéder au véhicule.")
|
||||
id_rfid, text_rfid = RFID_MODULE.read()
|
||||
if text_rfid in ["CHRIS "]:
|
||||
Ab.set_angle(90)
|
||||
print(f"Salut {text_rfid.rstrip()}, votre accès est validé avec succès.\nLa porte du véhicule est maintenant ouverte!")
|
||||
status = "Access successful"
|
||||
elif text_rfid == "TEST RFID ":
|
||||
Ab.set_angle(90)
|
||||
print(f"Bienvenue, {text_rfid.rstrip()}.\nLa porte du véhicule est maintenant ouverte!")
|
||||
status = "Access successful"
|
||||
else:
|
||||
print("Bonjour, vous n'êtes pas autorisé à entrer dans le véhicule.\nLa porte reste fermée.")
|
||||
status = "Access denied"
|
||||
print(f"(ID, Text)",id_rfid, text_rfid)
|
||||
time.sleep(2)
|
||||
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:
|
||||
Ab.PWMSERVO.stop()
|
||||
time.sleep(2)
|
||||
|
||||
# Vérification finale et affichage du statut
|
||||
if status == "Access 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)
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Importation des bibliothèques
|
||||
import time
|
||||
from gpiozero import LED
|
||||
from joyit_mfrc522 import SimpleMFRC522
|
||||
|
||||
# Initialisation de l'objet pour le module RFID
|
||||
reader = SimpleMFRC522()
|
||||
|
||||
# Fonction pour la lecture du tag RFID
|
||||
def read_rfid():
|
||||
print("### Lecture RFID ###")
|
||||
print("Approchez le tag RFID du capteur:")
|
||||
id, text = reader.read()
|
||||
print("ID:", id)
|
||||
print("Contenu:", text)
|
||||
time.sleep(5)
|
||||
|
||||
# Fonction pour l'écriture sur le tag RFID avec gestion des erreurs
|
||||
def write_rfid(data, max_attempts=3):
|
||||
print("### Écriture RFID ###")
|
||||
print("Valeur qui sera écrite:", data)
|
||||
print("Approchez le tag RFID du capteur:")
|
||||
try:
|
||||
reader.write(data)
|
||||
print("Succès de l'écriture sur le tag RFID.")
|
||||
time.sleep(3) # Attente courte avant de vérifier l'écriture
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de l'écriture RFID: {e}")
|
||||
time.sleep(3) # Attendre avant de réessayer
|
||||
|
||||
# Lecture initiale du tag RFID
|
||||
read_rfid()
|
||||
|
||||
# Écriture sur le tag RFID
|
||||
write_rfid("TEST RFID")
|
||||
|
||||
# Seconde lecture du tag RFID
|
||||
read_rfid()
|
||||
@@ -1,31 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import time,sys
|
||||
sys.path.append('/home/christian/WebControl/modules/')
|
||||
from AlphaBot import AlphaBot
|
||||
Ab = AlphaBot()
|
||||
|
||||
# Définir la broche GPIO pour le signal du servo-moteur
|
||||
SERVO_PIN = 27
|
||||
status = "initialization"
|
||||
try:
|
||||
Ab.set_angle(0)
|
||||
print("Positionné à 0°")
|
||||
time.sleep(2)
|
||||
Ab.set_angle(90)
|
||||
print("Positionné à 90°")
|
||||
time.sleep(2)
|
||||
Ab.set_angle(180)
|
||||
print("Positionné à 180°")
|
||||
time.sleep(2)
|
||||
Ab.set_angle(0)
|
||||
print("Positionné à 0°")
|
||||
status = "movement successful"
|
||||
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:
|
||||
Ab.PWMSERVO.stop()
|
||||
Ab.cleanup()
|
||||
|
||||
def setup():
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(SERVO_PIN, GPIO.OUT)
|
||||
# Vérification finale et affichage du statut
|
||||
if status == "movement successful":
|
||||
print("Le composant fonctionne correctement.")
|
||||
fonctionnement_ok = True
|
||||
else:
|
||||
print(f"Le composant a rencontré un problème: {status}.")
|
||||
fonctionnement_ok = False
|
||||
|
||||
def set_angle(angle):
|
||||
pwm = GPIO.PWM(SERVO_PIN, 50) # Fréquence PWM de 50 Hz
|
||||
pwm.start(2.5) # Position neutre (angle de 0 degrés)
|
||||
duty_cycle = angle / 18.0 + 2.5 # Convertir l'angle en devoir (duty cycle)
|
||||
pwm.ChangeDutyCycle(duty_cycle)
|
||||
time.sleep(0.5) # Attendre que le servo atteigne la position désirée
|
||||
pwm.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
setup()
|
||||
while True:
|
||||
# Faire tourner le servo-moteur de 0 à 180 degrés avec un pas de 30 degrés
|
||||
for angle in range(0, 181, 30):
|
||||
print("Rotation du servo moteur à {} degrés".format(angle))
|
||||
set_angle(angle)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
Ab.enregistrer_resultats(sys.argv[0], fonctionnement_ok, status)
|
||||
Reference in New Issue
Block a user