2

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!

3
  • Are the disturbances due to external effects (wind and turbulence)? Do they occur in still air, such as in a quiet indoor environment? In other words, can you tell whether the PID controller is the source of the problem or is just less-than-perfect at overcoming external forces? A feedback controller depends on the error-signal as its source of information, so by definition, it can never do a perfect job. If it could, its source of information would go to zero, i.e., it would "blind" itself. – JRobert Mar 3 '19 at 15:10
  • @JRobert I am flying indoor with no outside disturbance. The quad flys and stays extremely steady for about 2 seconds and then these small but random "bumps" make itnwobble before it steadies out again. I've read that some people use angular rates instead of angles? Is that common? And if so how do I know the angular rate to set it at with a certain error? – M.Schindler Mar 3 '19 at 16:36
  • I'm beyond my knowledge here (no drone experience), but I have to wonder about the "steady - wobble - steady again" cycles, especially if they are regular. Something seems to be disturbing it - software, electronic, atmospheric - especially since it seems very capable of holding steady, even if its only for short periods. It might be interesting (but challenging ): to log some raw sensor data and look for corresponding noise or other displacements. – JRobert Mar 3 '19 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.