CARIA.2.0
Repo initial CARIA : MAJ Interface Bootle amélioré - Optimisation de la structure - amélioration des fonctionnalités - debug . . .
This commit is contained in:
26
WebControl/tests/infrared_obstacle_module.py
Normal file
26
WebControl/tests/infrared_obstacle_module.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
ObstaclePin = 16
|
||||
|
||||
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:
|
||||
loop()
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
23
WebControl/tests/lidar_module.py
Normal file
23
WebControl/tests/lidar_module.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import serial
|
||||
import 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()
|
||||
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)
|
||||
finally:
|
||||
if 'ser' in locals():
|
||||
ser.close() # Fermeture propre du port série
|
||||
45
WebControl/tests/motor_speed_move.py
Normal file
45
WebControl/tests/motor_speed_move.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import sys
|
||||
sys.path.append('/home/christian/WebControl/modules/')
|
||||
from AlphaBot import AlphaBot
|
||||
|
||||
# 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()
|
||||
40
WebControl/tests/rfid_read_write_module.py
Normal file
40
WebControl/tests/rfid_read_write_module.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/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()
|
||||
31
WebControl/tests/servo_motor.py
Normal file
31
WebControl/tests/servo_motor.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
# Définir la broche GPIO pour le signal du servo-moteur
|
||||
SERVO_PIN = 27
|
||||
|
||||
def setup():
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(SERVO_PIN, GPIO.OUT)
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user