So, how do we get rid of these oscillations?
The key is to add one more term to our controller equation.
And remember, for the purposes of this lesson,
the controller sets a commanded acceleration.
So, in addition to setting acceleration in proportion to the error,
we also look at the rate of change,
or derivative of the error.
And the subscript d here stands for derivative.
And this equation is the equation for a PD or proportional derivative controller.
The intuition behind this d term is pretty straightforward.
While the p term is responsible for adjusting the thrust
so that the vehicle's position matches the target position,
the d term is responsible for adjusting the thrust,
so that the vehicle's velocity matches the target velocity.
So, when the vehicle is rapidly ascending towards this target set,
this term will oppose this rapid decrease in the size of the error,
and will cause the vehicle to slow down as it's approaching the target altitude.
To implement this in code,
recall how we've defined error.
This means that the derivative of error is
just the difference between the target speed and the actual speed.