Dear viewer, these subtitles were generated by a machine via the service YouTube and therefore are (very) buggy. If you are capable, please help us to create good quality subtitles: https://c3subtitles.de/talk/2646 Thanks!
[Music]
uh the next talk is going to be by uh OT
Williams the editorinchief of
hackaday.com he's especially interested
in bringing hardware and software people
together so uh to make the the step from
software to Hardware a little bit easier
he's going to tell you about uh one
aspect of of Hardware to make this uh a
lot easier for for Hardware people thank
you hey everybody thank you uh this
Talk's going to be P control all the
things and that's proportional integral
and derivative and that sounds scary but
it turns out to be something that you
need to know if you want to control any
sort of system and this is a weird old
Theory comes out of the 1920s I think
they were originally looking at
controlling complex chemical
manufacturing plants and things like
that but these days P control loops run
everything from like quadcopters to the
hotend on your 3D
printer um all sorts of kind of hacker
accessible devices instead and the point
is you want to be able to maybe hover at
a certain height or hold
your uh hot end at a certain temperature
or you have a sid cooker and you want it
to hold a certain temperature for a few
days and you want to be hyper precise
this is what lets you do that and it's
actually really simple again the theory
is way old um back to the 1920s and I
won't be showing you anything that's
particularly new here I'm just going to
step you through it as easily as I
possible possibly can because I don't
know if you're a mechanical engineer
this ends up being like a half year year
course and they do it in a very fancy
and formalized way and I'm just going to
show you what you need to know to get 20
lines of code working to make something
stupid like this hover at a given height
okay um the algorithm itself is really
simple the math is very easy
tuning PID control loops is known to be
black magic in the industry and it's
because it's kind of an IL defined
problem the goal is I want to get and
the and I'm going to be using this as an
example today it's on propeller on a
hinge the goal today is going to be get
this to hover right here and when I hit
it it's going to go back to hovering
right here it behaves like a quadcopter
one motor unic opter
um getting it so that it can do this you
know from a dead start up to here and
resist me pushing how hard how far how
fast is this fast as possible these are
all questions that are specific to this
particular problem and if this is like a
chemical manufacturing plant how fast
can I heat up this 20 ton boiler is a
different thing and this is what makes
tuning PID control loops hard is that
you're always dealing with different
systems even though you're applying kind
of the same basic
math um so like I said this could be
self-balancing scooters a coffee roaster
your printer a quad let's talk some
quick terminology and this is going to
dive as far as I'm going to go into the
engineering world the process variable
is what you care about controlling and
here it's going to be like the hover
height of this
monocopter but you could think if you
had a self-balancing scooter it's going
to be the balance angle or if you have a
coffee roaster it's going to be the
roast rate or the temperature in a s
controller the idea is that you have
some variable measurable thing that you
want to control and that's going to be
your set point and then you want to
figure out how far away the current
situation is from that goal and that's
going to give us the error so process
variable Seto error and you know our
goal is to get the error to zero as fast
as possible and STA and controllably and
without breaking
stuff so this example I actually ripped
off of a guy in Brazil named Clovis
fritsen uh it turns out I wrote the
article I went back and looked at it on
hackaday oop well there you go no
internet um I went back and looked at
the article it turns out I wrote it it
was pretty fun um he did exactly this
except he did a lightweight version of
this he had a much smaller motor and a a
skewer stick and I just thought it was
such a great example um so I've ripped
it off for you I made this last week
um this is basically a motor and a
propeller on the end of a stick uh let's
see if I turn it around you can see a
motor speed controller this takes a pwm
value and turns it into the right 3phase
commutation to make this DC motor spin a
battery just cuz I don't know thing
needs a battery uh it's connected to an
esp32 here is a potentiometer that is
hot glued to this bolt on a pivot here
so it actually reads the
potentiometer figures out at what angle
it is basically reads an a analog
voltage off that thing and that's what
we're actually going to control so in
terms of PID world the process variable
here the variable we want to control is
going to
be uh
the ADC value I mean kind of indirectly
it's the ADC value we're measuring off
this potentiometer this PO geometer is
measuring this angle so you know which
one is the end goal we'll work on later
um this is all done with the like I said
an esp32 and in micropython
definitely important is the safety
popsicle stick here glued on the back
that prevents this from going over
vertical this is actually safety
popsicle stick Mark
2 rip safety popsicle stick
one um that was fun if you turn the
motor on full of course it goes and you
know breaks this threatens to undo the
hot glue that's in here and flies on the
floor safety popsicle stick Saved My
Life um so this is
our uh this is our process variable is
the ADC reading off this the analog to
digital converter reading off this
potentiometer it's a you know a turny
thing um stands in for the height our
control variable that is how we're going
to control the system is going to be a
percentage of pulse width modulation
signal sent to the motor controller that
then makes this turn faster or slower
now this is kind of a weird chain of
things and it's going to mean a lot for
implementation here I'll talk about that
in a sec um our Control Function is
we're going to read in the data off the
potentiometer the angle and we're going
to Output a throttle very easy but there
are nonlinear things everywhere here
this propeller spins faster it puts out
more thrust it raises this up but the
amount of thrust it puts out more varies
with how fast it's already spinning and
probably the angle it's at you know cuz
you're talking about the vertical
component of the thrust I mean there's
all sorts of weird stuff going on just
with this motor it's a heavy cheap
Chinese motor it spins up really slowly
it's actually meant for airplanes not
for quadcopters I
mean trouble here
um going from the kind of linear 0 to
100% pwm into the power sent to the
motor is also nonlinear like there's all
sorts of stuff I don't know about here
and that's something we have to figure
out the other thing that's particularly
interesting about the system is that
when the motor's off it falls down um
and the motor can't spin backwards with
this particular motor so when this
thing's too high the only thing we can
do is spin the motor motor slower or
apply less power to it so it eventually
drops down meaning it can only drop down
with the force of gravity when we want
to go up this motor is really beefy it
can torque way up and pull up with 4G or
something I don't even know so it's
asymmetric around our what we want it to
stay at around our equilibrium point so
that's going to be fun too so this is
kind of a worst case scenario and that's
why I'm presenting it to you today CU it
can show us everything that can go wrong
so now let's talk theory real quick we
got proportional integral and derivative
these are going to be three numbers that
we're going to calculate and input back
into the throttle here so we take this
error which is the value of the ADC off
the potentiometer so it's a voltage and
we have an idea of what we want and I
held this up here earlier and it said
three
305 so I typed in 305 to my code and so
this is where our Target is 305 we can
set it to 500 later but right now 305 so
if it's higher it's going to be like
negative
error n positive error it's going to be
higher it's going to be positive lower
it's going to be negative um our output
is then going to consist of these three
terms the proportional term the integral
term and the derivative term the
portional term is really simple it's a
number times the error so if we're a
little bit too
high the error uh if we're too high the
error is negative because of the way
this is set
[Music]
up yeah okay if we're if we're too high
it's going to um our proportionality
here we're going to get a a if it's too
high we get a lower error and it drop it
slows down if it's too low we get a
higher we get a positive error and it
speeds
up that sounds wrong no it's just
straight up um when it's down here the
error is positive and it's very positive
sorry non-e equilibrium system we
haven't added in I yet sorry P term only
when we're down here it's the it wants
to be here this is 300 it's down here
this is 150 or something um so our error
is 300 - 150 is 50 it's going to give
the throttle k p which is our
proportionality constant times 150 and
so it's going to go up until it gets to
about here when there's no error and
that error is going to be zero and then
it's going to get up here and the error
is going to be negative and we don't
have any negative throttle control and
the stuff's going to hit the fan so
we'll deal with that in a
minute we'll deal with that with the
integral term actually this one is
another constant we'll call it Ki um and
basically the game here is going to be
finding these three numbers uh so this
is Ki this is a sum of the past errors
and the idea is that if for some reason
and we'll call that reason gravity this
thing is hanging a little too low
because gravity is always pulling it
down that adds up so we get an error
here and we get an error here and we get
an error here and the longer it's
sitting low the more the sum of errors
in the integral term accumulates and
pushes it up similarly if it's high for
too long it's going to push it down and
if it's wiggling nicely around the
middle point the high points and the low
points are going to cancel out and the
integral term will go away so the
integral term is eventually going to
settle in the level at which it wants to
hover and you'll see that in a bit the
proportional term will eventually tell
us how hard it wants to get back to that
level
and we'll show you um last up is this
derivative term this is the creepy one
um it is the change in the error times
yet another constant and what happens is
this thing's going up toward its set
point and it's going up toward it pretty
fast you might want to slow down the
extra power you're giving it as you get
closer and closer to this uh to the set
point and so that's what the D term the
derivative term is good for if one error
if it sees that your errors are
decreasing it can reduce the amount of
power you're giving to the thing so that
it doesn't overshoot so much and we'll
see this in a sec the role of the D term
is to keep it from oscillating wildly
you can imagine if you only have it
going plusus plusus plus minus it's
never going to sit in the center and the
D term provides some kind of
damping um if you look this up in the
internet you're going to see tons of
calculus nine Danka um it's makes the
math easier and so when you're proving
theorems about it it it makes that work
out right but in reality you're always
sampling things and so everything is in
is in discrete time and so it's I look
at the value on this potentiometer I
look at it again I look at it again
right it's just step step step the nice
thing about this is that if you sample
at regular intervals the kind of Step
size effect goes away and you have to
worry about it so we're going to do that
and then all that's left is some
multiplications keeping track of the
cumulative errors so that's for the I
term and then taking the difference
between last error and this error for
the derivative term so the math is super
easy no memory no nothing so let's do
this
um how much time do I
have
lovely um so the first thing I would do
if we were doing this is set up a dummy
system and that I'm going to do by just
plugging this into a remote
controller channel 3 and we're going to
operate this manually for a sec just to
get a feel of what's going on um and
this is actually super informative it's
not something you have the option of
doing
if you have for instance a large
chemical plant um but we don't so we can
do this right and I'm going to try to
get it to hover there but it's really
hard so I'm going to take the stick and
I'm going to Goose it up a little bit
and it doesn't pick up it doesn't pick
up it doesn't pick up it finally starts
picking up that's not bad um and then it
goes too high so I have to get down off
the throttle and then it goes back up
again way
overreacted
okay so what you can learn from this is
that what your ideal controller would do
is increase the throttle slowly till it
gets to about the right place then it
would knock the throttle down so it
would get to its like hover speed and it
would kind of stay there and then if you
tweaked it it would increase or decrease
the speed accordingly and settle in
getting it to do that is really hard
this is not just I'm going to see oh
yeah the last thing is that was kind of
throttle
around heish 30% right and that's with
the
batteries kind of fresh but not totally
fresh right and so you might think
naively well what I'll do is just tell
it to go throttle 30% right because
that's what it was when it was hovering
here and that won't work at all because
a it only hovers here when the batteries
are at this particular State you try to
do it later you're going to need 35%
throttle to hover you do it with fresh
batteries it's going to be 20% you don't
control that and it doesn't give you
this nice um you know crank the throttle
up shove it back down effect that I wish
I could have done better for you um and
so that is what the PID controller is
going to do for us um can you all see
the code on the screen or is it really
illegible super illegible okay well I'll
have to walk you through it um it's all
going to be available online
shortly
um let's
see uh this is it's actually I did this
in Python because it's as easy as
possible here it says it reads the ADC
and subtracts the value from the set
point that's our error term here it
figures out the time change we're
actually not going to use that that here
it calculates the error sum it adds the
errors together and keeps track of them
so it's Error sum equals error sum plus
error right uh P term is our constant
times the error I term is constant times
error sum and D term is the difference
between the error and the last error it
sets the throttle to the sum of these
three things P plus I plus d and then it
updates the other variables last error
equals error last time equals the number
of ticks and oh it prints data out to
the screen cuz we're going to get a nice
graph here and that's really all the
code there is so this is super simple
code this is not a coding problem it's a
you getting your head around how this
all works and getting the tuning right
problem and that's the point here um so
to start let's break it um let's set the
I
term instead of being the error sum
we're going to set it to zero because we
can and we're going to set the Z the D
term to zero so this is now
hopefully demo effect is in effect this
is going to be just the P term and I'll
show you what it
does and
run you know it it has a couple second
weight so that nothing horrible happens
and then it
starts and unfortunately
it's not strong enough to even lift this
thing off the ground but here's what you
can see when I raise it closer and
closer to the set point the blades go
slower and slower when it hits the set
point they stop and anywhere above it
doesn't do anything useful at all and
this is the problem largely with having
a uh non-equilibrium system like this if
you imagine a balancing bot or
something it's at least stable when it's
up and you don't need to push it
backwards or forwards for at least a
microsc right this thing Falls straight
to the ground so that's why this isn't
working
but if we so what this is doing is it's
taking the error multiplying it by some
number and then throwing that out to the
throttle that number is right now A
tenth um but let's Jack it up so this
wasn't lifting off the ground with our
current P term let's make it go crazy
I've changed it from one10 to 5/10 and
this should be quite active yep good
that's enough to get it off the ground
and enough to get it
hovering because
here that's what I wanted to see because
here again the motor's off here right
there's no error the error increases now
it's five times as much throttle as
before and so the good news is that gets
us a nice hover here somewhere it's the
wrong place but at least it's a nice
hover
but if you disturb it at
[Music]
all ask me how popsicle stick one died
um so this is the problem with straight
up P control is that you can't do it
very aggressively if it is too
aggressive oh did we see the graph on
this I don't know again with the screen
here but this one's
super I'm using T th whatever p on oh
hello uh IDE because it lets us see the
values and that blue line there is the
angle and the yellow line is the
proportional control and you can see
that they're moving together every time
it goes low it throttles up like crazy
and it makes this horrible oscillatory
Behavior horrible oscillatory behavior
is sign number one that your P
coefficient is too high so I'm going to
knock that back down to one for the
moment cuz it's safer
um the next contestant is the I term um
so this was p+ I I is the one that adds
up the past errors and so you saw when
it kind of got to hovering before it
went crazy it would hover about here
that's a little bit low so that's going
to be a positive error and then the next
time it reads it it's going to be
another positive error and the next time
another posit postive error etc etc
these are going to keep adding up and
the I term is going to get bigger and
bigger and that's going to push this
thing up so the D term kind of makes it
wiggle around a central point and the I
term kind of tells it where that
equilibrium Central Point needs to be so
let's see what
happens plug it back in oh hello um
reflash the code and then plug it back
in it's going to be good this is is
really fun to develop no chemical
plants
hello all right one more
time
play so this is with p and I and what
you're going to see is it's going to do
that same sort
of zzing
up oh hello it's still kind of hovering
around it still kind of has the
oscillations right you can see it
eventually wiggles out of control
but at least it's kind of wiggling
around the right
part and what you can see if you look at
the graph let's see the I term is green
can you guys see that there it's it's
way too high right now so the green term
is diving down the some of these is
getting negative and
negative as it goes down and now it's
below zero so now if I put this down
again the I term is going to be low
enough that it sits there at the bottom
but slowly over time we're going to get
a bunch of positive errors here they're
going to push this thing up
and pretty darn soon it should start to
come on I'm going to cheat by making it
even lower in the interest of
time oh good lord no that's negative -
250 I'm going to reset it and this is an
important lesson this is called integral
windup we'll talk about this in a minute
your integral term because it's an
addition and subtraction because it's an
addition of Errors can get way off the
rails and it can get way off the rails
high or low and that'll make your motor
stop
working but for
now we got a system that kind of wants
to be you know it's it's more on when I
push it down and it's less on when I
pull it up that's the P term it's kind
of sitting where we want it to be
eventually and that's the I
term and it's oscillating out of control
and that's the lack of a d term and so
the D term provides this damping by
saying if the eror is changing in the
right direction we slow down the extra
motor and vice versa so let's do that
throw some D term in
there
stop
play
reload fingers
crossed yeah
it's getting there it's getting
there it's got some jumpies in it and
this is actually unique to this stage
and I'll this is super instructive cuz
the derivative term is Tweaky and
subject to errors thank you but look if
I push this thing down it fights me
right and that's because it's going a
little bit below its set point and
that's the extra proportional term if I
hold it down for a long time
we're going to get lots of extra
integral and it's going to go too high
for a while before it settles back down
and that's the integral term adding
together if I do it too high for a while
it's going to
drop until it figures out that it's
dropped and it comes back
up
so those little bumps in there scare me
um it is the wind yeah and this is true
of real quadcopters too right they get
buffeted and it's true of real systems
that have any kind of disturbances in
them but that is basically your PID
controller the P gives you more as it
goes down and less as you go up the I
sets the set point to about right and
the D keeps it from swinging wildly out
of control what's fun is to set the D
too high and we'll talk about that in
just a second um you saw when the P term
was the only thing it kind of went w w w
it was really kind of slow 1 second
oscillation right that time scale is
worth keeping in your head because
that's kind of the natural period of
oscillation of the system left
undamped if
you there's another kind of oscillation
you can get and while we're doing the
demo I'm going to do it and that's when
you put too much derivative term in
there and it oscillates really fast
because it says oh I'm getting closer oh
I'm not as close as I thought I was oh
I'm getting closer and it just
goes like
that see what I mean can you hear the
motor about to die and the propeller
about to fly off I didn't have this on
tight enough when I was developing this
at home and it kept flying across the
room because the propeller just flies
off the thing when it jerks like that
and my son laughed his head off
um so let's see back to the talk um so
that was p i and d and it's really
really like you saw it's a few lines of
code it's you accumulate up a bunch of
errors and you take the difference
between the errors you multiply these by
three constants and you're good to go
the real trick is picking the constants
and this is called P ID tuning and this
is where all the bodies are buried um my
handwavy procedure and this is the
standard manual PID configuration
procedure is to start with all of the
Val all of the values zeroed so no p no
I no D you increase the P constant KP
until you get a reasonable response and
that was until this thing kind of lifted
off the floor like this remember when it
was too low it just sat there flopping
and it eventually kind of lifted up but
then it went oscillating crazy out of
control you then increase Ki until the
center of these crazy oscillations kind
of reaches the set point you want and
then it's probably going crazy and
oscillating wildly so you start adding
the D term just like I did until it
stabilizes out and at this point you can
then iterate and what's fun about these
systems and this is why they're super
hard to tune is that if you add more D
you can
then make both the proportional and
integral terms faster so you can make it
Zoop up faster
as long as you're able to keep it from
oscillating and so that's really the
game is to get it up there as fast as
you can without it oscillating wildly
out of control or going into crazy
uncontrolled oscillations when it hits a
disturbance um buried underneath all
this so that's how You' tune one of
these and that's what we did and that's
really all there is um notice I was able
to hold this thing and keep it from
breaking itself the whole time if you
have a
quadcopter you you want it to be
tethered while you're doing this um you
know you want it to be on a line cuz
it's going to hit something and you know
if it's expensive frame you're going to
be bummed if it's a system that can
catch on fire it'll catch on fire um so
you want to be you know when you're
doing this tuning you want your hand on
the off switch and that's why Engineers
spend all their time in control theory
doing it right um You don't need to do
it for something like
this buried bodies include uh the time
step uh my advice to you is to sample
regularly always so that you don't have
to worry about changing time steps in
there um sample often but not too often
and what I mean is if you sample too
frequently and I actually did that when
I was setting this up the error terms
don't detect any change in between them
like this thing moves kind of on the one
second time scale so if you're sampling
at the microc time scale all your
changes are going to be zero so all your
derivative terms are going to be zero
until that one when it's not and that's
going to be big and that's ugly so
there's a bit of an art to this and the
reason it's beeping at
me um so it's good to know your time
scale and this thing was kind of going
wub wub wub at about a second like that
and so that means you want to be
sampling it about 10 to 100 times faster
than that so I'm doing I think 10
milliseconds
here um and that's because of this D
term which depends on the time scale and
there's actually on the stage some weird
highfrequency noise that there wasn't
when I was doing this in my tent and
that makes the measurement of the dterm
extra noisy and if you're into
engineering or frequency domain stuff
you can think of this as being the noise
component is high frequency and the True
Value you're looking for the the way
this thing is moving is at a much lower
frequency so if you're sampling all the
time super high frequency you're
probably only sampling the noise and
none of the signal that you care about
and that is a bummer um the D term is
often the limiting factor in the overall
systems performance because like I said
if you can damp it out you can take more
aggressive ups and
downs
um there's a bunch of ways to tune these
to pick the P and D coefficients the
classic is uh seagler nickels it uh you
pick the P term and then you watch it
oscillate and using the frequency of
these oscillations and two formulas you
pick the other terms the problem with
seagler nickels is that it is very
aggressive and it it really wants to
optimize the system and that's dangerous
with something like this that's a motor
on the floppy end of a stick um it's
very aggressive at its tuning it will
get you kind of a nearly optimal
situation it'll goop like that instead
of this kind of wub wub wub that mine
did um but then if you push it to far
out of its sweet
spot and your thing's on the ground um
other automatic methods for tuning are
there's software Solutions but these all
have to be custom and basically consist
in you get it doing the right thing you
change it a little bit and you optimize
whatever it is you care about about the
system the problem is what you care
about might be stability it might be the
speed that it gets there it might be the
speed that it responds to wind buffeting
it might be how accurately it's exactly
at that angle you need to know what it
is you care about and then write
optimization software for it and that's
why this is kind of a problem worth
thinking about and that's why I think
the human in the loop is not dead um the
real worst thing with P Loops is lag and
that's caused by inertia in the plant
this is a heavy propeller this is a
heavy motor propeller pushing is the air
you know there's nothing happens at the
right time here I tell this thing to
give me more juice this thing spins up
slowly it only Rises slowly there's a
lag there and that limits how fast you
can make how high you can make your D
term and then that limits how quickly it
can uh settle
down this I didn't know where to put the
slide if you ever run into the standard
form it's just the whole same thing
except multiplied by K
P um it's neat because it lets you talk
about the integral time and how long it
takes to get from here up to here but
honestly I don't like it much you will
see it it's useful for proving formulas
you'll see it sometimes you now know
that a thing called standard form exists
and that you can get from the standard
Co form standard form coefficients to RS
by just multiplying or dividing by KP so
it's not
it's not interesting um real world
applications will often involve P Loops
inside P Loops so a self-balancing robot
has one p Loop that makes it balance and
another that sets the balance angle to
control the speed at which it's going
forward so you say here's the speed I
want to go and it has a p Loop that says
okay what angle should I tip the thing
at until it starts going at that speed
and then the other one says how do I
hold this angle
so you have an innal inside loop and an
outside Loop same thing with Attitude
control or GPS rooting of
quadcopters the important thing with
nested Loops is that the inner loop runs
a lot faster than the outer loop so that
the inner loop has time to react and
kind of get to its set point before the
outer loop says wait change your set
point right and factor of 10 is kind of
about right here so outer loop runs 10
times slower than the inner loop and
you're
good uh what else could go go wrong um
PID works best around the equilibrium
point that is when it was hovering here
I could push on it and it did pretty
well
um but you know starting off it had to
add extra kick once it's up here it has
to reduce it a
bit the plant responds differently at
different set points it's nonlinear but
if you're around the equilibrium point
it's pretty much linearizable or you can
at least pretend it is and that's where
these P Loops mathematically have their
bases
um
the I term is the one that gets you into
equilibrium and the P term is the one
that keeps you in equilibrium and what
happens when we get out of equilibrium
three or four bad things the first one
was integral windup you saw that when I
left it here or when I did this the
errors added up because I was subjecting
it to a disturbance namely I was holding
it up here for a long time against its
will and it couldn't control against
that and so the integral term got bigger
and bigger and bigger and bigger and
then once I finally let go of it it was
floating too high or yeah it was too
high too low whichever um this you want
a control for this in your code and the
easiest way to do it is just use Like A
Min and a Max function and say this is
as far as I want the integral term to go
and this is as low as I want the
integral term to go and that's easy
because here we wanted it to cruise at
about
30% right so 30 is a good number for our
inter term if it goes above 80 or below
10 that's probably not good so you can
actually limit the integral windup you
can actually limit the integral term to
a plausible range of motion and that
solves integral windup ha winner um oh
the other way to do it done sometimes in
industry is you detect these special
situations like you detect that there's
a man here holding this thing and you
say that's a special situation I stop
adding the integrals together whatever
um output range this thing is a throttle
so it's between 0o and
100% we got times in there where it was
trying to get it to go 125% I wrote a
function that says if it's greater than
100 set it to 100 you need to limit the
output range to um last if you're
changing the set point while you're
going it can cause something called
derivative kick and this is you've
changed it hasn't been buffeted up or
down but you've changed the set point
and when you change the set point
instantly it thinks whoo the error went
from here to here something's really
wrong and so it cranks the derivative
term up and it goes wub wub that's no
good you can solve this actually using a
trick called derivative on measurement
where instead of worrying
about we were doing the difference
between the two errors it's equivalent
to the difference between two set points
minus the difference between the two
measured values and if if you just use
the measure values instead it takes away
the set point thing this is really also
standard if you need to implement this
you can look it up on Wikipedia I was
going to live type it but we don't have
time um the last thing you might want to
do is tweak these parameters live if you
just want to change the K uh the
proportional or the derivative terms
it's not a problem but the I term has
the past errors embedded in it right
it's a sum of all these past errors so
if you change it if you increase it now
you're not just increasing the value now
but also kind of the sum of all errors
that would have been and the solution
here is to change the errors sum also
proportionately at the same time so if
you add 50% to your Ki just to see what
would happen you want to take 50% off
the current error sum to make that
balance out and if you don't do that
it'll
go um and that's
another classic trick so it's conclusion
time um my first conclusion is as you
saw especially toward the end of this
and with this thing flying out of
control P can be hard um it's basically
all the work is in tuning the system and
to do that you need to know your plant I
mean we played around with the remote
controller that helped a lot I knew 30%
was kind of my set point I knew I had to
ramp up and then ramp down that helps a
lot but it's not the end of the game um
your specifications are like as fast as
possible robust to wind Buffet you know
as little oscillation as possible these
are not very precise specifications and
so that means there's no solution to a
kind of ill-defined problem like this
which is why the math people still worry
about this and this is why there's a
whole industry of Engineers who will
worry about what the transfer functions
look like and treat this as a filter and
blah blah blah um when it goes wrong it
can break things so it's important to
get this right but P Loops are also
super easy um and it's really the con
Concepts you need to know the code was
15 lines um and I wasn't even using a
library uh the P fights deviations
around the equilibrium the I term kind
of gets it to ramp up till it's at the
equilibrium and then the D term keeps it
from going up and down wildly and if you
know those
you know which of the three knobs you
need to turn to make it behave more in
the right way than it is right now and
that can solve the problem and uh last
but not least thanks my sponsor Reed
more hagad keep on
[Applause]
y'all
[Music]
thank you Elliot for this very
entertaining very informative talk I
think we have time for two questions are
there any
questions here U please please wait till
you get the microphone so people on
stream will also hear
you thanks that was super cool um you
mentioned sampling it regularly yeah
that's also something that can go wrong
right if you don't have a real-time
operating system maybe you get some yeah
you can sample irregularly if you keep
track of the time differences um and
then there needs to be a multiplicative
term in the integral one and a divider
in the derivative one and that divisor
in the derivative one is really the
problem um that's the that shows you the
fragility of the of the D term when that
inter interval goes down to zero if you
sample faster and faster you end up div
dividing by zero and that goes all to
heck um when you sample regularly the
sampling time is in the coefficient and
so you just don't have to worry about it
if that's changing all the time you have
to think about you know doing that
multiplication
out yeah good and another
question I normally stop integrating if
the output is
um exceeding 100 or one or
0% is it better or worse than your sub
sucession you suggested to limit the
integral value yeah that's interesting
there's a couple different ways to do
there's actually a lot of different ways
to beat integral windup and I was
talking with an older engineer last week
and he said this was heresy to do this
kind of clamping back in the 80s because
it introduces nonlinearity to A system
that should be linear and they didn't
even used to do this back then nowadays
everyone does it so it's open um
some sources you read want you to clamp
the output um so and others want you to
clamp the integral term itself and which
of those you
do must make a difference and I'm not
100% sure which or what my gut says
clamp think the output is probably the
right thing to do I was
doing I was also doing that I had it
between zero and 100% because it has to
fit a a pwm value it has to fit this
motor
controller um and I wanted to show you
people how integral windup makes the
term go up and down
um my gut is that the output one is the
right one because then anything else
you're doing in your code has kind of
the out put value in the code that
represents what's actually going on in
the physical
[Music]
system but really don't hold me to that
Andor do research if it if it matters
both work in this kind of
practice okay thank you again Elliot
thank you very much give him another
round of
[Applause]
applause
[Music]