0% found this document useful (0 votes)
11 views

Lesson 5b-Feedback Control With Arduino

Uploaded by

quanghieu.inamed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lesson 5b-Feedback Control With Arduino

Uploaded by

quanghieu.inamed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

• Demo to show the differences between open

loop and closed loop control including P, PI


and PID

Master Project – Month Year 1


International University Biomedical Engineering
VNU-HCMC Department

Implementing a digital PID


Controller on Arduino board
Prepared: Nguyễn Vũ Duy Hậu
Author Scientific Advisor(s) [email protected]
Contents

• Overview
• Implementation

• Conclusion
• Anatomy of Arduino,
• How does it work?
• Functions of Arduino
• System using Arduino (w or w/o laptop)
• How to use Arduino in the feedback control?

Master Project – Month Year 4


• Anatomy of Arduino,

Master Project – Month Year 5


Overview
Comparision

VS

About 75,000 VND Consume more time and money

Which one do you prefer for prototyping


and testing?
September 2016 6
• How does it work?
• Functions of Arduino

Master Project – Month Year 7


• System using Arduino (w or w/o laptop)

Master Project – Month Year 8


• How to use Arduino in the feedback control?

Master Project – Month Year 9


Master Project – Month Year 10
Overview
Our PID demo system in detail
Counterclockwise
Motor - Actuator
Clockwise

Arduino - Controller

Sensor - Angle

September 2016 11
Implementation
Control Actuator by PWM (Pulse Width Modulation)

Duty Cycle RPM Connect control signal to


100% or Always On ~ 2000
digital pin (2) of Arduino
50% ~ 1000
• digitalWrite(2, LOW);
10% ~200
• digitalWrite(2, HIGH);

September 2016
Implementation
Control Sensor

Connect sensor signal to analog pin (A7) of


Arduino
• analogRead(A7);
Arduino automatically convert analog signal
from sensor to digital signal range from 0 -
1023
Sensor voltage Digital value (VCC=5V)
5V 1023
2.5 512
0V 0

September 2016
Implementation
PID controller

September 2016
Implementation
One cycle of PID controller

• Arduino get the desired angle


1

• Arduino get the recent angle from sensor


2

• Arduino compute the PID control signal


3 and send to motor

• Arduino wait for the next cycle


4

The first
1st 2nd 3rd 4th …
cycle
Time domain Period
September 2016
Implementation
The important of period

Natural PID system cycle:


1. Get the desired color in brain
2. Check the recent color
3. Adjust the position

• Decide how quick the system


response
• Must be selected approriately
to ensure Tasks 1,2,3 must be
done
5 hours/cycle
5 seconds/cycle1st 5 miliseconds/cycle
2nd 3rd 4th …
Time domain Period
September 2016
Implementation
Proportional - P term

Consider the current


Decide how strong
error at the time of the
the system response
controller calculation

Max control signal: 360 degree


Min control signal: 0 degree
September 2016
Implementation
Proportional - P term
How to get 100km/h with P controller?
Cycle Setpoint Process Value Kp Control Signal
1 100 km/h 0 km/h 3 300 degree
2 100 km/h 200 km/h 3 - 300 degree
or 0 degree
3 100 km/h 50 km/h 3 150 degree
4 100 km/h 150 km/h 3 -150 degree or
0 degree

Cycle Setpoint Process Value Kp Control Signal


1 100 km/h 0 km/h 0.5 50 degree
↑ Kp: ↑ Oscillation
2 100 km/h 50 km/h 0.5 25 degree
↓ Kp: ↓ Oscilation
3 100 km/h 110 km/h 0.5 -5 degree or 0
but can not reach
degree the setpoint → need
4 100 km/h 90 km/h 0.5 5 degree Integral term

September 2016
Implementation
Proportional - P term

In each cycle process of Arduino:


error = Setpoint - ProcessVariable;
Pterm = Kp*error;

September 2016
Implementation
Integral - I term

Decide how strong


the system response

Consider the history of the error over time

P controller cannot reach setpoint

With I term sum up all small value


overtime → increase signal
control to reach the setpoint
September 2016
Implementation
Integral - I term
Cycle Setpoint Process Value Kp Control Signal
1 100 km/h 0 km/h 0.5 50 degree I term can add
2 100 km/h 50 km/h 0.5 25 degree more to control
3 100 km/h 110 km/h 0.5 -5 degree or 0
signal → > 5
degree degree
4 100 km/h 90 km/h 0.5 5 degree

This P controller cannot reach


setpoint
With I term sum up all small value
overtime → increase signal
control to reach the setpoint

September 2016
Implementation
Integral - I term

Approximate by Discrete Integral

At the begin: Iterm = 0; ↓ Ki: ↓ Oscilation but


too low or cannot
In each cycle process of Arduino: reach the setpoint
Iterm = Iterm + ↑ Ki: reach setpoint
but ↑ Oscillation →
(Ki*error*period); need Derivative term
September 2016
Implementation
Differential - D term

Decide how strong D


term against P, I terms
Try to predict process value change
then against/slow this change or
the control efforts of P, I terms

At the begin: LastError = 0;


In each cycle process of Arduino:
Dterm = Kd*(error-LastError)/period;
September 2016
Implementation
Differential - D term
At the begin: Iterm =
LastError = 0;
In each cycle process of Arduino:
• Pterm = Kp*error;
• Iterm = Iterm +
(Ki*error*period);
• Dterm = Kd*(error-
LastError)/period;

Time Error Last Error Pterm Iterm Dterm


20 8 0 Kp*8 90 Kd*8/period
30 1 8 Kp*1 130 Kd*(-7)/period
40 -2 1 Kp*(-2) 120 Kd*(-3)/period

September 2016
Implementation
Simple PID controller

September 2016
Conclusion
Summary characteristics of P,I,D
P term = 0; I term largest D term largest

P term I term D term

Look at the error Look at the history of Try to predict the


currently error overtime value error in the
future
Try to drive system to Try to drive system to Find the way to
reach the setpoint reach the setpoint against P and I efforts
P term The more process value Get very strong Largest effect when
closer to the setpoin, overtime, can help P the process is
largest; the more P term get term drive system to changing rapidly in
I term smaller then cannot reach setpoint and one direction and
=0 drive system to reach event make system disapper when system
the setpoint oscilation if Ki too stable at setpoint
large

September 2016
Conclusion
Summary characteristics of P,I,D

Closed-Loop Rise Time Overshoot Settling Time Steady-State error Stability


Response
Increasing Kp Decrease Increase Small Increase Decrease Degrade

Increasing Ki Small Decrease Increase Increase Large Decrease Degrade

Increasing Kd Small Decrease Decrease Decrease Minor Change Improve

September 2016
Master Project – Month Year 28

You might also like