Drone Control and the Complementary Filter

Brian Douglas
5 Nov 201811:12

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

00:00

🤖 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.

05:01

🔍 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.

10:03

🛠 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

A complimentary filter is a type of sensor fusion algorithm that combines measurements from two different sensors to produce a more accurate and reliable output than either sensor could alone. In the context of the video, it's used to estimate the roll angle of a drone by blending data from an IMU's gyroscope and accelerometer. The filter is designed to leverage the short-term accuracy of the gyroscope and the long-term stability of the accelerometer, resulting in a more robust estimation of the roll angle.

💡Control System

A control system is a device or set of devices that manage, command, direct, or regulate the behavior of other devices or systems. In the video, the control system is discussed in the context of drone stabilization, where the complimentary filter is a part of the control system that helps in maintaining the drone's orientation by estimating its roll angle.

💡IMU (Inertial Measurement Unit)

IMU stands for Inertial Measurement Unit, which is a device that provides orientation and angular velocity feedback based on the sensor data from a three-dimensional accelerometer and a three-dimensional gyroscope. In the script, the IMU is used on a drone to estimate the roll angle, highlighting its importance in the field of robotics and aerospace for navigation and control.

💡Gyroscope

A gyroscope is a device used for measuring or maintaining orientation and angular velocity. In the video, the gyroscope within the IMU is used to sense the angular rate of the drone, which is then integrated over time to estimate the roll angle. The script emphasizes the importance of gyroscopes in short-term motion tracking but also mentions their susceptibility to drift over time.

💡Accelerometer

An accelerometer is a sensor that measures acceleration forces. It is used in the video to sense linear acceleration, including the acceleration due to gravity. By knowing the direction of gravity, the accelerometer can help determine the roll angle of the drone. The script explains that while accelerometers are noisy in the short term, they provide a stable long-term measurement of the gravity vector.

💡Roll Angle

The roll angle is the rotation of an object around its longitudinal axis. In the video, estimating the roll angle is the central problem being addressed. The script discusses how both the gyroscope and accelerometer can be used to estimate this angle, with the complimentary filter combining their measurements to achieve a more accurate estimation.

💡Dead Reckoning

Dead reckoning is a method of navigation that involves estimating one's current position based on a previously known position and factors such as speed, heading, and the time elapsed since the last known position. In the context of the video, dead reckoning is used to describe the process of integrating gyroscope measurements to estimate the roll angle over time. The script points out that while effective for short durations, cumulative errors can lead to significant inaccuracies in the estimated roll angle.

💡Low-Pass Filter

A low-pass filter is a type of filter that allows low-frequency signals to pass while attenuating high-frequency signals. In the video, a low-pass filter is used to process the accelerometer measurements, smoothing out the noise and providing a stable long-term estimate of the roll angle. The script explains how the low-pass filter is part of the complimentary filter's design to balance the short-term accuracy of the gyroscope with the long-term stability of the accelerometer.

💡High-Pass Filter

A high-pass filter is the opposite of a low-pass filter; it allows high-frequency signals to pass while reducing the amplitude of low-frequency signals. In the script, the high-pass filter is conceptually used in the complimentary filter to emphasize the short-term changes in the gyroscope measurements, complementing the low-pass filtered accelerometer data.

💡Sensor Fusion

Sensor fusion is the process of intelligently combining data from multiple sensors to achieve more accurate and reliable information than could be obtained from any individual sensor alone. The video script discusses the complimentary filter as an example of sensor fusion, where data from the IMU's gyroscope and accelerometer are combined to estimate the drone's roll angle more effectively.

💡Time Constant

In the context of filters, the time constant is a parameter that determines the filter's response time. A lower time constant results in a faster response, allowing more high-frequency content to pass through the filter. In the video, the time constant of the low-pass filter within the complimentary filter is discussed as a tuning parameter that affects the balance between the short-term accuracy of the gyroscope and the long-term stability of the accelerometer.

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

play00:00

welcome back to control system lectures

play00:02

in this video we're gonna talk about the

play00:04

complimentary filter it's such a dead

play00:07

simple filter which is a good reason to

play00:09

learn it but it's also practical because

play00:11

it produces nice results when blending

play00:13

measurements from two different sensors

play00:15

to understand how a complimentary filter

play00:17

works and the situations where it's

play00:19

useful we should set up a problem let's

play00:22

imagine we have a drone and we're trying

play00:24

to estimate the roll angle using its

play00:26

onboard inertial measurement unit or IMU

play00:28

the IMU has both a gyro that senses

play00:31

angular rate and an accelerometer that

play00:34

senses linear acceleration so the

play00:37

question is how can we measure the roll

play00:39

angle with the IMU now neither of these

play00:41

sensors can measure the roll angle

play00:43

directly however we can use either of

play00:46

them to estimate the roll angle let's

play00:48

look at how we would do that using just

play00:50

the gyro measurements if we assume that

play00:53

the roll angle is 0 degrees when the

play00:55

drone is sitting on the ground then

play00:56

after it takes off we can use the

play00:59

measured roll rates to calculate how the

play01:00

roll angle changes over time that is we

play01:04

can determine how far the drone has

play01:06

rotated in one time step and then add

play01:08

that value to the current estimate of

play01:10

roll angle for example if we read the

play01:12

gyro ten times a second and at the first

play01:15

time step the roll rate measures three

play01:17

degrees per second then after that time

play01:19

step or 0.1 seconds later we can

play01:22

estimate that the drone has rotated

play01:23

point three degrees we can then add that

play01:26

Delta angle to the current roll estimate

play01:28

then at the next time step we do it

play01:30

again and then again and again basically

play01:33

we are integrating the angular rate to

play01:35

get angles that's pretty straightforward

play01:37

right well this type of approach is

play01:40

called dead reckoning and it's very good

play01:42

for keeping track of motion over short

play01:43

periods of time

play01:44

how short well it depends on the noise

play01:47

and error characteristics of the gyro

play01:49

when we integrate the rate measurements

play01:51

any uncorrect at bias in the gyro or

play01:53

even just random high frequency noise

play01:56

gets summed as well and with these

play01:58

cumulative errors eventually there's

play02:00

going to be a large difference between

play02:02

the true roll angle and the angle we

play02:04

estimate dead reckoning is a relative

play02:07

measurement and there's no absolute

play02:08

measurement that will correct the roll

play02:10

over time

play02:13

now let's look at how to estimate role

play02:16

angle using the accelerometer gravity is

play02:19

always pointing down and near the

play02:21

surface of the earth that causes an

play02:23

acceleration of 1g let's imagine that

play02:26

the drone is sitting stationary on the

play02:27

ground and since there's no other

play02:29

accelerations acting on the drone the

play02:31

accelerometer will only be measuring the

play02:33

acceleration due to gravity now the

play02:35

drone knows which direction is down and

play02:38

knowing down relative to the drone

play02:40

reference frame it can determine the

play02:41

roll angle a simple way to do this is to

play02:44

just take the arctangent of the

play02:45

acceleration in the Y and z direction to

play02:48

get angle this measurement however isn't

play02:51

very precise in the short term because

play02:53

the accelerometer is also noisy but more

play02:56

importantly than that it measures all

play02:58

accelerations any time the drone

play03:00

accelerates in any direction the

play03:02

measurement is no longer just from

play03:03

gravity now we could ignore

play03:05

accelerations that are outside of some

play03:07

boundary but even really small

play03:09

accelerations can throw off the

play03:10

estimation of the down direction and

play03:12

then therefore the roll angle even

play03:14

rolling the drone will induce a linear

play03:16

acceleration if the IMU isn't located

play03:18

precisely at the center of rotation for

play03:21

these reasons it's hard to rely solely

play03:23

on the accelerometer for a short

play03:25

duration very quick roll measurements

play03:27

but the accelerometer is very stable

play03:30

long term because the gravity vector

play03:32

doesn't change over time the measurement

play03:35

of the gravity vector isn't wandering

play03:36

off like the rate-based roll angle did

play03:38

we may not want to trust it much at any

play03:41

given moment but at least we have an

play03:43

absolute understanding of which way down

play03:45

is over really long time scales so we

play03:48

have two different ways of determining

play03:50

the roll angle integrating the gyro

play03:52

which is more accurate over the short

play03:54

term and measuring the acceleration

play03:56

which is more accurate over the long

play03:58

term to let you visualize these two

play04:00

methods I created a simple JavaScript

play04:03

program that uses a noisy accelerometer

play04:05

and a noisy gyro to show you the

play04:07

direction the drone thinks is down with

play04:09

either method

play04:10

notice how the acceleration method is

play04:12

bouncing around more than the gyro both

play04:15

sensors have the same amount of noise

play04:17

but the gyro is integrated which

play04:19

attenuates high frequencies and makes it

play04:21

less jittery than the acceleration

play04:22

method so that smoothness makes it

play04:25

better over the short-term like

play04:27

we talked about but the gyro is slowly

play04:29

wandering around at times further than

play04:32

the accelerometer direction with these

play04:35

two estimates of roll angle from two

play04:36

different sensors we can now combine

play04:38

them using a complementary filter let me

play04:41

reset the values from the gyro and

play04:43

accelerometer sensors and add a third

play04:45

drone that uses a complimentary filter

play04:48

to estimate roll angle this filter needs

play04:51

to run for a little while for you to see

play04:52

the benefits so I'm just going to

play04:54

minimize this and go back to explaining

play04:56

what the complimentary filter is doing

play04:58

while it runs in the background

play05:01

complimentary in this sense means that

play05:03

we combine the two measurements in a way

play05:05

that complete each other or in other

play05:07

words we take some part of one

play05:08

measurement and add it to the

play05:10

complementary part of the other so that

play05:12

the sum of the two parts is still one

play05:14

whole measurement in our case we'd want

play05:17

to keep the short-term benefits of the

play05:18

gyro and add them to the long-term

play05:20

benefits of the accelerometer making

play05:23

these two parts complementary is easier

play05:25

than you might think if we pass the

play05:26

accel measurement through a low-pass

play05:28

filter G of s then the filter that we

play05:30

passed the gyro through is the high-pass

play05:32

filter 1 minus G of s since adding these

play05:36

two filters together equals 1 then

play05:38

they're complimentary of each other this

play05:40

is the basic complementary filter and G

play05:43

of s can be any filter you want like a

play05:45

notch filter or something and 1 minus G

play05:48

of s will be its complement however more

play05:50

often than not they are just the

play05:52

standard low-pass and high-pass filter

play05:54

now in our case with a rate sensor and

play05:57

accelerometer this block diagram isn't

play06:00

actually the way we would implement this

play06:02

filter because it would result in a lot

play06:03

of extra steps like integrating and

play06:05

filtering multiple signals that really

play06:07

just cancel out if we reduce this block

play06:10

diagram I'll show you what I mean with

play06:12

an example we'll use a first-order

play06:14

low-pass filter for the acceleration 1

play06:17

over tau s plus 1 this makes the high

play06:20

pass filter tau s over tau s plus 1 and

play06:22

since the integral is 1 over s we can

play06:26

cancel out those s's and then factor the

play06:28

low-pass filter 2 after the summing

play06:30

Junction and look at this we're no

play06:33

longer converting the rate measurements

play06:35

into angles at all we're just scaling it

play06:38

and then adding it to the acceleration

play06:39

angle

play06:40

and low-pass filtering the result to

play06:43

tune this filter we simply need to pick

play06:45

the time constant tau for the low-pass

play06:47

filter a lower tau raises the cutoff

play06:49

frequency and lets more Excel

play06:51

frequencies in and fewer gyro

play06:53

frequencies and a higher tau does the

play06:55

opposite now picking the ideal cutoff

play06:58

frequency depends on the noise

play06:59

characteristics of the two sensors and

play07:01

can be adjusted during simulation or

play07:03

tests all right no the continuous domain

play07:07

is a perfectly fine way to implement a

play07:09

complementary filter but since most

play07:11

control algorithms run on digital

play07:13

computers let's talk about a simple and

play07:15

intuitive way to implement a discreet

play07:17

filter that we can code in software

play07:19

let's start with the gyro measurement

play07:21

which were reading every time step we

play07:24

multiply this measurement by the length

play07:26

of time for one time step to get the

play07:28

angle traveled during that period now we

play07:31

can add this angle to the existing

play07:32

estimated roll angle I'm gonna explain

play07:35

where we get this in just a second at

play07:37

this point we have an updated roll

play07:39

estimate for the current time step from

play07:42

just the gyro but we also have another

play07:44

roll estimate from the accelerometer

play07:46

that we're also reading every time step

play07:48

we can combine these two angles by

play07:51

taking a fixed fraction of one and the

play07:54

complementary fraction of the other so

play07:57

for example we may take 98% of the gyro

play08:00

measurement and add that to 2% of the

play08:03

accel measurement so that ever so

play08:05

slightly were nudging the gyro angle in

play08:07

the acceleration direction this new

play08:10

angle is the estimated roll angle that

play08:12

we feedback at the next time step by

play08:15

believing the gyro more we're allowing

play08:17

the short-term speed and agility to make

play08:20

it through but we're nudging it back

play08:22

towards the absolute down direction over

play08:24

time to keep the angle from wandering

play08:26

off this is how we're getting the

play08:28

long-term stability of the accelerometer

play08:30

this is the algorithm that I implemented

play08:33

in my JavaScript example in fact let's

play08:36

check back in on that example and see

play08:38

how it's doing first off check out how

play08:41

well the complementary filter is holding

play08:43

close to the true down direction whereas

play08:46

the gyro has wandered off by 30 degrees

play08:48

or so and if you watch the motion of the

play08:50

complementary filter it's still moving

play08:53

back and forth in the same

play08:54

direction as the gyro getting those high

play08:56

frequencies passed through but it's just

play08:58

being pulled back by the excel which is

play09:01

hanging around the true down position

play09:02

this is the beauty of the complimentary

play09:05

filter

play09:09

all right so the question might be why

play09:12

does this implementation that we just

play09:14

walked through appear to work when there

play09:16

doesn't seem to be an obvious low pass

play09:18

or high pass filter well let's work

play09:21

through the math a bit and reduce this

play09:23

block diagram to see what we get

play09:24

now I'm sipping through this pretty

play09:26

quickly but if you pause the video you

play09:28

can follow along with the algebraic

play09:30

steps but the important part is that the

play09:32

first half of the resulting function is

play09:34

the summation of the scaled

play09:35

accelerometer and scaled rate

play09:37

measurements and the second half is a

play09:39

discrete low-pass filter so we're

play09:42

scaling the inputs summing them together

play09:44

and applying a low-pass filter and that

play09:48

is very similar to what we saw with the

play09:50

continuous domain implementation so

play09:53

that's pretty cool

play09:54

two different ways to implement a

play09:56

complimentary filter in one version we

play09:59

tuned it by adjusting the cutoff

play10:00

frequency and in the other we tuned it

play10:02

using the ratio of one signal versus the

play10:05

other now I hope this video helped you

play10:08

understand a bit more about

play10:09

complementary filters and has encouraged

play10:11

you to see if they will work for the

play10:12

control problems that you're working on

play10:14

it's nice when you can get away with

play10:16

simple filters like this because they're

play10:18

cheap from a computational perspective

play10:19

and they're easy to understand implement

play10:22

and tune if you have any questions or

play10:25

comments on this video please leave them

play10:27

below and I'll try to answer them if I

play10:28

can

play10:29

if you're interested in learning more

play10:30

about drone control and simulation check

play10:32

out my other videos on that topic on the

play10:35

MATLAB channel the link is in the

play10:36

description below and at the end of this

play10:38

video don't forget to subscribe so you

play10:40

don't miss any future videos on this

play10:42

channel and thanks for watching and a

play10:45

huge thank you to my patreon supporters

play10:47

for making this video possible if you'd

play10:49

like to support me in my efforts on

play10:50

YouTube you can go through the patreon

play10:52

link below for any amount of support you

play10:54

can download a digital copy of my book

play10:55

and progress on the fundamentals of

play10:57

control theory and if you just like a

play10:59

copy for free just email me at control

play11:01

system lectures at gmail.com and I'll

play11:04

send you the latest version that way we

play11:06

can spread the knowledge and help

play11:07

everyone on their quest to becoming

play11:08

better control system engineers thanks

play11:11

everyone

Rate This

5.0 / 5 (0 votes)

Related Tags
Control SystemsDrone IMURoll AngleGyro SensorAccelerometerDead ReckoningComplementary FilterSensor FusionSignal IntegrationControl TheoryEngineering Tutorial