gimbal kamera yapıyorım ardiuno uno r3 mpu6050 3 ad servo malzemeler bunlar int indirdiğim kodlar aşağıda iyi çalışıyor ancak 2 akis 3 akis çalışması lazım uğraştım olmadı yardımcı olan arkadaşlara teşekkür ederim
// 2 axis 2 servo conrol using mpu 6050 #include <SPI.h> #include <Wire.h> #include <Servo.h> #define MPU 0x68 // I2C address of the MPU-6050
Servo ServoX, ServoY; double AcX,AcY,AcZ; int Pitch, Roll;
void init_MPU(){ 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); delay(1000); }
//Pitch and Roll double FunctionsPitchRoll(double A, double B, double C){ double DatoA, DatoB, Value; DatoA = A; DatoB = (B*B) + (C*C); DatoB = sqrt(DatoB);
Value = atan2(DatoA, DatoB); Value = Value * 180/3.14;
// 2 axis 2 servo conrol using mpu 6050
#include <SPI.h>
#include <Wire.h>
#include <Servo.h>
#define MPU 0x68 // I2C address of the MPU-6050
Servo ServoX, ServoY;
double AcX,AcY,AcZ;
int Pitch, Roll;
void setup(){
Serial.begin(9600);
ServoX.attach(9);
ServoY.attach(10);
init_MPU(); // Initialisation of MPU6050
}
void loop()
{
FunctionsMPU(); // acquire Axis AcX, AcY, AcZ.
Roll = FunctionsPitchRoll(AcX, AcY, AcZ); // Roll
Pitch = FunctionsPitchRoll(AcY, AcX, AcZ); // Pitch
int ServoRoll = map(Roll, -90, 90, 0, 179);
int ServoPitch = map(Pitch, -90, 90, 179, 0);
ServoX.write(ServoRoll);
ServoY.write(ServoPitch);
Serial.print("Pitch: "); Serial.print(Pitch);
Serial.print("\t");
Serial.print("Roll: "); Serial.print(Roll);
Serial.print("\n");
}
void init_MPU(){
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);
delay(1000);
}
//Pitch and Roll
double FunctionsPitchRoll(double A, double B, double C){
double DatoA, DatoB, Value;
DatoA = A;
DatoB = (B*B) + (C*C);
DatoB = sqrt(DatoB);
Value = atan2(DatoA, DatoB);
Value = Value * 180/3.14;
return (int)Value;
}
//axis X,Y,Z MPU6050
void FunctionsMPU(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,6,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(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
}
DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.
Üye Ol Şimdi DeğilÜye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.