Smooth servo movements

Hey guys,

I made a Gimbal (camera stabilizer) with an Arduino Uno and MPU6050 gyro sensor. I read the values from the MPU6050 and write it to the servos. The values are really exact so I get every movement. The values go from 0 to 180 so we can write them on the servo directly. My problem is that I get values like 83, 91, 85 so it's always moving forward and backwards and because of this it's very instable. Anyone got an idea how to make it move smoother?

Thanks

For the accelerator: Use a filer. Either the Kalman filter or the i2cdev library. http://forum.arduino.cc/index.php?topic=58048.0 For the stepper motor : The accelstepper library speeds up smooth. http://www.airspayce.com/mikem/arduino/AccelStepper/

Hi,

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom… :slight_smile:

I’ll try this thanks!

Here’s the code

#include<Wire.h>
#include <Servo.h> 
const int MPU=0x68;  // I2C address vom MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
Servo myservo;

int pos, distance;

int i=0;



void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // 0 setzen, sleep mode vom sensor wird deaktiviert
  Wire.endTransmission(true);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  myservo.attach(9);
//  myservoX.attach(8);

}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // mit 0x3B register beginnen(ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,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)



//Y
  pos = (AcY/200)+85;

 
  if(pos <1){
    pos = 1;
  }
  
  if(pos>90){
    distance = pos -90;
    pos = 90-distance;
  }
  else if(pos <90){
   distance = 90-pos;
   pos = 90 + distance; 
  }
  


  Serial.println(pos);


  myservo.write(pos);

  delay(3);
}

That won't work. Every accelerometer is noisy. I suggest to start with the Kalman Guide.

You have to understand how to build a 6-DoF IMU from 3-axis gyro and accelerometer first - this is a requirement for orientation feedback. Accelerometer by itself is almost useless, and gyro output drifts. The accelerometer is purely used to eliminate the drift, not give orientation directly in the short term.

Since you have a 6050 you can just get the quarternion out of it directly surely?