loading

Step 15: IMU Part 2: Complementary Filter

My method of choice for combining the accelerometer and gyro signals into a clean and stable angle estimate is the Complementary Filter. It's computationally efficient and it directly addresses both transient horizontal acceleration and long-term gyro drift. The idea is to use the gyro for short term angle estimates, by numeric integration, but switch to the accelerometer for long-term estimates, by averaging. To do this in a continuous way, low-pass and high-pass filters are used. This is identical to the method I used in the Seg...stick Instructable, Step 10.

The image shows the a Complementary Filter in block diagram form. The sensor signals, converted to degrees and degrees per second, are the inputs. The accelerometer angle is low-pass filtered, reducing the influence of short-duration signals but maintaining a long-term average (from gravity).  The gyro angular rate is first integrated, to get an estimate of angle, and then high-pass filtered, to remove any long-term drift. The two filtered signals are summed together to create a single angle estimate that combines the best parts of both sensor signals.

It's one of the few cases where the code is more concise than the block diagram or the written explanation:

  // Excerpt from pd_digitalIMU.pde in 4pcb_ARD:
  // -------------------------------------------------------------------
  rate_pitch = (float) g_pitch * G_GAIN;
  angle_pitch = AA * (angle_pitch + rate_pitch * DT);
  angle_pitch += (1.0 - AA) * (float) a_pitch * A_GAIN;
  // -------------------------------------------------------------------

The first line converts the raw gyro signal, g_pitch, into º/s, as discussed in the previous Step. The end of the second line is the numeric integration. DT is the loop time, 0.01s. A small change in angle, rate_pitch * DT, is added to the previous angle estimate.

The rest of the second line and all of the third line form the high-pass and low-pass filters, in discrete form. The high-pass acts on the integrated angle estimate and the low-pass acts on the accelerometer signal, a_pitch. The constant AA determines the time scale of the high- and low-pass filters, and is a value you can tweak depending on your quadrotor. Larger AA trusts the integrated gyro signal for longer. Shorter AA merges the accelerometer signal in faster.

The value for AA used in 4pcb corresponds with a time constant of 1s. This is the approximate length of time for which the gyro angle estimate is trusted, and the approximate length of time over which the accerometer signal is averaged. Since these are infinite impulse-response (IIR) filters, the transition is smooth and continuous and the time constant only represents where the weighting of the two filters is equal.

I wrote up a more thorough explanation of the Complementary Filter as applied to self-balancing system in this white paper. It covers some of the details of how AA is related to the time constant of the low-pass and high-pass filters, how rate sensor bias affects the filter, and some more details.
<p>thank you .it was exellent</p>
<p>fantastic &lt;3 ^_^</p>
<p>It's a nice instructables!<br>I also want to build my own arduino-based quadcopter, but I have problems in controlling the motors.<br>Do you have your program saved somewhere, for example github or anything else? I really want to take a look at it for my reference, especially for implementing the PID Control<br>Thanks before!</p>
<p>Hi, your whitepaper link does not work. Do you have it saved elsewhere online? Would love to read it. Thanks!</p>
<p>I really enjoyed ;)</p>
<p>I really enjoyed. thankssssssss ;)</p>
<p>Great instructable. I have a quick question; in the schematic why did you use 0 ohm resistors and why are some components not meant to be placed( the parts you said DNP)? You could have excluded the parts you do not need.</p>
<p>Only Wow, this project is amazing! <br>(Frist sorry for my bad English) <br>I tried to adapt the code in my own quad to do it fly in x mode, but without success. The difference is that my IMU is turned 45 degrees compared to the project that there is here, the pitch of the IMU is at the center between the motors. This orientation of the IMU creates problems?<br>Thanks to the help and the patience. </p>
<p>good</p>
<p>super</p>
<p>found this blogspot by shane: http://scolton.blogspot.com/2011/08/something-like-flight.html. this particular blog about the control structure really helped me. the entire blog site, matter fact, is a gold mine of information. go check it out if you're also having trouble or would just like to see how amazing shane really is.</p>
<p>super</p>
<p>Would like to thank you man. Your balance filter theory helped us a lot get through our final undergraduate research last year. Worked better than any DCM or kalman filter code we ever wrote, probably because we understood your filter the most. I just got back to the hobby after a half-year lay-off, and just now remembered I should thank you for posting all these wonderful control information, without which I'm sure we would have all stayed grounded.</p>
mark !very cool
Great Instructable. I just have one question... In a video that was added its mentioned that activating the 12.5HZ low pass filter on the gyro really helped stability. After reading the datasheet on the gyro it says that there is a low pass filter but the sheet only gives instructions for controlling the High-Pass. Did you add a software filter or am I missing something on the datasheet?
It is a little unclear in the datasheet. Right above the High Pass settings, starting on p.29 of http://www.pololu.com/file/download/L3G4200D.pdf?file_id=0J491, there is a setting for &quot;DR and BW&quot; (data rate and bandwidth) which are the low-pass filter and output data rate settings. The lowest setting is 12.5Hz cut-off for the LPF. It's rather harsh, but it seemed to work better than 25Hz. If you could cut the vibration down a lot (by careful balancing of propellers and such), a higher frequency cutoff would be better.
how long this quadrotor can fly??
Flight time is about 8 minutes, depending on the size of the battery.
Hi, i think u did a great job. at least, i think it's a tall order for me. though i love href=&quot;http://www.rctophobby.com/rc-helicopters.html&quot;&gt;rc helicopters, i still knew <br>nothing about the details of the machine. however, after your presentation, i think i have a notice note about it. thanks for share it, good job!
Hi, i think u did a great job. at least, i think it's a tall order for me. though i love href=&quot;http://www.rctophobby.com/rc-helicopters.html&quot;&gt;rc helicopters, i still knew <br>nothing about the details of the machine. however, after your presentation, i think i have a notice note about it. thanks for share it, good job!
found this blogspot by shane: http://scolton.blogspot.com/2011/08/something-like-flight.html. this particular blog about the control structure really helped me. the entire blog site, matter fact, is a gold mine of information. go check it out if you're also having trouble or would just like to see how amazing shane really is. <br>
Hi shane. great work by the way. I've been trying to implement the same control structure in my own quad. My quad is way bigger than yours but I'm using the same IMU. My propellers are 10x4.5. I also use smaller ones which are 8x4.5 for testing. As such, I'm having a hard time determining what value to start my kp and kd constants at. I've been trying to tune for a month now and I haven't had a successful flight yet.
excellent project and videos. i saw a TED video of this a while back really wanted to do this. <br> <br>i am new to this so was wondering if there are any books/literature you would suggest to better how this particular system works as a whole and how each of its parts interact with each other? also, if one wanted the altitude feedback and return to horizontal position, would it be just as easy as rewriting some of the code for the Arduino board or would some extra hardware/electronics such as the gyros be required as well? Thanks!!
I don't know of any books in particular, but many of the links at the bottom of Step 1 have great information on the different components involved in multirotor systems. As written, the code already has &quot;return to horizontal&quot; capability (see Step 13), but if you wanted to add altitude hold, you would need some way of measuring absolute height, such as a barometer or ultrasonic distance sensor.
I'm surprised you got it so small and it could still carry its own battery. Nice work. <br>I'm working on a similar project with a much larger form factor (Turnigy Talon v1) and we're having massive trouble with vibration on our gyro. I have the picture of your foam mounting but I can't really tell how it's set up. Is the sensor board weighted and set on top of a foam loop, or is the gray foam wrapped around something? <br>Thanks.
The weighted IMU sat on top of the foam loop. <br> <br>I also have a Talon v1...it's a great frame. But yeah I haven't had much luck with mounting the controller or IMU directly to it. Some kind of isolation is needed.
In the schematic , Obviously where it says DNP is open circuit however where it lists the resistors as 0 is that meant to be a closed circuit. For example R18 is a direct connection from pin 15 to the 3 resistors but there is no cap to ground ?
Yes, all DNP and zero-ohm resistors are for configuring the various settings on the TB6588FG. They're either shorts or open-circuits. So you could use a solder bridge instead of an actual zero-ohm resistor.
I was about to ask if you were affiliated with MIT, then I noticed you were testing it in Building 7!
Congrats on the win! <br>You provide excellent specs on components. <br> <br>Bill
How did you choose your motors?
For this size quadrotor, there weren't many options. But in general, you would choose the motor and propeller at the same time. There are suggested propellers listed for most motors. Sometimes you can also find data on thrust/RPM/current values with different propellers. <br> <br>The total maximum thrust should be 2-3x greater than total weight, so that you have plenty of extra thrust available for maneuvering and stability. I think on this quad it was much closer to 1x when I was using the 7.4V battery. Switching to 11.1V made it closer to 2x, which improved the stability a lot.
Would this battery be a good choice for this quadrotor? <br> <br>http://www.hobbyking.com/hobbyking/store/__11895__Turnigy_nano_tech_370mah_3S_25_40C_Lipo_Pack.html
Yes, that's the exact one I used.
As of August, 2012, there is MinIMU-9 version 2. Did you use the version 1 or 2, and would the other one work with the quad just as well?
I'm using the version 1, but I think the version 2 would also work fine.
Allow me to be the first to congratulate you on the grand prize win! Well deserved!
Thank you! I'm glad people like it and I hope there will be swarms of PCB quadrotors in the near future.
guys i have an idea...see i wanted to build this but it is too expensive i mean like 300$? ya like ma parents are gonna give me that so i wanted to make the worlds most cheapest quadrocopter!!! and i really mean it ..in this one he used an xbee which is really expensive plus he didnt add the cost to make the transmitter so add another 50 to 100 bucks so total about less than 500$? <br />so i had abt module laying around so i thought hey why cant we make a bt quadrocopter instead of an r/c?(cheaper u can get two modules for like 15 $ at ebay one for transmitter and another for reciever <br /> <br />most probably ill make this one and maybe make an instructable for u guys <br /> <br />by the way awesome instructable(this) well explained well done!!!

About This Instructable

221,418views

661favorites

License:

More by scolton:PCB Quadrotor (Brushless) Seg...stick. 
Add instructable to: