In the last video I showed that we can manipulate the four motors of a
quadcopter to maneuver it in 3d space by getting it to roll pitch yaw and change
its thrust we also covered the four sensors that we have at our disposal to
estimate the system States now in this video we're going to use that knowledge
to design a control system architecture for hovering a quadcopter that means
we're gonna figure out which states we need to feedback
how many controllers we need to build and how those controllers interact with
each other I'm Brian and welcome to a MATLAB Tech Talk in the control system
we're developing the plant is the mini drone itself it takes four motor speeds
as inputs which then spin the propellers generating forces and torques that
affect the output state the output that we want is to have the mini drone hover
at a fixed altitude so the question becomes how do we command these four
motors autonomously so that that happens well to start let's assume that rather
than do it autonomously we want to command the mini drone manually that is
we have a remote control with toggles that directly control all four motor
speeds the left toggle would control the two front motors and the right toggle
would control the two rear motors this puts you in the feedback path because
you can see where the drone is and then react to its position and attitude by
moving the four toggles in very specific ways if you want to increase thrust
you'd speed up all four motors by moving the two toggles in this direction yaw
requires that two opposing motors increase their speed and the other two
decrease speed so that yang left for example would require this kind of
toggle motion then to roll the vehicle you would need to increase one of the
left/right pairs and decrease the other and to pitch the vehicle you would
increase one of the front back pairs and decrease the other in this way you as
the feedback controller could get the drone to hover by expertly changing the
commands to these four motors now while this is possible thinking in terms of
motor speed seems really hard and we want to make our job easier
so instead we can use the motor mixing algorithm that we created in the last
video and command thrust roll pitch and yaw directly
when we command thrust for example this single thrust command gets split evenly
to all four motors the yaw command is distributed positive to two motors and
negative to the other two and so on now our remote-controlled toggles are
aligned with the intuitive roll pitch yaw and thrust rather than the
mind-bending motor speeds this is the controller configuration that a lot of
operators use when manually flying their quad copters but it turns out thinking
in terms of roll pitch yaw and thrust is also beneficial when we're developing an
autonomous control system so we'll keep the motor mixing algorithm and build a
feedback control system with it in the loop as well all right let's get rid of
the human operator and think about how we can accomplish the same thing
autonomously we'll start by focusing on the thrust
command thrust is always in the same direction relative to the drone airframe
it's along the z axis of the mini drone that means that if the drone is flying
level and the z axis is aligned with the gravity vector then increasing thrust
causes the drone to increase its altitude rate which is how fast it's
rising and decreasing thrust drops the altitude rate and that's pretty
straightforward however if our drone is flying at a steep pitch or roll angle
then increasing thrust is coupled to both altitude rate and horizontal speed
therefore if we're building a controller for a racing drone that's likely to fly
at extreme roll and pitch angles then we need to take this coupling into account
however for our simple hover controller I'm just going to assume that the roll
in pitch angles are always really small in this way changing the thrust only
meaningfully impacts altitude rate and nothing else so with this information we
can start our control design to begin let's build a controller that uses
thrust to adjust the altitude if we're able to measure the drone altitude then
we can feed it back to compare it to an altitude reference the resulting error
is then fed into an altitude controller that's using that information to
determine how to increase or decrease thrust for now we can think of this
controller has some form of a PID controller and we're going to talk about
how to tune it in future videos in this sea
so with this controller if the drone is hovering too low the altitude error will
be positive and the thrust command will increase causing all four motors to
speed up at the same time and the drone will rise if the drone is too high then
all four motors will slow down so that the drone will descend so that's it
right our job is done we've developed a simple altitude controller which will
hover our mini drone and it's perfect except that you know that that's not the
case because there are disturbances like wind gusts that will induce a little
roll or pitch into the system and when that happens the thrust will not only
adjust altitude but also create some horizontal motion and the drone will
start to move away from you and what good is a hover controller that
maintains altitude but requires you to chase after it or it'll crash into walls
that's hardly hovering nope we clearly need a better control system
architecture and we should start by trying to maintain level flight by
controlling roll and pitch angles to 0 degrees if we can keep the mini drone
level then thrust once again will only impact altitude and the drone won't
wander away now we know from the last video that we're able to command thrust
roll pitch and yaw independently that is we can command one action without
affecting the others knowing this we can create three more feedback controllers
one for roll pitch and yaw exactly the same way that we did for thrust now to
give us a little more room I'm going to redraw the block diagram and we'll
condense the motor mixing algorithm block to just say MMA now the output of
the plant is more than just altitude we're also going to need to measure or
estimate the roll pitch and yaw angles as well and I'm gonna feed all of the
system States back and then label which state I'm using for each controller so
hopefully this all makes sense to you I'm feeding the estimated roll angle
into the roll controller and the estimated yaw angle into the controller
and so on alright so now what do we have well we have four independent or
decoupled controllers one for thrust which is really an altitude controller
since we're claiming small role in pitch angles and then three controllers that
are trying to zero degrees in roll pitch and yaw
respectively this should maintain altitude and it should keep the mini
drone facing forward and level with the ground now this is obviously a better
hover controller than our first one but again it's still not perfect to
understand why let's play our hypothetical wind gust through this
system now the wind might initially introduce a little roll angle but our
roll controller will remove that error and get the drone back to level flight
however for a very brief time during the roll the thrust vector is not straight
up and down and therefore the drone will have moved horizontally a little bit
then another gust comes and causes another roll or pitch error and the
drone walks away a little bit more so even though the drone won't run away
continuously like our first controller this controller will still allow it to
meander away slowly there's nothing in our control system architecture that
will bring the drone back to its starting position let's improve this
control system to do just that I'm going to once again clean up our block diagram
to make some room for additional control logic okay now that we have a little
room let's think about what role and pitch are doing while hovering it's
tempting to say that both angles should be zero and that's how we set up this
current version of the controller however they may need to be nonzero in
order to hover for example if we want to hover in a strong constant wind then the
drone will have to lean into the wind at some angle to maintain its ground
position so rather than specifying that we want level flight really what we need
is a ground position controller something that will recognize when the
drone is wandering off and make the necessary Corrections to bring it back
to the reference point x and y but just because we don't want to pick specific
role in pitch angles that doesn't mean that we don't need the roll in pitch
controllers remember from the first video that a quadcopter is incapable of
moving left right forward or backward without first rolling or pitching into
the desired direction of travel so our control system needs to couple position
errors with roll and pitch and this is a complicated sounding set
of maneuvers but luckily the resulting controller is pretty simple to
understand we can feedback the mini-drones measured XY position and
compare it to the reference to get the position error for now we'll say that
the reference position is zero zero this way our controller will cause the drone
to hover right above the take-off point now our position controller takes the
position error as an input and then outputs roll and pitch angles these are
the reference angles that are role in pitch controllers are trying to follow
so instead of us as the designer picking roll and pitch angles we're letting the
position controller create them for us in this way the position controller is
the outer loop and it's generating the reference commands for the inner loop
roll and pitch controllers these are cascaded loops now as a quick side note
the measured yaw angle also feeds into the position controller the reason very
briefly is that the XY position error is relative to the ground or the world
reference frame whereas roll and pitch are relative to the body of the drone
therefore pitch doesn't always move the drone in the ex-world direction and roll
doesn't always move the drone in the Y world direction it depends on how the
drone is rotated or its yaw angle so if we need to move the drone to a very
specific spot in the room then it needs to know yo in order to determine whether
roll pitch or some combination of the two is needed to achieve that so our
position controller uses Yod to convert between the world XY frame and the body
XY frame all right let's walk through a thought exercise to see how all of these
controllers work together to maintain position and altitude let's say that the
mini drone is flying level at the correct altitude but a little too far
left of where it took off this will result in a position error that feeds
into the position controller the proportional part of the controller will
multiply that error by a constant which will request that the drone roll to the
right the role controller will see that there is a roll error because the drone
is still level and request a rolling torque this will
play through the motor mixing algorithm and request that the motors on the left
side of the drone speed up and the motors on the right side slowed down
this will roll the drone to the commanded angle now the drone will begin
to move to the right but since the vertical component of
thrust is slightly smaller when rolled the drone will also start to lose
altitude the altitude controller will sense this error and increase the thrust
command accordingly now as the drone continues moving right the position
error is dropping and therefore the requested roll angle through the
proportional path is also dropping bringing the drone back level this is
now a good architecture for our hover control system but there are two glaring
obstacles to creating and tuning it first this requires us having a way to
estimate the state's yaw roll pitch altitude and XY position these are the
signals that were feeding back into our controllers and second we need to tune
six PID controllers that all interact with each other and specifically four of
them directly coupled in cascaded loops the way we're going to handle the first
problem is by combining the measurements from the four sensors we have and in
some cases using a model and a common filter to estimate each of those
feedback States for the second problem we need a good model of our system so
that we can use model-based design and MATLAB and Simulink to tune our six PID
controllers in fact if we just look at the controller portion of this feedback
system you can see that the Simulink model has pretty much the exact same
controller architecture that we've built in this video the outer loop XY position
controller is generating the reference pitch and roll angles for the inner loop
controller there's also the yaw and altitude controllers in each of them
feed into the motor mixing algorithm in the next video we're going to leave the
world of concepts and drawings and move over to Simulink to build the actual
software for this control system and model the plant and environment dynamics
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 they
as well thanks for watching and I'll see you next time