Bonjour
Je cherche à contrôler un Pan / Tilt / Roll avec 3 servos commandés par une carte Arduino avec MPU6050.
Je trouve beaucoup de scripts sur internet pour Pan / Tilt.
Mais quand je teste, ça ressemble plus à du Roll / Tilt ... que du Pan / Tilt !
Dommage, je suis plus intéressé par le Pan que le Roll !
Par rapport à mon code ci dessous, quand je teste, j'ai :
Servo1 = ax ... pour le Tilt
Servo2 = ay ... pour le Pan ... mais pour moi ça réagit comme du Roll
Servo3 = az ... devrait le Roll
Comprenez vous ce qui ne va pas dans le code ci dessous ?
Merci pour votre aide.
#include <MPU6050.h>
#include <I2Cdev.h>
#include <Wire.h>
#include <Servo.h>
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
Servo servo1;
Servo servo2;
Servo servo3;
int val1;
int val2;
int val3;
int pval1;
int pval2;
int pval3;
void setup() {
Wire.begin();
Serial.begin(115200);
mpu.initialize();
servo1.attach(8);
servo2.attach(9);
servo3.attach(10);
}
void loop() {
mpu.getMotion6(&ax,&ay, &az, &gx, &gy, &gz);
val1= map(ax, -17000, 17000, 0, 179);
if (val1 != pval1){
servo1.write(val1);
pval1= val1;
}
val2= map(ay, -17000, 17000, 0, 179);
if (val2 != pval2){
servo2.write(val2);
pval2= val2;
}
val3= map(az, -17000, 17000, 0, 179);
if (val3 != pval3){
servo3.write(val3);
pval3= val3;
}
delay(5);
}