# Quadcopter PID Controller for distance

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?