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!

4
  • 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, 2019 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? Mar 3, 2019 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, 2019 at 17:05
  • Check kd relative to the measurement error. Maybe the measurement error noise is significant enough that multiplying its derivative by your 200*kd factor is enough to bump the system.
    – Dave X
    Oct 30, 2021 at 17:51

1 Answer 1

2

I'd suggest setting Kd to zero, Kp to a minimal value and letting the integral alone function as the controller. Any response to an error might be slow but the integrator alone will control a process with zero error. After observing the response of the integral for a period of time, hopefully without the problem you referenced, gradually introduce proportional control and watch for the periodic instability. If increasing the proportional gain results in oscillation, reduce the proportional back to a stable value and gradually introduce more derivative gain. I have worked with PID throughout my career and the instability you described sounds like something I'd expect to see originating from the derivative control action. No sensor is perfectly noise free and even if the noise is low amplitude, the rate of change may still be fairly large which will result in a very obvious periodic instability in the flight of your drone.

If this is the case, finding the source of the induced noise may not be easy. Perhaps reducing the derivative gain and using mostly proportional and integral control will effectively filter and attenuate the instability you're noticing. Good luck.

2
  • 1
    "Good luck." It's difficult to say, being four years later, whether or not they'll get that. I'll vote it up for the effort and that someone may find it useful.
    – timemage
    Jul 12 at 1:46
  • I saw it was dated 2019 but thought the reply might benefit others struggling with debugging PID control and tuning issues. Isolating PID related operational perturbations is a fairly common event in a number of industries well outside of drones. - JL Jul 13 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.