IoT2x Module 4 PID Activity

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

IoT2x Module 4 Activity – PID Control

We have previously looked at the difference between open-loop and closed-loop systems and how
the feedback from a sensor can help us to maintain automated control. The video used a motor with
a rotary encoder and an Arduino controller to demonstrate how a closed-loop system can maintain
the intended speed of a motor despite external influences such as a changing load.

Here are some terms used in control systems, and their definitions:

Set Point – This is the desired outcome of the control system at any moment. In the video it was set
by the position on the dial, or potentiometer. The dial may have been marked with a scale from 0 to
125RPM. In a heating system this may be the temperature setting on a thermostat or for a driverless
car this may be the direction the car should be turned towards.

Process Variable – This is the actual outcome which can be observed or which can be measured by
sensors. In the video it was the speed that the motor was moving as measured by the rotary
encoder. In a heating system it would be the actual temperature measured by a temperature sensor
and for a driverless car it could be the direction the car is actually moving.

Error – In this context, the error is the difference between the process variable and the set point.

Whenever any error needs to be corrected so that the process variable matches the set point it
would be ideal if the process variable was able to respond and adjust instantly. In reality, there will
be some sort of delay to consider while things change. In the example of the motor being started, it
cannot go from 0 to 125RPM in an instant due to inertia. Neither can a heater raise air temperature
by 10 degrees or a car change from a left to a right turn instantly. In all cases, if the error is corrected
too fast, then the process variable may overshoot the set point, creating error in the opposite
direction. If error is corrected too slowly then the system may be useless for the purpose, such as a
driverless car that is too slow to respond to a corner.

PID controllers can be fine-tuned for the ideal response to correcting an error, based on the context
of the particular system. PID uses a combination of Proportional, Integral and Derivative actions to
respond to the error.

We will use an online simulator to demonstrate each part of a PID controller.

IOT2x IoT Sensors and Devices - Module 4 – PID Activity


View a Simulated PID Controller

Click the link or copy and paste into a browser to open a website.

http://www.rentanadviser.com/en/pid-fuzzy-logic/pid-fuzzy-logic.aspx

You will see an online PID controller simulator. Below is a screen-captured image from the website

You can see that this image represents a closed-loop controller. There are 5 different values that can
be changed:

dt – represents the sampling rate for the process variable. Leave this unchanged at 0.1

R(t) – this is used to adjust the set point, which can vary between 0 and 10000 units but
defaults to 400. In keeping with our motor example, let’s assume this number represents
revolutions per minute, or RPM. It can be adjusted by typing in a new value, clicking the up
and down arrows or by clicking and dragging the slider labelled RT below the diagram

Kp – the first value which can be adjusted in the controller adjusts the proportional response

Ki – this value adjusts the controller’s integral response

Kd – this value adjusts the controller’s derivative response

Two more readings to take notice of are Y(t) which is the resulting process variable value, or the
motor’s actual speed in our example, and E(t), which is the error calculated.

IOT2x IoT Sensors and Devices - Module 4 – PID Activity


Proportional Response
1. Leave the R(t) – set point at the default of 400 and dt (sampling rate) at default of 0.1
(seconds)

2. Adjust the Kp to 0.1.

3. Adjust the Ki and Kd to 0.0 so that there is only a very small proportional control and no
integral or derivative.

4. Start a “Realtime” simulation by clicking the link “Plot Realtime (P,I,PI,PID)”

You will see a live graph appear which represents time in seconds on the horizontal axis. The
numbers on the vertical axis may represent RPM for our example.

➢ The red plot line represents the set point R(t).


➢ The green plot line represents error E(t).
➢ The blue plot line represents the process variable Y(t).

Proportional control works by looking at the error at any moment and producing an output in
proportion to that error, multiplied by the gain (Kp). Therefore, the moment you started the
simulation, the motor was stopped (at 0 RPM), the set point was 400 so the error was also 400. This
error was multiplied by a Kp of 0.1 (40 RPM) and the controller adjusted accordingly. This process is
being calculated and done 10 times each second (dt = 0.1) and error correction is reduced each time.

5. Click “Plot Realtime” again and notice how long it takes until the green plot and the error
reading E(t) can be rounded to 0.00.

By this method, the error can never be completely reduced to 0 but will always be fractionally
different to the set point at best, even if it is very close to zero. This is known as “steady state error”
and in real life is often greater than this particular simulation can show.

6. To exaggerate the steady state error, adjust Kp to 0.01 by clicking and typing the new value.

7. Click “Plot Realtime” again and notice how long it would take to arrive at the set point.

8. Change Kp to 1 and begin the simulation by clicking “Plot Realtime”. (Ki and Kd should still be
at 0.0.)

You will notice that the set point is achieved in around 1 second with negligible steady state error. In
some applications, a proportional response like this by a controller is adequate and it would be all
that is needed.

9. The slider below the diagram labelled RT allows you to click and drag the set point. Click to
move this up to its maximum setting of 10000 and try changing it to many other settings. Try
moving it both slowly and fast and observe the response.

You might wonder why you can’t just increase the proportional gain until the response is fast
enough to suit requirements. Next, we will see the effects of increasing Kp even further.

IOT2x IoT Sensors and Devices - Module 4 – PID Activity


10. Increase the Kp to 2.0.

11. Make sure R(t) is anywhere above 0 and click “Plot Realtime” again.

12. Try a few changes on the RT slider by moving the set point both slowly and fast.

You will notice a small overshoot. The process variable increased towards the set point so fast that it
went past it and had to be adjusted for negative error before reaching the set point.

13. Change Kp to 3.0 and repeat steps 11 and 12.

This time the overshoot is over-corrected so that there are oscillations. They will settle, but looking
at the E(t) window will give indications of ongoing small ripples with fractional error.

14. Change Kp to 4.0 and repeat steps 11 and 12.. Observe the effects of too much proportional
gain.

Integral Response
Where proportional response considers how large the error is, integral response integrates the error
over a period of time until it becomes zero. It uses the sum of the error reading at every sample
point to work out a mean value, effectively adjusting controller output based on the past error.

1. Refresh your web browser page so that the R(t) value returns to its default value of 400.

2. Adjust Kp to 0.0, Ki to 0.1 and adjust Kd at 0.0.

3. Click the “Plot Realtime” button to start the simulation.

You will notice that the process variable heads towards the set point at a much slower rate than it
did for the same value of Kp. It would take several minutes to achieve zero error at this rate.

4. Increase Ki to 5.0 and click “Plot Realtime”.

The error is reduced faster with this much integral gain and it can reach the set point without the
steady state error of a proportional controller. (Note: steady state error is difficult to view on this
particular simulator.)

5. Try increasing Ki to 10.0, 15.0 25.0 and 30.0 and move the RT slider around to change the set
point in each case. Notice the response and when oscillations start to occur.

Proportional and Integral Combined


The problem with using just integral control is that it must build up some time with error states
before it can accurately respond to the error. Increasing the gain helps it to respond faster but this
can also cause it to overcorrect and lead to oscillations.

IOT2x IoT Sensors and Devices - Module 4 – PID Activity


Proportional control can instantly respond to a large error but it has difficulty eliminating steady
state error because it finds that small errors are hard to reduce completely to zero. Combining the
two types of controllers requires some fine-tuning but can create a response closer to ideal than
each on their own.

1. Make sure the set point R(t) is at 400 and refresh the page if not.

2. Set Kp to 0.5, Ki to 0.0 and Kd to 0.0.

3. Start the simulator by clicking “Plot Realtime” and observe the response.

4. Now set Kp to 0.0, set Ki to 2.0 and leave Kd at 0.0.

5. Start the simulator by clicking “Plot Realtime” and observe the response.

6. Now increase Kp back to 0.5 and leave the other two values where they were.

7. Start the simulator by clicking “Plot Realtime” and observe the response.

You will notice that this much integral gain on its own takes around 9 seconds to get to zero. This
much proportional gain on its own takes more than 2 seconds. Combining the two lets the error zero
out much faster, in less than 1 second. The integral component means that steady state error is
eliminated.

Derivative Response
A derivative controller looks at the derivative of the process variable, or the rate of change. In this
way it can help to anticipate future change required based on current movement and create a more
accurate response by the controller. Unlike proportional and integral, derivative control cannot be
used on its own.

1. Leave Kp on 0.5 and Ki on 2.0. Adjust Kd to 0.1.

2. Start the simulator by clicking “Plot Realtime” and observe the response.

3. Move the RT slider around to see responses to a change in set point.

You will now see that the set point is reached and the error is zero in only a fraction of a second with
the same proportional and integral parameters as before. The process variable responds very fast
and accurately in relation to the changing set point.

4. Increase the Kd value and watch the response to a changing set point.

A disadvantage with combining proportional, integral and derivative responses to make a PID
controller is that it is far more complex to fine-tune than a P, I or PI controller would be. Getting the
correct balance requires extensive trial and error or a very detailed mathematical analysis.

Applying this to the real world control examples used, you could imagine that steady state error and
oscillations are undesirable in a motor or temperature controller and may even be very dangerous in
a steering controller in a driverless car.

IOT2x IoT Sensors and Devices - Module 4 – PID Activity

You might also like