1
$\begingroup$

I am trying to use a PID controller to stop a quadcopter at a specific location while travelling horizontally, however currently it overshoots/undershoots depending on the max velocity. I have tried manually tuning the P,I and D gains with limited success. Essentially the velocity needs to go from maxSpeed to 0 at the very end of the flight path.

It uses the DJI SDK so the inputs to the quadcopter are very simplistic, the pitch input to the quadcopter is in m/s and I recalculate the distance(m) to the target on each iteration.

I run a loop that executes every 0.1 of a second. Some pseudo code:

kP = 0.25
kI = 0.50
kD = 90
timeStep = 0.1
maxSpeed = 10

currentError = initialDistanceToLocation - currentDistanceToLocation
derivativeError = (currentError - previousError) / timeStep
previousError = currentError
output = kP * currentError + kI * integralError + kD * derivativeError
integralError = integralError + currentError * timeStep

if >= maxSpeed {
    output = maxSpeed
} else if output <= 0 {
    output = 0
}
return output

Is there a way to reliably tune this PID controller to this system that will work for different max velocities, or is it too simplistic and there are other factors I need to consider?

$\endgroup$
1
$\begingroup$

If you want to work with higher velocities, you need to look into velocity controller as well. You can also try incorporating velocity control into your control system. It enables smooth stopping to point which can alleviate your problem. But a generic PID controller with just position control should not overshoot too much if tuned correctly and the maximum velocities aren't too high.

| improve this answer | |
$\endgroup$
-1
$\begingroup$

The posted sourcecode measures the current system state and then the control action is determined. Even if the calculation is done 10 times per second it is based on a single measurement in the now. The desired behavior to stop the quadcopter smoothly and avoid overshooting is a multi-stage problem. Multi state means, that more than a single decision and measurement are required. In the simplest case, the source code has to be extended with a second input value, so that the equation takes t and t-1 as input.

From an implementation perspective the architecture has a lot of common with using a recurrent neural network and a pid controller together. This helps to improve the quality of the control actions.

| improve this answer | |
$\endgroup$
  • $\begingroup$ The solution used values from t-1 as input. the derivative term is calculated as the difference between the current error and the previous error. The previous error is coming from t-1. The advice to use recurrent neural networks is interesting, but it is not sufficiently explained, how such a network can be used, what are its inputs and outputs and how to obtain a dataset to train it. $\endgroup$ – 50k4 Nov 2 at 16:27

Your Answer

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

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