
Posted On: févr. 27, 2021
Seen by: 3506
Categories: ROBOTS
Author: Christian Joseph
Tags: robot , arduino , HC08 Bluetooth , MPU6050
Je vous présente le gant open-source Arduino que j'ai personnellement baptisé P.I.L.T(Play It Like Thanos / Joues la comme Thanos).
Bien entendu ce gant ne va pas vous permettre de remonter le temps (pour revivre un amour de jeunesse peut-être!) et encore moins d'éradiquer la moitié de l'univers...(Pas touche à belle-maman!), mais il vous rendra capable de commander vos robots au doigt et à l'oeil, grâce à son module Bluetooth HC-08 intégré: châssis mobiles, bras robots, robot quadrupèdes, hexapodes, etc...mais pas vos enfants!
1. PRESENTATION:
Le PILT est un gant mécanique Arduino muni d'un module accéléromètre gysroscope MPU6050 pour transmettre le mouvement de la main, et de 5 potentiomètres pour transmettre les mouvements des doigts.
Le PILT est basé sur une carte Arduino UNO, avec un connecteur USB pour la programmation du gant via l'IDE Arduino, ainsi que d'une batterie rechargeable et un bouton poussoir ON/OFF.
Le gant ne peut correspondre qu'avec un robot disposant d'un autre module HC-08. C'est la raison pour laquelle nous livrons le gant avec un module HC-08 supplémentaire, ce qui n'est pas le cas dans les autres plateformes où le gant est vendu. La synchronisation des modules HC-08 se fait de manière automatique dès la mise sous tension.
Le gant PILT dispose d'un bouton DEL qui permet de supprimer l'adresse du HC-08 secondaire enregistrée dans la mémoire du HC-08 du Gant et ainsi acter la désynchronisation des 2 modules, afin que le gant puisse se synchroniser avec un autre module HC-08. Tout est expliqué dans notre notice d'utilisation livrée avec le gant.
2.PROGRAMMATION:
Dans l'IDE Arduino, il faut sélectionner la carte Arduino UNO et connecter le gant à votre PC via son connecteur mini-USB.
/*Projet: PILT - PLAY IT LIKE THANOS
* Auteur: Christian Joseph
* Date:15.08.2019
* www.eagle-robotics.com
*/
#include "Wire.h"
#include "Servo.h"
#include "SoftwareSerial.h"
#define BTH_RX 11
#define BTH_TX 12
const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
double x; double y; double z;
int minVal=265; int maxVal=402;
char a;
SoftwareSerial Bth(BTH_RX, BTH_TX);
void setup(){
// INIT POTENTIOMETRES DOIGTS
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A6, INPUT);
//INIT MPU6050
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
//INIT MODULE HC08 EN MODE MAITRE
Bth.begin(9600);
Bth.print("AT+ROLE=M"); //
delay(100);
Bth.print("AT+RESET"); //
delay(250);
}
void loop(){
//VARIABLE DE LECTURE ETAT POTENTIOMETRES
int val = analogRead(A0);
int val1 = analogRead(A1);
int val2 = analogRead(A2);
int val3 = analogRead(A3);
int val4 = analogRead(A6);
//LECTURE POTENTIOMETRES ; les paramètres 2500 et 500 sont à modifier selon le gant
//de sorte à avoir les données val à val4 autour de 2000
//Si valeur < 2000 = doigt plié et si valeur > 2000 = doigt tendu
val = map(analogRead(A0), 0, 150, 2500, 500);
val1 = map(analogRead(A1), 0, 150, 2500, 500);
val2 = map(analogRead(A2), 0, 150, 2500, 500);
val3 = map(analogRead(A3), 0, 150, 2500, 500);
val4 = map(analogRead(A6), 0, 100, 2500, 500);
Serial.println(val);
Serial.println(val1);
Serial.println(val2);
Serial.println(val3);
Serial.println(val4);
Serial.println(" ");
if (val1 < 2000 && val2 < 2000 && val3 < 2000 && val4 < 2000){ //Tous les doigts repliés, poing fermé
Serial.println("mode g/d active"); // activation mode tourner à gauche ou à droite
if (y > 260 && y < 320){
Serial.println("gauche"); // Main penchée à gauche - Le robot tourne à gauche
Bth.write('d');
while(y > 260 && y < 320){
delay(1);
pos();
}
Serial.println("exit de gauche");
Bth.write('s');
}
else if (y > 40 && y < 130){
Serial.println("droite"); // Main penchée à droite - Le robot tourne à droite
Bth.write('c');
while(y > 40 && y < 130){
delay(1);
pos();
}
Serial.println("exit de droite");
Bth.write('s');
}
}
else if (val1 > 2000 && val2 > 2000 && val3 < 2000 && val4 < 2000){ //index et majeur tendus, autres doigts pliés
Serial.println("mode m/a active"); // activation mode marche avant et arrière
if (x > 0 && x < 80){
Serial.println("avant"); // Main penchée en avant - Le robot avance
Bth.write('f');
while(x > 0 && x < 80){
delay(1);
pos();
}
Serial.println("exit de avant");
Bth.write('s');
}
else if (x > 270 && x < 315){
Serial.println("arriere"); // Main penchée en arrière - Le robot fait marche arrière
Bth.write('b');
while(x > 270 && x < 315){
delay(1);
pos();
}
Serial.println("exit de arriere");
Bth.write('s');
}
}
else if (val1 > 2000 && val2 > 2000 && val3 > 2000 && val4 > 2000){
Serial.println("mode stop active");
Bth.write('x');
}
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
int xAng = map(AcX,minVal,maxVal,-90,90); int yAng = map(AcY,minVal,maxVal,-90,90); int zAng = map(AcZ,minVal,maxVal,-90,90);
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI); z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
Serial.print("AngleX= "); Serial.println(x);
Serial.print("AngleY= "); Serial.println(y);
Serial.print("AngleZ= "); Serial.println(z); Serial.println("-----------------------------------------");
}
void pos(){
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
/*Serial.print("AcX = "); Serial.print(AcX); //Accéléromètre X
Serial.print(" | AcY = "); Serial.print(AcY); //Accéléromètre Y
Serial.print(" | AcZ = "); Serial.print(AcZ); //Accéléromètre Z
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //Température
Serial.print(" | GyX = "); Serial.print(GyX); // Gyroscope X
Serial.print(" | GyY = "); Serial.print(GyY); // Gyroscope Y
Serial.print(" | GyZ = "); Serial.println(GyZ); // Gyroscope Z
*/
int xAng = map(AcX,minVal,maxVal,-90,90); int yAng = map(AcY,minVal,maxVal,-90,90); int zAng = map(AcZ,minVal,maxVal,-90,90);
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI); z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
} //Fin du programme
#include
SoftwareSerial BT (2,3);
char a;
void setup()
{ Serial.begin(9600);
BT.begin(9600);
}
void loop()
{
if (BT.available())
{
a=(BT.read());
if (a=='f')
{
while(a != 's'){
a = (BT.read());
Serial.println("Robot en avant");
}
}
else if (a=='b')
{
while(a != 's'){
a = (Serial.read());
Serial.println("Robot en arrière");
}
}
else if (a=='c')
{
while(a != 's'){
a = (Serial.read());
Serial.println("Robot à droite");
}
}
else if (a=='d')
{
while(a != 's'){
a = (Serial.read());
Serial.println("Robot à gauche");
}
}
Il s'agit ici d'un programme exemple, et il est tout à fait possible de programmer le gant selon le positionnement des doigts et où l'inclinaison de la main souhaité.
Pour toutes questions, vous avez projet@eagle-robotics.com. Ils ne vous aideront toujours pas pour belle-maman, mais pour le fonctionnement du gant avec votre robot ils sont très compétents.