Drone Control and the Complementary Filter
Summary
TLDRThis video lecture introduces the concept of a complementary filter, a simple yet effective tool for blending data from different sensors, particularly useful in drone control systems. It explains how to estimate the roll angle using an IMU's gyro and accelerometer, highlighting the strengths and limitations of each method. The video demonstrates how integrating gyro data over time can accumulate errors, while accelerometer readings offer long-term stability despite short-term noise. It then illustrates the implementation of a complementary filter that combines the short-term accuracy of the gyro with the long-term stability of the accelerometer, providing a practical solution for more accurate roll angle estimation.
Takeaways
- 📚 The video introduces the concept of a complementary filter, a simple yet effective method for blending measurements from two different sensors.
- 🛠 The context of the explanation is a drone trying to estimate its roll angle using an IMU (Inertial Measurement Unit), which includes a gyroscope and an accelerometer.
- 🔄 The gyroscope measures angular rates and can be used to estimate the roll angle by integrating these rates over time, a method known as dead reckoning.
- 📉 Dead reckoning is susceptible to cumulative errors due to the integration of noise and bias in the gyroscope measurements, leading to inaccuracies over time.
- 🌐 The accelerometer measures acceleration, including gravity, and can be used to determine the roll angle by calculating the arctangent of the acceleration in the Y and Z directions.
- 🔍 While accelerometer measurements are stable long-term due to the constant gravity vector, they are noisy and can be affected by any acceleration, not just gravity.
- 🤝 The complementary filter combines the short-term accuracy of the gyroscope with the long-term stability of the accelerometer to produce a more reliable roll angle estimate.
- 🧩 The implementation of the filter involves using a low-pass filter on the accelerometer measurements and a high-pass filter on the gyroscope measurements, or a simplified approach by scaling and combining the two measurements.
- ⚙️ The filter can be tuned by adjusting the time constant for the low-pass filter, which affects the balance between short-term agility and long-term stability.
- 📉 The video demonstrates the effectiveness of the complementary filter through a JavaScript program, showing how it maintains a closer estimate to the true roll angle compared to using either sensor alone.
- 🔧 The video also discusses the discrete implementation of the filter in software, which involves scaling the gyroscope and accelerometer measurements and applying a low-pass filter to the sum.
Q & A
What is a complimentary filter in the context of control systems?
-A complimentary filter is a simple yet effective method used to blend measurements from two different sensors, such as an IMU's gyro and accelerometer, to estimate a variable like the roll angle of a drone more accurately than either sensor could alone.
Why is the roll angle estimation using only a gyroscope prone to error over time?
-Estimating the roll angle using only a gyroscope is prone to error over time because the integration of the angular rate measurements accumulates any bias or noise in the gyro readings, leading to a growing discrepancy between the estimated and true roll angles.
How does an accelerometer help in estimating the roll angle of a drone?
-An accelerometer measures the linear acceleration, including the acceleration due to gravity. By knowing the direction of gravity relative to the drone's reference frame, the roll angle can be determined, although this method is less precise in the short term due to noise and other accelerations.
What is the main advantage of using a complementary filter over relying solely on either the gyroscope or the accelerometer?
-The main advantage of using a complementary filter is that it combines the short-term accuracy of the gyroscope with the long-term stability of the accelerometer, resulting in a more reliable and accurate estimation of the roll angle.
How does the script describe the behavior of the gyroscope and accelerometer measurements over time?
-The script describes the gyroscope measurements as being smooth and less jittery in the short term due to integration, but slowly wandering over time. In contrast, the accelerometer measurements are more stable long term because the gravity vector doesn't change, but are noisy and less reliable in the short term.
What is the purpose of the low-pass filter in the context of the complementary filter?
-The purpose of the low-pass filter in the complementary filter is to attenuate high-frequency noise and emphasize the long-term stability provided by the accelerometer, while still allowing some of the short-term agility from the gyroscope measurements.
How is the high-pass filter related to the low-pass filter in the complementary filter?
-In the complementary filter, the high-pass filter is the complement of the low-pass filter, meaning that if the low-pass filter is represented by G(s), the high-pass filter is represented by 1 - G(s). When combined, they sum up to 1, ensuring the integrity of the original measurements.
What is the significance of the time constant 'tau' in the low-pass filter of the complementary filter?
-The time constant 'tau' in the low-pass filter determines the cutoff frequency of the filter. A lower 'tau' allows more high-frequency content from the gyroscope, while a higher 'tau' emphasizes more low-frequency content from the accelerometer.
Can you explain the discrete implementation of the complementary filter as described in the script?
-The discrete implementation of the complementary filter involves scaling the gyroscope and accelerometer measurements, summing them, and then applying a low-pass filter. This is done at each time step, updating the roll angle estimate by taking a fixed fraction of the gyroscope measurement and a complementary fraction of the accelerometer measurement.
How does the script demonstrate the effectiveness of the complementary filter through a JavaScript program?
-The script uses a JavaScript program to simulate the behavior of the complementary filter, showing how it holds close to the true down direction, unlike the gyroscope which wanders off, and the accelerometer which is noisy. The program visually demonstrates the filter's ability to balance short-term agility and long-term stability.
Outlines
🤖 Introduction to Complementary Filters in Control Systems
This paragraph introduces the concept of a complementary filter within the context of control systems, specifically for a drone's roll angle estimation using an Inertial Measurement Unit (IMU). The IMU consists of a gyroscope for angular rate sensing and an accelerometer for linear acceleration. The paragraph explains the limitations of using either sensor alone due to noise and bias in gyro measurements or inaccuracies in accelerometer measurements during motion. It sets up the problem of estimating the roll angle and hints at the solution involving a blend of both sensor inputs.
🔍 Analyzing Roll Angle Estimation Methods
This section delves deeper into the two methods for estimating the roll angle: using gyro measurements through dead reckoning and using accelerometer measurements based on gravity. It discusses the advantages and disadvantages of each method, highlighting the short-term accuracy of the gyro and the long-term stability of the accelerometer. The paragraph also introduces a JavaScript program to visually demonstrate the noise and stability issues of both methods, leading to the necessity of a complementary filter that combines the strengths of both sensors.
🛠 Implementing the Complementary Filter
The paragraph explains the implementation of a complementary filter that blends the short-term accuracy of the gyro with the long-term stability of the accelerometer. It describes the process of using low-pass and high-pass filters to create a filter that enhances the strengths of each sensor while compensating for their weaknesses. The explanation includes a mathematical breakdown of the filter's operation in both continuous and discrete domains, illustrating how the filter can be adjusted for optimal performance and how it is applied in practice through a software algorithm.
📚 Conclusion and Further Resources
In conclusion, the paragraph summarizes the benefits of using complementary filters for control problems, emphasizing their simplicity, computational efficiency, and ease of implementation and tuning. It invites viewers to ask questions or leave comments and promotes further learning through related videos on drone control and simulation available on the MATLAB channel. The paragraph also acknowledges Patreon supporters and offers a way for viewers to support the creator's work, including the option to download a digital copy of a book on control theory fundamentals.
Mindmap
Keywords
💡Complimentary Filter
💡Control System
💡IMU (Inertial Measurement Unit)
💡Gyroscope
💡Accelerometer
💡Roll Angle
💡Dead Reckoning
💡Low-Pass Filter
💡High-Pass Filter
💡Sensor Fusion
💡Time Constant
Highlights
Introduction to the complimentary filter, a simple yet effective method for blending measurements from two different sensors.
The practical application of the complimentary filter in estimating the roll angle of a drone using its IMU.
Explanation of how to measure the roll angle using gyro and accelerometer readings from an IMU.
Dead reckoning method for estimating roll angle by integrating angular rate measurements over time.
Limitations of dead reckoning due to cumulative errors from noise and bias in gyro measurements.
Utilizing the accelerometer to measure the roll angle based on the gravity vector pointing downwards.
Challenges in using accelerometer for roll angle estimation due to noise and external accelerations.
The stability of the accelerometer for long-term roll angle estimation as gravity vector remains constant.
Visual demonstration of the complimentary filter's effectiveness using a JavaScript program with noisy sensors.
The concept of combining short-term accuracy of the gyro with the long-term stability of the accelerometer.
Technical explanation of the complimentary filter implementation using low-pass and high-pass filters.
Adjusting the time constant tau to tune the filter's balance between short-term and long-term accuracy.
Discrete implementation of the complimentary filter in software for digital control algorithms.
Algorithm explanation for combining gyro and accelerometer measurements to estimate the roll angle.
Demonstration of the complimentary filter's performance in maintaining the true down direction compared to individual sensors.
Mathematical breakdown of the discrete complimentary filter implementation and its similarity to the continuous domain approach.
The simplicity and computational efficiency of using the complimentary filter for control system applications.
Invitation for questions, comments, and further exploration of drone control and simulation topics.
Acknowledgment of Patreon supporters and offer to download a digital copy of the book on control theory fundamentals.
Transcripts
welcome back to control system lectures
in this video we're gonna talk about the
complimentary filter it's such a dead
simple filter which is a good reason to
learn it but it's also practical because
it produces nice results when blending
measurements from two different sensors
to understand how a complimentary filter
works and the situations where it's
useful we should set up a problem let's
imagine we have a drone and we're trying
to estimate the roll angle using its
onboard inertial measurement unit or IMU
the IMU has both a gyro that senses
angular rate and an accelerometer that
senses linear acceleration so the
question is how can we measure the roll
angle with the IMU now neither of these
sensors can measure the roll angle
directly however we can use either of
them to estimate the roll angle let's
look at how we would do that using just
the gyro measurements if we assume that
the roll angle is 0 degrees when the
drone is sitting on the ground then
after it takes off we can use the
measured roll rates to calculate how the
roll angle changes over time that is we
can determine how far the drone has
rotated in one time step and then add
that value to the current estimate of
roll angle for example if we read the
gyro ten times a second and at the first
time step the roll rate measures three
degrees per second then after that time
step or 0.1 seconds later we can
estimate that the drone has rotated
point three degrees we can then add that
Delta angle to the current roll estimate
then at the next time step we do it
again and then again and again basically
we are integrating the angular rate to
get angles that's pretty straightforward
right well this type of approach is
called dead reckoning and it's very good
for keeping track of motion over short
periods of time
how short well it depends on the noise
and error characteristics of the gyro
when we integrate the rate measurements
any uncorrect at bias in the gyro or
even just random high frequency noise
gets summed as well and with these
cumulative errors eventually there's
going to be a large difference between
the true roll angle and the angle we
estimate dead reckoning is a relative
measurement and there's no absolute
measurement that will correct the roll
over time
now let's look at how to estimate role
angle using the accelerometer gravity is
always pointing down and near the
surface of the earth that causes an
acceleration of 1g let's imagine that
the drone is sitting stationary on the
ground and since there's no other
accelerations acting on the drone the
accelerometer will only be measuring the
acceleration due to gravity now the
drone knows which direction is down and
knowing down relative to the drone
reference frame it can determine the
roll angle a simple way to do this is to
just take the arctangent of the
acceleration in the Y and z direction to
get angle this measurement however isn't
very precise in the short term because
the accelerometer is also noisy but more
importantly than that it measures all
accelerations any time the drone
accelerates in any direction the
measurement is no longer just from
gravity now we could ignore
accelerations that are outside of some
boundary but even really small
accelerations can throw off the
estimation of the down direction and
then therefore the roll angle even
rolling the drone will induce a linear
acceleration if the IMU isn't located
precisely at the center of rotation for
these reasons it's hard to rely solely
on the accelerometer for a short
duration very quick roll measurements
but the accelerometer is very stable
long term because the gravity vector
doesn't change over time the measurement
of the gravity vector isn't wandering
off like the rate-based roll angle did
we may not want to trust it much at any
given moment but at least we have an
absolute understanding of which way down
is over really long time scales so we
have two different ways of determining
the roll angle integrating the gyro
which is more accurate over the short
term and measuring the acceleration
which is more accurate over the long
term to let you visualize these two
methods I created a simple JavaScript
program that uses a noisy accelerometer
and a noisy gyro to show you the
direction the drone thinks is down with
either method
notice how the acceleration method is
bouncing around more than the gyro both
sensors have the same amount of noise
but the gyro is integrated which
attenuates high frequencies and makes it
less jittery than the acceleration
method so that smoothness makes it
better over the short-term like
we talked about but the gyro is slowly
wandering around at times further than
the accelerometer direction with these
two estimates of roll angle from two
different sensors we can now combine
them using a complementary filter let me
reset the values from the gyro and
accelerometer sensors and add a third
drone that uses a complimentary filter
to estimate roll angle this filter needs
to run for a little while for you to see
the benefits so I'm just going to
minimize this and go back to explaining
what the complimentary filter is doing
while it runs in the background
complimentary in this sense means that
we combine the two measurements in a way
that complete each other or in other
words we take some part of one
measurement and add it to the
complementary part of the other so that
the sum of the two parts is still one
whole measurement in our case we'd want
to keep the short-term benefits of the
gyro and add them to the long-term
benefits of the accelerometer making
these two parts complementary is easier
than you might think if we pass the
accel measurement through a low-pass
filter G of s then the filter that we
passed the gyro through is the high-pass
filter 1 minus G of s since adding these
two filters together equals 1 then
they're complimentary of each other this
is the basic complementary filter and G
of s can be any filter you want like a
notch filter or something and 1 minus G
of s will be its complement however more
often than not they are just the
standard low-pass and high-pass filter
now in our case with a rate sensor and
accelerometer this block diagram isn't
actually the way we would implement this
filter because it would result in a lot
of extra steps like integrating and
filtering multiple signals that really
just cancel out if we reduce this block
diagram I'll show you what I mean with
an example we'll use a first-order
low-pass filter for the acceleration 1
over tau s plus 1 this makes the high
pass filter tau s over tau s plus 1 and
since the integral is 1 over s we can
cancel out those s's and then factor the
low-pass filter 2 after the summing
Junction and look at this we're no
longer converting the rate measurements
into angles at all we're just scaling it
and then adding it to the acceleration
angle
and low-pass filtering the result to
tune this filter we simply need to pick
the time constant tau for the low-pass
filter a lower tau raises the cutoff
frequency and lets more Excel
frequencies in and fewer gyro
frequencies and a higher tau does the
opposite now picking the ideal cutoff
frequency depends on the noise
characteristics of the two sensors and
can be adjusted during simulation or
tests all right no the continuous domain
is a perfectly fine way to implement a
complementary filter but since most
control algorithms run on digital
computers let's talk about a simple and
intuitive way to implement a discreet
filter that we can code in software
let's start with the gyro measurement
which were reading every time step we
multiply this measurement by the length
of time for one time step to get the
angle traveled during that period now we
can add this angle to the existing
estimated roll angle I'm gonna explain
where we get this in just a second at
this point we have an updated roll
estimate for the current time step from
just the gyro but we also have another
roll estimate from the accelerometer
that we're also reading every time step
we can combine these two angles by
taking a fixed fraction of one and the
complementary fraction of the other so
for example we may take 98% of the gyro
measurement and add that to 2% of the
accel measurement so that ever so
slightly were nudging the gyro angle in
the acceleration direction this new
angle is the estimated roll angle that
we feedback at the next time step by
believing the gyro more we're allowing
the short-term speed and agility to make
it through but we're nudging it back
towards the absolute down direction over
time to keep the angle from wandering
off this is how we're getting the
long-term stability of the accelerometer
this is the algorithm that I implemented
in my JavaScript example in fact let's
check back in on that example and see
how it's doing first off check out how
well the complementary filter is holding
close to the true down direction whereas
the gyro has wandered off by 30 degrees
or so and if you watch the motion of the
complementary filter it's still moving
back and forth in the same
direction as the gyro getting those high
frequencies passed through but it's just
being pulled back by the excel which is
hanging around the true down position
this is the beauty of the complimentary
filter
all right so the question might be why
does this implementation that we just
walked through appear to work when there
doesn't seem to be an obvious low pass
or high pass filter well let's work
through the math a bit and reduce this
block diagram to see what we get
now I'm sipping through this pretty
quickly but if you pause the video you
can follow along with the algebraic
steps but the important part is that the
first half of the resulting function is
the summation of the scaled
accelerometer and scaled rate
measurements and the second half is a
discrete low-pass filter so we're
scaling the inputs summing them together
and applying a low-pass filter and that
is very similar to what we saw with the
continuous domain implementation so
that's pretty cool
two different ways to implement a
complimentary filter in one version we
tuned it by adjusting the cutoff
frequency and in the other we tuned it
using the ratio of one signal versus the
other now I hope this video helped you
understand a bit more about
complementary filters and has encouraged
you to see if they will work for the
control problems that you're working on
it's nice when you can get away with
simple filters like this because they're
cheap from a computational perspective
and they're easy to understand implement
and tune if you have any questions or
comments on this video please leave them
below and I'll try to answer them if I
can
if you're interested in learning more
about drone control and simulation check
out my other videos on that topic on the
MATLAB channel the link is in the
description below and at the end of this
video don't forget to subscribe so you
don't miss any future videos on this
channel and thanks for watching and a
huge thank you to my patreon supporters
for making this video possible if you'd
like to support me in my efforts on
YouTube you can go through the patreon
link below for any amount of support you
can download a digital copy of my book
and progress on the fundamentals of
control theory and if you just like a
copy for free just email me at control
system lectures at gmail.com and I'll
send you the latest version that way we
can spread the knowledge and help
everyone on their quest to becoming
better control system engineers thanks
everyone
Weitere verwandte Videos ansehen
![](https://i.ytimg.com/vi/0rlvvYgmTvI/hq720.jpg)
Understanding Sensor Fusion and Tracking, Part 2: Fusing a Mag, Accel, & Gyro Estimate
![](https://i.ytimg.com/vi/Df0vq2jz5Ws/hq720.jpg)
ACCOUNTANT EXPLAINS: Should You Buy, Lease or Finance a New Car
![](https://i.ytimg.com/vi/hN8dL55rP5I/hq720.jpg)
Understanding Sensor Fusion and Tracking, Part 3: Fusing a GPS and IMU to Estimate Pose
![](https://i.ytimg.com/vi/4G9nXBjZ58c/hq720.jpg)
MES 5 OUTILS LES PLUS RENTABLES 💶 🧐
![](https://i.ytimg.com/vi/2Ad0g80F9PA/hq720.jpg)
Climate and weather | Global air circulation | Grade 12 Geography INTRODUCTION |Thundereduc|
![](https://i.ytimg.com/vi/3vdzghRCprU/hq720.jpg)
Como memorizar ABSOLUTAMENTE TUDO
5.0 / 5 (0 votes)