TTs whisper
This commit is contained in:
156
raspi/tests/test_eyes.py
Normal file
156
raspi/tests/test_eyes.py
Normal file
@@ -0,0 +1,156 @@
|
||||
"""
|
||||
test_eyes.py — Tests individuals del mòdul eyes.py.
|
||||
Executa des del directori Rasp/: python tests/test_eyes.py
|
||||
|
||||
Descomenta la funció que vols provar al final del fitxer.
|
||||
Assegura't que el venv està activat i pigpiod en marxa (sudo pigpiod -s 1).
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
import time
|
||||
import pigpio
|
||||
from eyes import (
|
||||
eyes_setup, eyes_cleanup,
|
||||
eyes_turn_on, eyes_turn_off,
|
||||
eyes_gesture_mode_on, eyes_gesture_mode_off, eyes_listening,
|
||||
EYES_OPEN, EYES_FW, EYES_DOWN, EYES_GESTURE,
|
||||
WHITE, RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, CYAN, BLACK,
|
||||
)
|
||||
|
||||
def _setup():
|
||||
pi = pigpio.pi()
|
||||
if not pi.connected:
|
||||
print("ERROR: pigpiod no està en marxa. Executa: sudo pigpiod -s 1")
|
||||
sys.exit(1)
|
||||
eyes_setup(pi)
|
||||
return pi
|
||||
|
||||
def _teardown(pi):
|
||||
eyes_cleanup()
|
||||
pi.stop()
|
||||
|
||||
|
||||
# ==================
|
||||
# TEST 1 — Formes i colors bàsics
|
||||
# ==================
|
||||
|
||||
def test_shapes():
|
||||
"""
|
||||
Mostra totes les formes existents en colors diferents.
|
||||
Hauries de veure les formes als ulls LED del robot.
|
||||
"""
|
||||
print("=== TEST FORMES I COLORS ===")
|
||||
pi = _setup()
|
||||
|
||||
print("EYES_OPEN en blanc...")
|
||||
eyes_turn_on(EYES_OPEN, WHITE)
|
||||
time.sleep(2.0)
|
||||
|
||||
print("EYES_FW en vermell...")
|
||||
eyes_turn_on(EYES_FW, RED)
|
||||
time.sleep(2.0)
|
||||
|
||||
print("EYES_DOWN en blau...")
|
||||
eyes_turn_on(EYES_DOWN, BLUE)
|
||||
time.sleep(2.0)
|
||||
|
||||
print("EYES_OPEN en verd...")
|
||||
eyes_turn_on(EYES_OPEN, GREEN)
|
||||
time.sleep(2.0)
|
||||
|
||||
print("Apagant...")
|
||||
eyes_turn_off()
|
||||
time.sleep(1.0)
|
||||
|
||||
_teardown(pi)
|
||||
print("Test formes completat.\n")
|
||||
|
||||
|
||||
# ==================
|
||||
# TEST 2 — Animació de repeat i direcció
|
||||
# ==================
|
||||
|
||||
def test_animation():
|
||||
"""
|
||||
Prova l'animació amb repeat i les dues direccions.
|
||||
Hauries de veure els LEDs encenent-se un per un en ordre normal i invers.
|
||||
"""
|
||||
print("=== TEST ANIMACIÓ ===")
|
||||
pi = _setup()
|
||||
|
||||
print("EYES_OPEN groc, repeat=2, endavant...")
|
||||
eyes_turn_on(EYES_OPEN, YELLOW, repeat=2, forward=True)
|
||||
time.sleep(1.0)
|
||||
|
||||
print("EYES_FW taronja, repeat=2, enrere...")
|
||||
eyes_turn_on(EYES_FW, ORANGE, repeat=2, forward=False)
|
||||
time.sleep(1.0)
|
||||
|
||||
eyes_turn_off()
|
||||
_teardown(pi)
|
||||
print("Test animació completat.\n")
|
||||
|
||||
|
||||
# ==================
|
||||
# TEST 3 — Animacions mode gestos (TFG)
|
||||
# ==================
|
||||
|
||||
def test_gesture_animations():
|
||||
"""
|
||||
Prova les animacions específiques del mode gestos.
|
||||
Hauries de veure: doble parpelleig cian, tornada a blanc, marc cian.
|
||||
"""
|
||||
print("=== TEST ANIMACIONS MODE GESTOS ===")
|
||||
pi = _setup()
|
||||
|
||||
print("Activant mode gestos (doble parpelleig cian)...")
|
||||
eyes_gesture_mode_on()
|
||||
time.sleep(2.0)
|
||||
|
||||
print("Escoltant gest (marc cian)...")
|
||||
eyes_listening()
|
||||
time.sleep(2.0)
|
||||
|
||||
print("Desactivant mode gestos (torna a blanc)...")
|
||||
eyes_gesture_mode_off()
|
||||
time.sleep(2.0)
|
||||
|
||||
eyes_turn_off()
|
||||
_teardown(pi)
|
||||
print("Test animacions gestos completat.\n")
|
||||
|
||||
|
||||
# ==================
|
||||
# TEST 4 — Parpelleig (breathing)
|
||||
# ==================
|
||||
|
||||
def test_breathing():
|
||||
"""
|
||||
Verifica que el thread de parpelleig funciona correctament.
|
||||
Hauries de veure la brillantor dels LEDs pujant i baixant suaument.
|
||||
"""
|
||||
print("=== TEST PARPELLEIG (BREATHING) ===")
|
||||
pi = _setup()
|
||||
|
||||
print("EYES_OPEN blanc — observa el parpelleig durant 10 segons...")
|
||||
eyes_turn_on(EYES_OPEN, WHITE)
|
||||
time.sleep(10.0)
|
||||
|
||||
eyes_turn_off()
|
||||
_teardown(pi)
|
||||
print("Test parpelleig completat.\n")
|
||||
|
||||
|
||||
# ==================
|
||||
# Execució
|
||||
# ==================
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Descomenta el test que vols executar:
|
||||
test_shapes()
|
||||
# test_animation()
|
||||
# test_gesture_animations()
|
||||
# test_breathing()
|
||||
Reference in New Issue
Block a user