SlidePub
Home
Categories
Login
Register
Home
General
Tutorial de programação scratch-controle-PID
Tutorial de programação scratch-controle-PID
ViniciusAndrade377192
21 views
22 slides
Sep 27, 2024
Slide
1
of 22
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
About This Presentation
PID Scratch Proportional I Detivative
Size:
1.98 MB
Language:
en
Added:
Sep 27, 2024
Slides:
22 pages
Slide Content
Slide 1
ADVANCED EV3
PROGRAMMING LESSON
EV3 Classroom:
PID Line Follower
Slide 2
ìLearn the limitations of proportional control
ìLearn what PID means
ìLearn how to program PID and how to tune
ìPrerequisites: Math Blocks, Color Sensor Calibration, Data Wires,
Variables, Proportional Control
We highly recommend knowledge of Algebra at a minimum. PID is a calculus-based concept and students should
understand why it is used and the math behind it before using it.
Please use Presentation Mode as there are lots of animations.
© 2020 EV3Lessons.com, Last edit 12/27/2019
Lesson Objectives
Slide 3
When does Proportional Control Have
Trouble?
What would a
human do?
On line àgo straight
On white àturn left
Moving across line àturn right
On white àturn left
Getting further from line à
turn even more!
What would proportional
control do?
On line àgo straight
On white àturn left
Moving across line àgo straight!
On white àturn left
Getting further from line àturn left the same amount!
© 2020 EV3Lessons.com, Last edit 12/27/2019
LIGHT READING = 50%100%
Slide 4
What would a
human do?
What would proportional
control do?
Turning left/on line àgo
straight!
Getting further from line
àturn left the same
amount!
© 2020 EV3Lessons.com, Last edit 12/27/2019
1. Predict what the next
sensor reading will be
2. Has past steering fixes
helped reduce error?
How can we fix Proportional Control?
Turning left/on line à
turn right
Getting further from line
àturn even more!
Slide 5
Integrals and Derivatives
•When the correction is working well, what does error readings look like?
•+5, -6, +4 -3…. i.e. bouncing around 0
•When steering is not working, what does error look like?
•+5, +5, +6, +5… i.e. always on one side of 0
•How can we detect this easily?
•Hint: look at the sum of all past errors
•What is an ideal value for this sum? What does it mean if the sum is large?
•Integral èthe “sum” of values
© 2020 EV3Lessons.com, Last edit 12/27/2019
1. Predict what the next sensor
reading will be?
2. Have past steering fixes
helped reduce error?
•If readings are: 75, 65, 55
àwhat do you think the
next reading will be?
•What if the readings
were 57, 56, 55…
•What information did you
use to guess?
•Derivative èthe rate at
which a value is changing
Slide 6
ìProportional [Error] àHow bad is the situation now?
ìIntegral àHave my past fixes helped fix things?
ìDerivative àHow is the situation changing?
ìPID control àcombine the error, integral and derivative values
to decide how to steer the robot
© 2020 EV3Lessons.com, Last edit 12/27/2019
What is PID?
Slide 7
ìSolid line represents what you have seen, dotted line is the future
ìAt time 20, you see light reading = 40 and error = -10 (red X)
© 2020 EV3Lessons.com, Last edit 12/27/2019
Error
-20
0
20
40
60
80
01020304050
Time (sec)
Error
-20
0
20
40
60
80
01020304050
Time (sec)
Light Intensity
Subtract
target (50)
Slide 8
ìLooks at past history of line
follower
ìSum of past error
ìLike area under the curve
in graph (integral)
ìGreen = positive area
ìRed = negative area
© 2020 EV3Lessons.com, Last edit 12/27/2019
Integral
-50
0
50
01020
Error
Time (sec)
0
100
200
01020
Integral
Time (sec)
Slide 9
ìHow quickly is position changing?
ìPredicts where the robot will be
in the immediate future
ìSame as how fast is error
changing
ìCan be measured using tangent line
to measurements àderivative
ìApproximated using two nearby
points on graph
© 2020 EV3Lessons.com, Last edit 12/27/2019
Derivative
-15
-5
5
15
102030
Error
Time (sec)
Tangent line
-5
0
5
10
102030
Derivative
Time (sec)
Slide 10
1.Take a new light sensor reading
2.Compute the “error”
3.Scale error to determine contribution to steering update (proportional control)
4.Use error to update integral (sum of all past errors)
5.Scale integral to determine contribution to steering update (integral control)
6.Use error to update derivative (difference from last error)
7.Scale derivative to determine contribution to steering update (derivative control)
8.Combine P, I, and D feedback and steer robot
© 2020 EV3Lessons.com, Last edit 12/27/2019
Pseudocode
Slide 11
ìThis is the same as the proportional control code
© 2020 EV3Lessons.com, Last edit 12/27/2019
Code -Proportional
Error = distance from line = reading -target
Correction (P_fix) = Error scaled by proportional constant (Kp) = 0.5
Slide 12
ìThis section calculates the integral. It adds the current error to
a variable that has the sum of all the previous errors.
ìThe scaling constant is usually small since Integral can be large
© 2020 EV3Lessons.com, Last edit 12/27/2019
Code -Integral
Integral = sum of all past errors = last integral + newest error
Correction (I_fix) = Integral scaled by proportional constant (Ki) = 0.01
Slide 13
ìThis section of code calculates the derivative. It subtracts the current
error from the past error to find the change in error.
© 2020 EV3Lessons.com, Last edit 12/27/2019
Code -Derivative
Derivative = rate of change of error = current error –last error
Correction (D_fix) = Derivative scaled by proportional constant (Kd) = 4.0
Slide 14
ìEach of the components have already been scaled. At this
point we can simply add them together.
© 2020 EV3Lessons.com, Last edit 12/27/2019
Putting it all Together
Add the three fixes for P, I, and D together. This will compute the final correction
Apply the correction the the steering of a move steering block
Slide 15
ìThis is what you get if you put all these parts together.
ìWe hope you now understand how PID works a bit better.
© 2020 EV3Lessons.com, Last edit 12/27/2019
Full Code
Proportional
Integral
Derivative
Putting it all Together
Slide 16
© 2020 EV3Lessons.com, Last edit 12/27/2019
Full Code
Proportional
Integral
Derivative
Putting it all Together
Set up the variables
for the last error and
integral before the
loop and initialize to 0
because they are read
before being written.
Slide 17
ìThe most common way to tune your PID constants is trial and error.
ìThis can take time. Here are some tips:
ìDisable everything but the proportional part (set the other constants to zero). Adjust just
the proportional constant until robot follows the line well.
ìThen, enable the integral and adjust until it provides good performance on a range of
lines.
ìFinally, enable the derivative and adjust until you are satisfied with the line following.
ìWhen enabling each segment, here are some good numbers to start with for the
constants:
ìP: 1.0 adjust by ±0.5 initially and ±0.1 for fine tuning
ìI: 0.05 adjust by ±0.01 initial and ±0.005 for fine tuning
ìD: 1.0 adjust by ±0.5 initially and ±0.1 for fine tuning
© 2020 EV3Lessons.com, Last edit 12/27/2019
Key Step: Tuning The PID constants
Slide 18
Evaluating Line followers
Proportional
ìUses the “P” in PID
ìMakes proportional turns
ìWorks well on both straight
and curved lines
ìGood for intermediate to
advanced teams àneed to
know math blocks and data
wires
PID
ìIt is better than proportional
control on a very curved line,
as the robot adapts to the
curviness
ìHowever, for FIRST LEGO
League, which mostly has
straight lines, proportional
control can be sufficient
© 2020 EV3Lessons.com, Last edit 12/27/2019
Slide 19
© 2020 EV3Lessons.com, Last edit 12/27/2019
Proportional Control (0.6 Constant)
Slide 20
© 2020 EV3Lessons.com, Last edit 12/27/2019
Proportional Control (0.8 Constant)
Slide 21
© 2020 EV3Lessons.com, Last edit 12/27/2019
PID Control
Slide 22
ìThis tutorial was created by Sanjay Seshan and Arvind Seshan
ìMore lessons at www.ev3lessons.com
© 2020 EV3Lessons.com, Last edit 12/27/2019
CREDITS
This work is licensed under aCreative Commons Attribution-
NonCommercial-ShareAlike4.0 International License.
Tags
Categories
General
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
21
Slides
22
Age
434 days
Related Slideshows
22
Pray For The Peace Of Jerusalem and You Will Prosper
RodolfoMoralesMarcuc
33 views
26
Don_t_Waste_Your_Life_God.....powerpoint
chalobrido8
36 views
31
VILLASUR_FACTORS_TO_CONSIDER_IN_PLATING_SALAD_10-13.pdf
JaiJai148317
33 views
14
Fertility awareness methods for women in the society
Isaiah47
30 views
35
Chapter 5 Arithmetic Functions Computer Organisation and Architecture
RitikSharma297999
29 views
5
syakira bhasa inggris (1) (1).pptx.......
ourcommunity56
30 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-22)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better