Video 1.8 - Discrete PID Controller - Implementation (Quadrator Example)

Video

#Physics #Engineering #Control_Theory #Robotics

↩️ Go Back

Table of Contents:


D) Discrete PID Control - Implementation: Quadrator Example

Now we have a useful general purpose controller, the PID regulator.

We saw how it can be used to make a cruise controller.

What we are missing now is how do we turn all these "mathematics" into "executable code"? How do we make it run on a platform?

Well, first let's remember that computers work in discrete time.
So they have a Sample Time Δ t

There is a certain Clock Frequency on the computer and we are sampling at a certain rate.

And what we have to do is take the continuous time PID regulator and have it defined in discrete time.

D.1) Discrete P-term

In continuous time we have,

and the discrete version is trivial, we just need to sample the error,

D.2) Discrete D-term

In continuous time we have,

And we know that the derivative of the error is roughly,

In fact, as Δ t (the sample time) goes to 0, this becomes the definition of the derivative limit,

And we also now that we can store in memory the “old error". This means we can sample a "new error”, compute the derivative and then store the "new error" as “old”. So this is a good approximation for e˙.

Furthermore, we can modify KD and include Δ t in the calculation, we will call it KD

Then, our controller will be,

D.3) Discrete I - term

In continuous time we have,

But, **what is the integral geometrically speaking?

And we can approximate this area with rectangles,

And now we write the sum of these rectangles as,

So after some time Δ t passes, and I want to calculate my new integral, I just need to add a new rectangle to the sum,

Conclusion:
To calculate the approximate integral we just need to compute,

Which can be broken down to,

Then, our discrete controller would be,

But we can modify KI and include Δ t in the calculation, we will call it KI

Then, our controller will be,

And we just need to update "Enew" every cycle,

D.4) Discrete PID Controller

So our discrete PID controller is,

Now let's put it into pseudo-code:

D.5) Quadrotor Altitude Control (demo)

Let's now implement this PID controller to control the altitude of a hovering quadrotor.

Quadrotor Altitude Control: What is the model for altitude Control?

Let's do a demonstration in the lab,

Let's see a PID regulator in action, right now with our rudimentary model of a quadrator we will do altitude control only.

Let's turn it on! We can see that the system is stable (it is not falling down to the ground).

It is drifting a little bit sideways because we are not controlling drift at all.

I can push it down a bit and the controller is able to overcome the load, therefore it is also robust.

In terms of tracking, we would have to see the data of our Ultrasonic Sensor which is measuring the altitude.


↩️ Go Back


Z) 🗃️ Glossary

File Definition

↩️ Go Back