diff --git a/labyrinthe/6-jumeaux/test/cam_bille-test.py b/labyrinthe/6-jumeaux/test/cam_bille-test.py index 6c0b4c2..12e3644 100644 --- a/labyrinthe/6-jumeaux/test/cam_bille-test.py +++ b/labyrinthe/6-jumeaux/test/cam_bille-test.py @@ -6,12 +6,11 @@ import cv2 ############################################################################### # cam_bille-test.py : # @title: Détection de la bille par vision (caméra + OpenCV) -# @project: Blender-EduTech - Tutoriel : Tutoriel 6 Labyrinthe à bille - Développement de jumeau numérique +# @project: Blender-EduTech - Tutoriel : Tutoriel 6 : Labyrinthe à bille - Développement de jumeau numérique # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2023 Philippe Roy # @license: GNU GPL -# ############################################################################### ### diff --git a/labyrinthe/6-jumeaux/test/documentation/fr0109m.pdf b/labyrinthe/6-jumeaux/test/documentation/fr0109m.pdf new file mode 100644 index 0000000..6b9858e Binary files /dev/null and b/labyrinthe/6-jumeaux/test/documentation/fr0109m.pdf differ diff --git a/labyrinthe/6-jumeaux/test/manette-test/manette-test.ino b/labyrinthe/6-jumeaux/test/manette-test/manette-test.ino index f9d880d..c8b411e 100644 --- a/labyrinthe/6-jumeaux/test/manette-test/manette-test.ino +++ b/labyrinthe/6-jumeaux/test/manette-test/manette-test.ino @@ -10,7 +10,6 @@ * @authors: Philippe Roy * @copyright: Copyright (C) 2023 Philippe Roy * @license: GNU GPL - * ******************************************************************************/ /****************************************************************************** diff --git a/labyrinthe/6-jumeaux/test/servo-test.py b/labyrinthe/6-jumeaux/test/servo-test.py new file mode 100644 index 0000000..8253dc4 --- /dev/null +++ b/labyrinthe/6-jumeaux/test/servo-test.py @@ -0,0 +1,29 @@ +import pyfirmata + +############################################################################### +# servo-test.py : +# @title: Test de pilotage d'un servomoteur par pyFirmata +# @project: Blender-EduTech - Tutoriel : Tutoriel 6 : Labyrinthe à bille - Développement de jumeau numérique +# @lang: fr +# @authors: Philippe Roy , Andre Nicolas +# @copyright: Copyright (C) 2023 Philippe Roy +# @license: GNU GPL +############################################################################### + +# Communication avec la carte Arduino +carte = pyfirmata.Arduino('COM3') # Windows +carte = pyfirmata.Arduino('/dev/ttyACM0') # GNU/Linux +print("Communication Carte Arduino établie") + +servo = board.get_pin('d:9:s') # Servo sur broche D9 + +try : + while True: # Boucle infinie + angle = int(input("Entrer un angle entre 10 et 170):")) # Demande à l’utilisateur d’entrer la valeur de l’angle + if angle < 10 : # Si la valeur entrée est inférieure à 10° on bloque le servo moteur à 10° + angle = 10 + elif angle > 170 : # Si la valeur entrée est supérieur à 170° on bloque le servo moteur à 170° + angle = 170 + servo.write(angle) # Ecrit cette valeur dans le pin du servo moteur +except : + carte.exit() diff --git a/labyrinthe/6-jumeaux/test/servo-test/servo-test.ino b/labyrinthe/6-jumeaux/test/servo-test/servo-test.ino index 1faf96b..826412b 100644 --- a/labyrinthe/6-jumeaux/test/servo-test/servo-test.ino +++ b/labyrinthe/6-jumeaux/test/servo-test/servo-test.ino @@ -1,25 +1,39 @@ -#include "servo.h" +#include "Servo.h" /****************************************************************************** * servo-test.ino - * @title: Programme pour la carte Arduino (2 servomoteurs) - * @project: Blender-EduTech - Tutoriel 6 : Labyrinthe à bille - Développer le jumeau numérique du labyrinthe + * @title: Test de pilotage d'un servomoteur + * @project: Blender-EduTech - Tutoriel 6 : Labyrinthe à bille - Développer le jumeau numérique du labyrinthe * @lang: fr * @authors: Philippe Roy * @copyright: Copyright (C) 2023 Philippe Roy * @license: GNU GPL - * ******************************************************************************/ +/****************************************************************************** +* Servo-moteurs +******************************************************************************/ + +Servo servo; +String servo_txt; +String servo_txt2; +bool servo_sens; +int angle_ms; + /****************************************************************************** * Initialisation ******************************************************************************/ void setup() { - // Liaison série - Serial.begin(115200); + // Liaison série + Serial.begin(115200); + // Servo-moteurs + servo.attach(9); // Servo sur broche D9 + servo_sens = true; + angle_ms = 1500; // Position centrale (90°, 500 -> 0° et 2500-> 180°) + servo.writeMicroseconds(angle_ms); } /****************************************************************************** @@ -27,4 +41,63 @@ void setup() { ******************************************************************************/ void loop() { + + // Affichage + servo_txt = String(servo.read()); + servo_txt2 = String(angle_ms); + Serial.print(servo_txt2); + Serial.print(" -> "); + Serial.print(servo_txt); + Serial.println("°"); + + // Sens + if (servo.read()==170) { + servo_sens=false; + } + if (servo.read()==10) { + servo_sens=true; + } + + // Mouvement + if (servo_sens) { + angle_ms=angle_ms+1; // Résolution à 180/2000 soit 0,09° + //servo1.write(servo1.read()+1); // Résolution à 1° + } else { + angle_ms=angle_ms-1; // Résolution à 180/2000 soit 0,09° + //servo1.write(servo1.read()-1); // Résolution à 1° + } + servo.writeMicroseconds(angle_ms); + delay(10); + + // Test des positions + /* angle_ms =1500; */ + /* servo.writeMicroseconds(angle_ms); */ + /* servo_txt = String(servo.read()); */ + /* servo_txt2 = String(angle_ms); */ + /* Serial.print(servo_txt2); */ + /* Serial.print(" -> "); */ + /* Serial.print(servo_txt); */ + /* Serial.println("°"); */ + /* delay(1000); */ + + /* angle_ms =500; */ + /* servo.writeMicroseconds(angle_ms); */ + /* servo_txt = String(servo.read()); */ + /* servo_txt2 = String(angle_ms); */ + /* Serial.print(servo_txt2); */ + /* Serial.print(" -> "); */ + /* Serial.print(servo_txt); */ + /* Serial.println("°"); */ + /* delay(1000); */ + + /* angle_ms =2500; */ + /* servo.writeMicroseconds(angle_ms); */ + /* servo_txt = String(servo.read()); */ + /* servo_txt2 = String(angle_ms); */ + /* Serial.print(servo_txt2); */ + /* Serial.print(" -> "); */ + /* Serial.print(servo_txt); */ + /* Serial.println("°"); */ + /* delay(1000); */ + }