Dear viewer, these subtitles were generated by a machine via the service Trint and therefore are (very) buggy. If you are capable, please help us to create good quality subtitles: https://c3subtitles.de/talk/1078 Thanks!
[Music]
this talk is will be modeling and
simulation of physical systems for
hobbyists Manuel iul wanted to lower the
threshold entry entry thresholds for the
subject and so explaining Mo modeling
and simul simul simulation techniques
that help even small projects for makers
and hobbyists so please welcome Manuel
for the talk about modeling simulation
and pH of physical systems for
hobbyists thank you for the kind
introduction and welcome
everybody um actually I forgot uh to say
that um all examples that I will show in
this talk um can be downloaded on the
website of the talk so if you want to um
yeah try it out already right now while
I'm actually going to show the examples
you can do
so so let's get started by taking about
this title a little bit to see what is
meant by the individual words and by
this have a rough outline of what we're
going to talk about so first
modeling in this context means
to create a mathematical description of
a system so we look at the physics of
for example a robot that we want to
build or a
mechanism then we extract the different
physical ex effects look at the equation
that are represented in these effects
put it all together and then we obtain a
mathemtical
description and simulation then means
that once we have this system this model
we are going to use the computer to
perform calculations from one time step
to the next so to basically extrapolate
from an initial state of the system to
how the behavior is going to be in
time in this talk I want to talk about
physical systems so Hardware that we can
create um and not some sort of fictional
physics for computer games or something
but relas something like a mobile robot
a small drone or similar
that yeah as a makeer you want to um
create and I'm addressing this talk to
hobbyists I don't want to reduce the uh
knowledge and competences of um
hobbyists but only say by this that the
resources that we're going to use in
this talk are all commonly available
tools and not uh simulation software
that you have to buy for tens of
thousands and your and I'm not
exaggerating about it so maybe a quick
round like who did U math courses uh at
University
level okay yeah that's quite a lot
so actually I prepared the talk um to
address it to everybody who had 10th
grade um school math so it might be a
bit ilar to to you already but then you
can help your neighbors who have
difficulties so let's get started what's
the motivation behind doing simp
simulation why do we want to simulate
something so imagine with your friend
you want to build a
small
um yeah self-balancing robot like this
so it's a very easy design two wheels
left and right which have one motor uh
each wheel has one motor and then
there's a rod going up with a camera
fixed on top so that uh you actually
have a higher point of view so that you
see
something and this is actually um an
inverted pendulum so if you build it
like this without the controller it will
just uh fall
over but yeah it's uh quite easy to
implement uh at least Hardware wise
so you want to build this with your
friend and you say okay I'm good at uh
programming but I am not so good with
the mechanical aspects so your friend
says okay no problem I will build the
hardware but then you're stuck okay you
don't have the hardware yet so how do
you want to develop the software if you
don't have the hardware and this is
where simulation can help for example um
so in the time that your friend is
building the hardware you can already
start the software you just uh have your
simulator you recreate uh the hardware
while it's absent and then you can
program your controller everything that
you want and once the hardware is ready
you keep the controller you throw away
the simulator
and ideally
then the system is complete so I build a
small Simulator for for this
example and python you can also download
the code um so you see here the
simulation is already run running but
it's perfectly balanced so it's not
dropping yet but if I push it a little
bit from the side it will tip over
because I didn't activate the controller
yet so it's like if you have your robot
without power if you push it a little
bit it will tip over so now I can
activate the controller and then push it
a little bit and then you see that the
controller will actually bring it
back so this the controller is the part
that you will Implement in software and
the hardware is what you so basically
this part The Tipping overp part is the
hardware that your front will build
and
um let's see I can even make it drive
around just as one example of what you
can simulate with uh the methods that
we're going to
see okay the problem is I don't have
that much time
so uh we're going to not going to go all
the way I will start with the very basic
um models and then we see how far we go
so um to summarize the
motivation simil can be used as a
placeholder so while the hardware is
built you have the simulator and then
you exchange it or it can be used like
for as a virtual test bench for example
for scenarios where you don't
necessarily want uh the real Hardware
because it's risky behavior and it can
be
damaged okay now one step back modeling
what what is it and what are the the
basic formations so imagine our friend
Newton here uh under his apple tree and
now we cut the Apple loose and we ask
ourself okay what's going to happen we
can look at that at different levels of
detailed like from sever some from very
simple level to a very detailed level at
the simple level you could say okay the
Apple moves down so you see on the plot
the line just goes down constant
velocity
then well this is an observation that
you can make very easily just by looking
at it you don't need to measure anything
then at the more detailed level you see
that if you make a more precise
measurement actually your Apple is
accelerating so you have this parabolic
curve um because of the gravitation the
Apple becomes faster and faster and then
if you go at a even more detailed level
you know that there's actually
aerodynamic drag so it won't accelerate
infinitely but it will eventually reach
a saturation velocity this is for
example when a sky diver is falling from
the sky
uh yeah then you clearly notice this
effects are add over longer
period so the take- home message that I
want to show with this slide is that
actually the depending on the question
that you want to look at with your mod
your modeling and your simulation you
should um choose a appropriate level of
detail so as simple as possible and as
detailed as necessary and this might
actually change for the same system so
at one point in time you might be
interested in this uh starting Behavior
so you need the acceleration and at
another Point uh your project you might
be interested only at what happens here
at saturation
velocity okay now we go uh even one step
further back and the mathematical
methods so differentiation and
integration because this is very
essential it's many physical measures
are linked to each other through
differentiation or integration for
example if you take the
position x velocity V and acceleration a
then if you differentiate X you get uh
velocity V and if you differentiate that
again then you get the acceleration a
and the other way around by integration
then you obtain velocity again and the
position so you might remember this
equation from school for calculating um
uh the derivative so
basically the derivative is defined as
the ratio of the function you want to
differentiate at two points in time
Point t plus h and
T so the difference of this divided by
the uh distance and time so the
H and if you then have this corner case
where H goes towards zero you actually
obtain the derivative at the point T so
in this case the velocity at the point T
now if you take this equation and you
modify it a little bit so you multiply
by H and you add the x of T then you
obtain this equation which is one way of
uh calculating the uh integration so X
in this case at the point t + H and time
so you see that it
depends on the X of T so a little bit
earlier in time and it also depends on
the velocity so the derivative of x a
bit earlier in times multiplied by H and
again if you can take this corner case
where H goes towards zero then you uh
obtain uh X of t +
H so this means um actually by
integrating we can look a tiny little
bit into the future because the
derivative is always running ahead in
time of
the uh
function that um was
differentiated if you integrate it
backwards you can look a bit into into
the future and that's exactly what we
want to do in simulation right we want
to say okay we have an initial State at
Point T and then we're interested to
know what happens at Point t plus a
little bit so in the following we're
always going to integrate for the
simulation and not
differentiate the only problem now this
corner case definition that's nice for
mathem mathematicians but it's not
really useful for computations we cannot
WR this in software so what's we're
going to do is we're going to use the
so-called Oiler method and this simply
means that we replace this corner case
limit of AG going towards zero of age by
a finite uh value TS which is often
called the sampling period so finite
means we just uh take a small but
defined value and not this limit
thingy and
then with TS we actually only going to
calculate the points and time at integer
multiply multiples of TS so we call K
the index and then we calculate the
point and time at T equals K *
TS so this is
discretization and and yeah
so we transform this equation into this
one we do divide by TS and we obtain
this nice equation which is uh X of k +
1al x of K plus v ofk * TS so this is
something that we can easily Implement
in
um software we just have a for Loop and
every time we do that equation
so I'm going to show you a simple
example in
spreadsheet just to show that well it's
pretty independent of uh What uh
software you
use so let's define some constants here
on the left side um we take a sampling
period of 1 millisecond let's put the
unit here so we have it in seconds then
we have the index here we call it K we
have the time here we call it t and
we're interested in the position we call
it X and then the velocity we call it
V so and now every line here will be one
point in time so we begin at time zero
and everything is uh
zero like
this let's get a bit more space
here okay so now we have this this
formula so we need a k + one that's not
a problem we just say okay the next K is
equal to the previous k + one and the
time oh now I covered this
formula uh the time we say is equal to
this index K times the sampling
period so we use these dollar signs so
it doesn't change if we copy
pasted and then we have the integration
formula so the x is the previous x times
the previous V times the pr velocity
again multiplied by the sampling
period like this again with the dollar
signs and now okay it would be boring if
the velocity is zero all the time so
let's put the velocity of5 m/s for
example
and now we want the next moment in time
so we just do the same operation over
and over again so I just copy paste um
the lines and this is now the time um
Evolution for example I can now
um plot um position over time I just add
this
plot I tell it to take the time on the
xaxis
and take the position on the y-
AIS okay insert it
here all right so yeah it's not very
exciting but it's exactly what we expect
if we integrate a constant over
time
um so we just obtain a straight
curve so let's add the acceleration now
we call it
a okay we start the acceleration from
the beginning um like this and now what
we do is we actually use the same
formula that we used for the uh position
so this one um we C we also use it for
the velocity we copy pasted and then
um we can copy this
line and now if we want we can repeat
this um like a bit
longer okay so you see now we have a
constant acceleration we integrate two
times so we get the position as a
parabola shape like this actually I
could have added the negative
acceleration just to have the drop from
before so this is all already quite
useful if we now say that um the
acceleration input is not a constant but
for example we have the acceleration
input from an from a sensor from an
acceleration sensor then just by um
using this method which doesn't rely on
any knowledge of the um shape of the
acceleration right so we can just give
it random input and it will always
integrated so if we have the sensor
input from the acceler meter and we
integrate it twice then we can can cre
keep track of our
position okay but now we want to model
something so we don't have an
accelerometer yet so where do we get the
acceleration from okay one warning
always keep the sampling period small
we're going to discuss later on what
small
means um okay so some building blocks I
canot obviously not um summarize all
physical equations that exist but in
mechan I will show some of equip
mechanics and of electr mechanics that
are useful like for mobile robots if you
have a motor turning something with
gears maybe and then a sort of um lever
arm me mechanism for example so we start
from the simplest version so a moving
Mass uh just imagine a bilard ball for
example which has a mass m and the
velocity V and now if we want to change
this
Movement we need a force F again this is
uh our FR Newton uh telling us that and
we this is the second law of motion so
the force that we need is proportional
to the mass times um the
acceleration okay I need to accelerate a
little bit as well because timing time
is running
out so um yeah actually have so the same
equation that you have for linear
motions you also have for uh rotational
motions which is the right side and then
you can also have the the white so this
is what we had in the ex Apple example
so the force from the weight is just the
mass times the um gravit
constant and other effects that you can
have are for example spring force and
viscous damping these two are actually
not only useful if you truly have um
spring damper mechanism like you would
have an a suspension for example but
it's also useful if you for example want
to model a hard contact like uh uh yeah
I had in the uh beginning
in the simulation example
the uh robot tipping over and falling on
the ground so you just put the um
stiffness quite High and the damping as
well and you will obtain this um OB
effect of the input of a contact sorry
so let's see if we now combine this for
example we want to have
um just for the sake of the example a
small Mass spring temper so we put the
gravitation here we put
um the spring
here and the damper here um yeah
[Music]
damper and what I didn't say here is
that this F is
not um necessarily one force but it's
the resultant Force so this is actually
a vector Edition so you take all forces
together and then this is the F which
drives um your acceleration so this is
what I'm going to do here I just t Okay
some um from here to
there and then I need some constant so
for the gra invitation I need the mass
so let's say 2 kilo it's a bit heavy but
okay let's make it half a kilo and then
let's say the spring stiffness
um we just put
100 uh Newton per
meter and the damper we let's put 10
so um of course this
uh setting of The parameters now I do a
bit random but ideally you would look at
your system um when you design it and
then calculate U these values so that
they correspond to what you're actually
building now I just make a simple
example so I picked them at
random okay so then we have the
gravitation we said gravitation was if
we look here M * G um okay so I also
need the
G so that's the well-known uh
9.81 um m/ second
Square so that's the m
uh yeah the mass
times
this we again add the dollar
signs and then we have the spring so the
spring is I set the x0 at zero so the x0
is the equilibrium position
and so we had minus
okay
times um
position and now what you see here what
I didn't say but if you know a little
bit about physics and math you see that
this is actually a differential equation
that we're going to solve
here but yeah you don't need to worry
too much uh right now
because the new method is taken care of
that uh so we also need the damping here
times
velocity
okay and now I'm just going to copy it
all the way down so that I have like 60
Minutes uh seconds
it takes a bit longer because yeah it's
a lot okay and actually what you see
here is
that what I said before about the um
sampling period was a problem right now
because you we're actually doing an
error in the Y method in the integration
and
if
the so normally because we have this
feedback loop in the differential
equation it's not a problem because if
there is an error then it will be
compensated in the feedback loop but if
the sampling period is too big then this
uh error is actually um yeah multiplied
and then you get get this instability
Behavior so I can also show it with a
bit bigger effect like if I take only
100 of a second then you see here if you
look at the values it's actually going
to Infinity so my simulation is uh not
robust and this
means that the sampling period is just
too big
and the simulation is becoming unstable
so now I picked
um a smaller value which of course is a
problem because now I'm only simulating
6 seconds instead of 60 but you see that
here is a tradeoff to make between model
uh
complexity uh and precision which means
more computation
um resource I needed and
um
the um yeah the robustness of the
simulation
sorry uh okay so the question was
whether this was a
resonation
yeah right um but in theory this okay
maybe I made an error in my calculations
let me show you the one that I
prepared okay I'm just going to take the
one where I prepared it properly because
obviously I made an error in the
calculations um
so this is uh the effect that you are
expecting right so you start at a
certain position then um you have an
oscillation through the spring which is
bringing back the M wants to bring back
the mask to the center and then you have
a damping so it slowly Fades
out okay actually I'm also running out
of time I wanted to also treat some um
uh electric um principles and
electromechanics to show an electric
motor I can quickly show it to
you um
and and the slides and so the nice thing
of the electric motor example is that it
uh shows how to solve problems where you
actually have two equations which are
entangled with each other
and you can also see uh in this
example the effect of taking into
account uh one physical principle or
ignoring it in this case the effect of
the
coil so as I said you can download it
from the website and then uh have a look
at it if you're
interested right so this brings me uh
already to the end of the talk just some
tips and tricks to summarize so the as I
said the sampling period needs to be
small as a rough estimate I usually take
around 100 times faster than the system
time constant so for mechanical system
usually 1 millisecond is okay I don't
know why now well I had an error before
but um one millisecond usually works
fine if you have the electric motor with
the coil then you need to reduce the
sampling period maybe to 10 micros
seconds or even less it depends on um
yeah the system time constant as I said
then um as a second Point use block
diagrams so this is uh what I mean by
block diagrams it helps you to keep
track of um yeah which physical measures
influence which other physical
measures uh
well it's a bit difficult to read maybe
in the beginning but uh you get used to
it then then it's really
useful and then if you want to be sure
about what you're doing or you're having
more complex models maybe use some
specialized to for example scipi which
has a good ordinary differential
equation solver or open modelica with om
edit where you can basically just uh
compose your system uh as you find it
you just add a block for this spring you
add another block for D the damper and
then it takes care of that or a cab with
xose where basically you use this block
diagram method to Define your equations
instead of writing them
down and so as I said they have better
differential equation solving they're
also more ient because often they use
VAR variable time step so they see okay
when it's critical to reduce the
sampling period And when it's less
critical and also very helpful are the
data logging and visualization tools
that come with uh this software
otherwise it's sometimes uh really comp
back on to track to keep track of all
your variables and then plot them
nicely okay so actually I think I
accelerated that much that I still have
some time so I can maybe show you um how
this works in om
edit uh which is also free
software and it's basically a graphical
tool to use open
modelica and open modelica itself is
um
um modeling programming like well let's
say definition
language uh okay some thing is not
working because it's not starting as it
should okay then I can show you um the
python code of the simulator that I
showed in the beginning so this
one
um so what I did here was um to Define
two classes um just to have them run in
different threads one thread for the
simulation and another one for the
visualization and actually
the um simulation part is pretty simple
and then the visualization part takes
more lines of code so you see here that
there's a reset function where you just
Define the initial State and then if you
look at the simulation part itself you
find again what we had before so there's
a simulation Loop here I do a busy idle
just uh to uh well here is the busy idle
just
to have a sort of fake real time and
then um here you see the Ula method
integration so in this case it's just a
bit contracted with the plus equal uh
notation but basically it means theta
equals theta plus uh Omega time the
something period and then once
more um for the um yeah Omega the
rotational
speed then the different torque effects
so in this case that's the um
rotational version and not the linear
version and then at some point there's
the controller I didn't uh separate it
nicely in this example but usually you
should
and the same again for the linear
motions so I got the sign that time is
up and um
yeah would be happy to take some
questions yeah time is up but you're not
we're not letting you go
[Applause]
[Music]
yet because we do have time for
questions out in the room there are
microphones please if you have any
questions stand behind one of the
microphones and I will call out the
microphone number and you can uh you can
ask a
question please don't be shy seems like
there are a lot of you that are quite
knowledgeable about the subject so you
can stand up behind the microphones we
have a micro a question from microphone
number
four yes uh hello and thanks for the
talk I would like to ask ask if you have
the code somewhere available uh yes as I
said all the examples that I showed are
on the uh side of the torque itself so
um if you go in the far plan then uh
there are links to where you can
download these
files there any other examples on land
someware
uh not from me I mean there are probably
millions of examples but uh for this
talk I just created these ones I just
have one more for the drag with the drop
uh drop with drag um which you also
find but uh
yeah so this is uh drop
with so this is your chance if you want
to ask any questions and share the
answer to your question with the rest of
us please get up to one of the
microphones
and are there any questions from the
internet there is no signal from the
sign signal Angels
so is there a question from the
internet
no good well let's give Marius let's
give em Manuel a big round of applause
thank you for his talk thank
[Music]
[Applause]
[Music]
[Applause]
[Music]
you
[Music]
oh