i recently made a stabilization system for my Rc Glider project. It uses only two servos X and Y and it has a problem when i tilt he gyro to left the servo arm turns left and when the gyro tilts right the servo arm turns right.i need to make this exactly opposite.so hes the code i use please help me with this
#include <Wire.h>
#include <Servo.h>
const int MPU=0x68; // I2C address of the MPU-6050
int16_t GyX, GyY; //Variabile int a 16bit
Servo ServoMot_X;
Servo ServoMot_Y;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
ServoMot_X.attach(8);
ServoMot_Y.attach(9);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true); // request a total of 14 registers
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)
int PosServo_X = map(GyX, -16000, 16000, 0, 179);
int PosServo_Y = map(GyY, -16000, 16000, 0, 179);
ServoMot_X.write(PosServo_X);
ServoMot_Y.write(PosServo_Y);
Serial.println("Giroscopio");
Serial.print("Asse X : "); Serial.println(PosServo_X);
Serial.print("Asse Y : "); Serial.println(PosServo_Y);
Serial.println(" ");
delay(100);
}