问题
Possible Duplicate:
Combine Gyroscope and Accelerometer Data
I have read a number of papers on Kalman filters
, but there seem to be few good publically accessible worked examples of getting from mathematical paper to actual working code.
I have a system containing a three-axis accelerometer and a single gyro measuring rotation around one of the accelerometer axes. The system is designed to be held by a human, and much of the time the gyro will be measuring rotation about the gravity vector or close to it. (People working in the same industry will likely recognise what I am talking about from that ;)) I realise this is underconstrained.
The gyros appear to have a near-constant bias that is slightly different for each instance of the system. How would I go about coding a filter to use the accelerometer readings to calibrate the gyro at times when the system is tilted so the gyro axis is not collinear with gravity, and is being rotated about the gyro axis? It seems like there should be enough information to do that, but being told that there isn't and why would be an answer too :)
回答1:
nBot, a two wheel balancing robot
Quite a bit of info and links about how this author chose to solve the balance problem for his two wheeled robot.
回答2:
You seem to have two (or three) separate problems here.
1. You don't really understand Kalman filters and/or the mathematics behind them. That is going to make it very difficult to correctly implement and use one.
2. You don't seem to understand the basic physics involved in the problem. (Basic physics means underlying physics, not simple physics, because it isn't simple.)
I'd suggest that you try to use a much simpler integrator, such as a Runga-Kutta 4, for which you can find many books with examples of both the implementation and the use. It should be sufficient for this problem. (If the customer specified Kalman, inquire why.)
As for why the problem is under constrained, it seems to me that it is having no way to insure that the device is held vertically and no way to measure the actual orientation. Forget the gyro for the moment and assume the device can not be rotated about a vertical axis. You have three accelerometers, presumably to estimate position in 3D. So if you see an acceleration in the X direction, you increase the estimate of where you are in the X direction. Similarly, if you see an acceleration in the Z direction (which I will assume is "up"), you increase the estimate of where you are in the Z direction. Now rotate the device slightly, say 30 degrees about the Y axis. Now when the device thinks you are accelerating along the X direction, the device is actually accelerating a bit less than indicated in X and it is also accelerating in the Z direction. So your position estimate is now incorrect.
Rotations are much harder to integrate (the equations are more "stiff", requiring a smaller time step to maintain precision). But they will suffer similar problems of computing wrong answers if the device is tipped (because the device can not tell that it is tipped). It will think that the rotation about the vertical axis is larger or smaller than it actually is, because part of the rotation is actually about a different axis (just as part of the acceleration part was along a different axis).
Perhaps you need to hire a consultant (no, I'm not seeking a job) to assist you in formulating the mathematics.
回答3:
Given your interest in the kalman filter, perhaps you intend to augment GPS data with inertial measurements. About your question:
"How would I go about coding a filter to use the accelerometer readings to calibrate the gyro at times when the system is tilted so the gyro axis is not collinear with gravity, and is being rotated about the gyro axis? It seems like there should be enough information to do that"
This sounds like a gyrocompasing alignment. Assuming you are doing a factory calibration, and have the unit on a bench, you will be able to independently measure the alignment. Then run the leveling code you will write and back out the gyro bias error from the difference between the measure and gyrocompased alignments.
If you want to update gyro drift on-the fly, then you will need the kalman filter.
As far as implementation goes I recommend Chapter 7, GPS and Inertial Integration of Global Position System Theory and Applications vol 2 has excellent background on the topic. It has the theory and math, but no source code.
回答4:
I found good articles about the use of accelerometers and gyroscopes in navigation on this blog. The part on Kalman filtering is a bit hazy, but there seems to be code samples.
You will also find general resources on Kalman filtering at http://academic.csuohio.edu/simond/publications.html. The article referred in (8) is a good, not too scary, introduction to the mathematics behind Kalman filters.
回答5:
A gentleman in Denmark has just posted a worked example of the derivation of a Kalman filter for solving almost exactly this problem.
回答6:
If you happen to be developing for the Propeller uController, than the Parallax Object Exchange has some code. Great question ;-)
来源:https://stackoverflow.com/questions/110804/integrating-gyro-and-accelerometer-readings