* The accelerometer data is very noisy. I'm not sure he's using proper anti-aliasing filters.
* The X&Y accel data is certainly not constantly zero as the "theory" would have it. What I think is happening is this: as the quad is commanded to rotate, one motor increases its RPM, resulting in much more noise in the X&Y channels (but not as much in the Z axis for some reason).
* Having said that, after analyzing the spectrum of the data via FFT tools, I am seeing a significant low frequency component that is present in both the gyro signal and the X&Y accel signals, which could mean that the accels are responding to the tilt (but it could mean other things, like both signals are responding to some other stimulus, or aliasing from the motor, or just that the "noise" from the faster-turning rotors is correlated with the tilt.
* I do plan on running the data through a low-pass filter, to see if cleaning up the "noise" shows me anything.
Also, I emailed my question to Dr. Robert Mahony (whom Bill Premerlani credits with the basic concept used in the DCM algorithm). Dr Mahony wrote back "This one twists my brain also. Firstly - the complementary filters work extremely well - so there must be an explanation." Interesting (and somewhat disheartening) to see that even the experts are scratching their heads! But he then goes on to say that, on average, the thrust vector has to match the gravity vector, as long as the vehicle is mostly hovering. So I think he's acknowledging that the accels are only reading the thrust vector.
There is an explanation to the apparent paradox that accelerometers measure aerodynamic forces, yet they are used to determine which way is down.
The 3 axis accelerometer on the UAV DevBoard is a typical accelerometer. I have verified that it measures the gravity vector minus the instantaneous acceleration vector of the accelerometer with respect to the earth measured in the frame of reference of the accelerometer.
If you work the math and physics on that, you can show that the net result is that when it is mounted in an aircraft that is in the air, the accelerometer measures the instantaneous negative of the total aerodynamic forces on the aircraft, divided by the mass of the aircraft. So, from the point of view of instantaneous values, the folks are correct who say that accelerometers cannot tell you which way is down. An accelerometer only tells you the instantaneous direction of the total of all aerodynmic forces on the aircraft, including such things as lift, drag, thrust, side-slipping forces, etc. That is why you cannot use an accelerometer by itself to control the roll and pitch of an airplane or a helicopter. It just will not do the job.
Yet, the combination of gyros and accelerometers work just fine in practice, for both helicopters and planes. I have been using them for 5 years to keep my planes very level, and have helped JohnMac to use them to level his helicopter.
So, this raises the question, what happens? How can the accelerometer be of any use? What is the explanation?
The key is to use the gyros for continual instantaneous estimates of attitude, and to use the accelerometers only for long time drift correction of the gyros. Use the gyros to control roll and pitch. Use the accelerometers to lock the gyros.
The reason that you can do that is because for gyro drift correction, it is not the instantaneous value of the accelerometer output that is relevant, it is the average value that is important. For example, in the DCM algorithm, the PI feedback gains are very low for the gyro drift correction. The integral term allows an absolute lock with no residual drift, even with low gains. Therefore the drift correction does not respond to the instantaneous response of the accelerometer, it responds to the average response of the accelerometer. So, instead of thinking about the instantaneous aerodynamic forces, you need to think about the average values.
On average, the aerodynamic forces on any body supported only by the air, such as an airplane, a helicopter, a person, or a rock, will be equal and opposite to gravity. That is because the body will, on average, accelerate downward, generating increases aerodynamic forces, until it reaches equilibrium. It will work even for a rock in free fall. Eventually a rock reaches terminal velocity. The only external, inexorable, continual force on an aircraft is gravity. There are no continual external later forces. Therefore, as long as the aircraft is in the air, the average aerodynamic force on it must be vertically upward.
Since the measurement is made in the aircraft frame of reference, you do need to worry about centrifugal effects if the aircraft makes a steady turn, but that is easy to correct for.
If you have a GPS on board, you can go one step better. Since the GPS will give you 3 dimensional velocity, you can differentiate that to obtain (nearly) instantaneous acceleration, which you can add to the accelerometer output (gravity minus acceleration) to get gravity.
So the bottom line is that accelerometers measure the total of aerodynamic forces, divided by the mass of the aircraft, which on average must be equal and opposite to gravity.
By the way there is another interesting way to look at it, using a thought experiment. If you weigh a box with a bird in it, the weight that you measure will be the same whether the bird is sitting on the bottom of the box, or flying around inside the box. You will measure the total of the weights of the box and the bird. Also, no matter what the bird does inside the box, it cannot transmit an average sideways force to the box.
Looking at the data, it all looks correct. The noise levels are pretty close to each other. Noise happens.
Hovering things are kind of easier to think about than normal aircraft I think. Bills note looks right, here is another thought experiment:
Put your quadcopter on the table (like one set of data you show) with nothing spinning. You see the Z accel measuring the force of the table acting on it and countering gravity. You see no X/Y accel because it isn't moving. Remember, the table / ground exerts a force on your unit to keep it stationary despite gravity trying to pull it.
Now turn the motors on but don't lift the thing off the ground. Things get noisy, but it is still pretty much Z (big signal), X/Y zero with noise. The bias might shift a little, but these are probably MEMs.
Now hover. Your quadcopter is flying with no X/Y/Z displacement motion at all. Imagine that someone draws an imaginary table underneath the unit. Looks like the last case. So Z signal shows 1 g, x/y are zero bias with some noise.
The copter isn't accelerating in X or Y. It also isn't accelerating in Z. It is motionless, as if it is on the table. But the only thing countering gravity in this case is the thrust from the props. They have taken the place of the force exerted by the table. So you will read 1g on Z, X and Y are zero.
I completely agree with you and Dr. Mahony that flying vehicles are, on average (that is, in a low-frequency sense) not accelerating (i.e. the second derivative of the position vector is zero). Hence accelerometers can be used to determine the gravity vector in this low-pass filter sense.
My question (and you'd have to go back to the original blog post to see it) is this: in a quadrotor, will the x and y accelerometers be able to register the components of the gravity vector at all? I think the answer is no. In a quadrotor, the only source of aerodynamic forces are the rotors, which are always aligned with the z-axis. In a fixed-wing aircraft, this is not the case. You could use (suitably filtered) accelerometer readings to determine, for example, the pitch attitude of the vehicle (roll attitude is a little different since during steady turns to vehicle is actually accelerating, but as you say this can be compensated for). Even a helicopter is different, in that rotor flapping will result in forces that are not aligned with the z-axis.
However, I think the concept still works for the quad since if the attitude is non-zero the quad is accelerating. I would like to try replacing the accelerometer inputs to the attitude routine with zero, to see if it makes any difference. The only time this scheme would not work is if the quad is moving at a constant non-zero airspeed. In this case, the quad would need to tilt slightly to overcome drag, and the accels could be used to sense gravity (and the x and/or y axis accels would be non-zero). I suspect the drag would be low enough that we would not be able to distinguish the x or y readings from noise. Also, quads probably don't spend a lot of time flying at a steady airspeed.
It wasn't quite the right question (see my response to Bill above). Thanks for looking at the data. My concern was that the accelerometers might not be filtered well enough and that we were getting aliasing. I have not concluded that for a fact (I do not know what the rotor speeds actually were)
That makes it more clear what you were asking. Do the thought experiment again but tilt the unit. It still works. Your X and Y sensors will measure the tilt of the craft, they are just noisy. A 10 degree tilt is only about 2/10ths of a g (sin 10 = 0.1736). So if your noise is 1/2 a g spiky, its hard to see it, but it is there. Like Bill said, using rate sensors to update pitch / roll attitude in the short term, coupled with corrections to their bias in the long term with accelerometers works.
Actually, I don't think it works the way you think it does. Read through the original blog post and the many comments if you care to - the question is more complicated than it may seem at first. Draw or imagine the free body diagram of the quadrotor. There are only 3 force sources that we care about: rotor thrust, drag, and gravity. The accelerometer doesn't register gravity, so that leaves the other two. Drag (I'm guessing) is pretty small, so the overwhelming force component is from the rotors, which is always in the z-axis direction. X and Y axis sensors just measure "noise" from rotor vibration, thermal sources, sensor mis-alignment with the vehicle c.g. etc., but nothing useful in terms of estimating the body attitude.
If you see something different in the data, or if you have a better theory, then please let me know. As I said, I see energy in the x and y sensors that is of the same frequency as energy on the gyro signal, but I'm not yet convinced of the cause and effect relationship there.
You're right, the accel doesn't measure gravity, but in steady flight it measures the acceleration from other sources that keep it steady in the gravitational field. If you aren't accelerating (back to my discussion about the unit sitting on the ground), then you register 1 g. This 1 g is the ground exerting a force that counters gravity on your copter. Tilt it anyway you like, the vector sum of the three axes will be 1 g. Find a magic way of keeping it hovering with no acceleration (in any orientation) and you will see the same thing. When it tilts and moves, it experiences a transient acceleration, then it reaches steady state velocity due to other forces and you are back to the same scenario...your accels should root sum square to 1 g. Finding the vector angles between them gives you your atittude vectors.
If your unit is tilted a little (lets say 10 degrees) and the rotors are fixed to that body frame, and you have set the throttle for the rotors to keep the copter at a fixed altitude, then the vehicle will be moving forward at a constant speed. This speed is the result of the rotor thrust * sin (pitch angle) balanced by the drag force in that direction. Yes, this is small, it is approximately your forward velocity squared times some drag coefficent.
After it reaches steady state, then the net acceleration in that direction is zero (constant speed = no acceleration). Then you are back to the original problem, which is just resisting gravity. This is what your accels are really measuring.
I just saw your FBD, and if you look at your "a" vector, the one pointing along the copter axis, maybe this will make more sense. If there is any real acceleration in that direction, your copter is sliding thru the sky (not moving forward due to pitch, but actually "sliding" along the "a" axis you show). If it is hovering, that isn't happening obviously. So an accelerometer aligned with "a" is going to be measuring your resistance to gravity, g * sin theta.
I'll try to diagram and equation it later if I can find the time...
The real data problem is trying to pick a small signal out of a very noisy environment...that is where the gyro / accel complimentary filtering comes in...
The accelerometers will eventually register which way is down for any body falling (or suspended) in the air, even for a quadrotor. The quadrotor is not special in this regard. It does not matter what the shape or configuration of an aircraft is, the principle is the same.
Here is what happens in the case of the quadrotor:
1. Lets say that the quadrotor starts out level, and then, for some reason, pitches (or rolls, it does not matter) just a little bit. Since, in the frame of reference of the quadrotor, the aerodynamic forces do not change, the instantaneous accelerometers do not register any change. So far, it does not look good for the accelerometers. Fortunately, you have the gyros, which will register the change, and could be used to control the pitch. But, lets say to want to pitch forward, get the quad moving, and have the accelerometers work, too.
2. With the quadrotor pitched forward, it will start to slide forward. At first the forward acceleration will be equal to gravity times the sine of the pitch angle.
3. As the quadrotor starts to move forward, the airflow through the rotors will no longer be parallel to the rotor shafts and perpendicular to the rotor blades. If you work out the physics on that, you will see that there will be an aerodynamic force that will build up that resists the acceleration. As the quad starts to move forward, the angle of the airflow with respect to the rotor blades will change as the blade rotates, in such a way as to resist the forward motion. Also, the forward motion of the quadrotor will develop aerodynamic forces on all of the other parts of the aircraft, which will also resist the forward motion.
4. The forces resisting the acceleration will build up approximately proportional to the square of the forward velocity. It will not take long to reach steady state, the copter will be in a downward glide at constant speed, and the accelerometers will correctly read which way is down.
The paradox in the reasoning that I saw in the original post is that the direction of the total aerodynamic force for a quadrotor copter must be parallel with the rotor shafts. It is simply not true. The direction of the force on the blades depends on the lateral motion of the copter. When the lateral motion is zero, the force is parallel with the rotor shafts. However, lateral motion will generate lateral aerodynmic forces which help the accelerometers determine which way is down.
It is the air drag that is the key factor at work. It keeps the aircraft from accelerating indefinitely, so it always reaches a steady state, allowing the accelerometers to work, on the average.
In a shorter form, here is the assumption that is not correct:
"In a quadrotor, the only source of aerodynamic forces are the rotors, which are always aligned with the z-axis."
When the quadrotor moves laterally, the aerodynamice forces generated by the rotors are no longer aligned with the z-axis, because the airflow through the blades is no longer perpendicular to the blades. As a result, there will be a lateral aerodynamic force.
Thanks for your response. You are the only person to make this observation about the out of plane rotor forces. I agree that this should be the case. Of course, this fact does not really help the cause since it represents other forces that the accelerometer measures that detract from using them as gravity vector sensors. However, I think you are right again in that the complementary filter structure works because the quad spends most of its time in unaccelerated "trim" flight - either stationary hover or in "terminal" steady velocity - in which cases the accels can be used to measure the gravity vector. Even if the quad never spends significant time in trim, I think the low frequency ("on average") position is still evenly distributed around hover.
I had the idea in my simple one-axis-at-a-time complementary filter to ignore the accelerometer input if the magnitude of the sensor is outside a certain band of 1 g. In other words, just integrate the (bias compensated) gyro in this case. I don't know if this is a useful addition to the DCM algorithm or not (especially if the rotor vibration dominates the accel response - as it does in the data I linked to)