I am building an Arduino based flight controller for a quadcopter and have got it flying but it is not performing how I want it to. The drone is flying but when I release the sticks the drone does not stay perfectly still. There is some random and small oscillations that occur when it is just hovering.
Right now I am using a single PID controller for each axis though functions like this.
dt=0.005;
error = *in - *set;
P = (error * kp);
I = I + (error * ki)*dt;
D_M = ((*in - in1)*kd)/dt;
D_E = ((error - error1)*kd)/dt;
D=D_M*(1-jerk) + D_E*(jerk);
I = constrain(I, LOWER_BOUND*0.75, UPPER_BOUND*0.75);
in1 = *in;
error1 = error;
pid = P + I + D;
pid = constrain(pid, LOWER_BOUND, UPPER_BOUND);
*out = pid;
The error is the Euler angle and the setpoint is the angle I want it to go to.
I then output the PID controller values to the motors using the Arudino Servo library.
motor1 = throttle;
motor2 = throttle;
motor3 = throttle;
motor4 = throttle;
motor1 += rollOUT;
motor2 += rollOUT;
motor3 -= rollOUT;
motor4 -= rollOUT;
motor1 -= pitchOUT;
motor2 += pitchOUT;
motor3 -= pitchOUT;
motor4 += pitchOUT;
motor1 += yawOUT;
motor2 -= yawOUT;
motor3 -= yawOUT;
motor4 += yawOUT;
Is there something I am missing about quadcopter PID controllers? Thank you for the help!
kd
relative to the measurement error. Maybe the measurement error noise is significant enough that multiplying its derivative by your200*kd
factor is enough to bump the system.