in the last video we were given
functioning flight code
in the form of the quadcopter model in
simulink and we showed that it
successfully hovered the parrot
minidrone
but what if we had to develop the code
ourselves or make changes to it
how could we design and test the code in
a safe way for that we need a good model
of the mini drone and the environment
it's going to operate in
and that's what we're going to talk
about in this video i'm brian
and welcome to a matlab tech talk
to understand how a model can help us
let's look at a really simple block
diagram
in this first block we have the flight
control software
this represents all of the control
system software that we reviewed in the
previous video
this code has to interface with the rest
of the mini drone firmware
so as we talked about before it has two
inputs the raw sensor readings
and the reference commands or set points
and it also has two outputs
the motor speed commands and the stop
flag
remember though in the last video we
moved the reference commands to inside
the flight code
so really this input goes away and we're
just left with the one
the second block we'll call model and it
represents
everything else anything that isn't the
flight code
this includes the rest of the mini-drone
firmware
the hardware and the atmosphere it's
flying in everything
but we'll get into the details of that
in just a bit at a very basic level
though
the model inputs motor commands and the
stop flag
makes a few calculations and then
outputs sensor measurements
in this way the model is wrapping around
the flight code and
provides the feedback loop imagine we
had this model that was so accurate that
it perfectly represented reality
to a bystander it would be
indistinguishable whether the results
came from the actual hardware or if it
came from this perfect model
if this was the case we could simulate
the mini drone performance using the
model
and then be very confident that when we
later run the flight code on the actual
hardware
it's going to have the same result and
as long as we're happy with the
simulated performance then our design is
complete
now the nice thing about simulating the
performance is that we can reset the
model quickly
and put the vehicle in any situation we
want and see how it does
and if it does poorly we make the
necessary changes
and we don't damage any of the hardware
in the process
as you can imagine though a perfect
model of reality
is impossible to create luckily we don't
need to model
everything the trick is to figure out
what to include in the model and what to
leave out
some of that knowledge comes easily by
just understanding your system
and how it will be operated for example
we probably don't need to model the code
that turns on
and off the front leds this won't impact
our control system
but there are a lot of other things that
aren't as obvious and knowing what to
model can require a little experience
and investigation
one example is whether to model the
airframe structure as a rigid body or
as a flexible body do we need to take
into account the flexibility and
vibrational modes of the structure
will they meaningfully impact our sensor
measurements or
is the additional logic in the model
just going to complicate matters and
slow the simulation down
without any noticeable benefit it's hard
to know exactly what to model and what
to leave out initially
usually what happens is you start with
your best guess and then over time the
fidelity of your model will grow
until you're satisfied with the match
between your experimental results and
your simulation
so simulation is a way to verify the
system in situations that are hard or
time
consuming to physically test as long as
the model adequately reflects reality
but we also use a model to design our
control system
and for control design it would be great
if we could use the linear analysis
tools that we already know unfortunately
our non-linear model we use for
simulation
doesn't lend itself well to linear
analysis and design
for that we need a linear model
essentially what we need to do
is remove the non-linear components in
our model
or estimate them as linear components
the linear model won't reflect reality
as accurately as the non-linear model
but the hope is that it's still accurate
enough that we can use it to design our
controllers
we would then have two different models
that we can use for model based design
we have a lower fidelity linear model
that's useful for determining the
controller structure in gains
and we have a higher fidelity non-linear
model that's useful for simulating the
result
and verifying the system now to
summarize the steps we'd take to design
our flight control software
and test it using model based design
looks like this
first we create a high fidelity model of
everything the flight control software
needs to interact with
more than likely this will be a
non-linear model then we verify the
model matches reality with some number
of test cases
and once we have a model that reflects
reality we can create a linear version
of it so that we have both a linear and
non-linear model
we use the linear model and our linear
analysis tools to design
and analyze our control system then we
use the non-linear model to verify the
performance of the control system
and the last step is that we feel
confident enough to run the flight
control software on the actual hardware
for final verification
so far i keep drawing a model as this
single block
but rather than thinking about it as a
monolithic set of calculations
it's generally easier to break it up
into several smaller models that
represent specific
and discrete systems for our mini drone
we might break it up into the airframe
structure
the actuators the environment and the
sensors
and then within each of these models
there's even smaller subsystem models
like the gravity model or the imu model
there are many reasons to approach
thinking about modeling in this
hierarchical way
rather than lumping all of the behavior
together into a single model
for instance it allows multiple people
in teams to build different parts of the
model simultaneously
you can also upgrade portions of the
model based on which area needs more
fidelity without
impacting the rest and each sub-model
can be developed using different
modeling techniques
you can choose the modeling technique
that makes the most sense or is the
easiest for each system
then when you put it all together you'll
have an entire model that you can use
for wrapping around your flight control
software and simulating the results now
just like in the last video on flight
software we don't have the time in this
video to build up the models from
scratch
however the quadcopter example within
the aerospace block set
comes with a model that provides a
pretty good starting point for our
discussion
i'll point out a few interesting things
as we go along but i want you to realize
that this is just
one perspective on how to develop a
quadcopter model and the different
techniques that you can use to generate
the different subsystems
so with that disclaimer out of the way
let's jump into this particular model
you can see that we have the flight
software that we talked about in the
last video
and wrapped around this block is the
model that we're going to use for
simulation
at this level we have the airframe
environment and sensors
an airframe is implemented as a variant
subsystem which basically means that
before you run the model you can select
which
version of the airframe you want to run
with the non-linear model that we're
going to use in this video for
simulating the flight
or the linear airframe model that we're
going to use in the next video to tune
the controllers
let's take a peek inside the non-linear
model to see how it's set up
there are two main blocks the ac model
on the left consists of the actuator
models and a model of how the
environment disturbances
impact the system basically anything
that can create a force or a torque on
our mini drone is calculated in that
block
the forces and torques are then fed into
the sixthoff model
this is a rigid body model that comes
with the aerospace block set
and this is an example of using an
existing model rather than going through
the effort of writing out the equations
of motion for a rigid body yourself
of course you still need to determine
the specific parameters for your rigid
system
like mass and inertia more than likely
the developer pulled this information
from a cad model of the mini drone
however you could just set up a physical
test to calculate this information
yourself let's go back up to the top
level of the model and go into the
environment block
here again it's a variant subsystem and
we have the option of choosing constant
environment variables
or variables that change based on
position
we're going to select the constant
variables because things like gravity
and air pressure
aren't really going to change between
ground level and hovering at less than a
meter
however if you wanted to simulate how
high your mini drone could fly
then selecting the changing environment
will lower air pressure and air density
as it gets higher which will eventually
stall the drone
at some maximum altitude so choosing one
model
or another depends on what you're trying
to test for
okay lastly i want to go into the
sensors block
and well you've guessed it this is also
a variant subsystem
here we can select dynamic sensors with
noise or
feed through sensors we're going to
select the feed-through option for
tuning in the next video but for this
simulation we want our sensors to behave
as much like the real thing as possible
so inside this subsystem there are some
hard-coded sensor calibration data and a
block
called sensor system that houses the
models for the camera
the imu the ultrasound and the pressure
sensor
all right now at this point let's head
back up to the top level and run the
simulation so that i can show you what
the output looks like
this particular model is set up with a
3d visualization that renders the mini
drone based on the outputs from the
simulation
and just like in the last video we're
trying to get the mini drone to hover
about 0.7 meters above the ground and we
could check the simulation data and
compare it to the save data from the
actual test that we ran in the last
video
but in the interest of time let's just
compare them visually
i'll play the two results side by side
so we can see that this model is fairly
close to reality
at least for this one test condition
so now that we have a model that we like
we can use it for things like
safely simulating a failure and then
seeing how the system does
for example we can go back to the sensor
block and into the imu model
and change the gyro bias let's say that
we estimated the bias poorly and it's
really three times worse than we expect
now we can simulate the system and see
how our controller responds
it takes off just about the same but the
gyro bias
error quickly causes our drone to roll
away from level and then it just
runs away and eventually crashes into
the ground
so we've learned two things from this
one
if the gyro bias is three times worse
than we expect
the drone won't perform very well and
two if we're worried about being this
far off on estimating bias
then maybe we should change the stop
flag logic to recognize that we're
drifting away
and shut the drone down before we hurt
the hardware
alright now this was a fast walkthrough
but hopefully i've given you enough
information to review the model on your
own in more detail
or to start the process of creating your
own drone model
in the next video we're going to see how
we can use the linear version of this
model to tune the pid controllers
so if you don't want to miss the next
tech talk video don't forget to
subscribe to this channel
also if you want to check out my channel
control system lectures i cover more
control theory topics there as
well thanks for watching and i'll see
you next time