Re: Kalman Filter Code

Started by rade95 July 19, 2007
Kyle,

Thanks for the code. Could you make a recommendation as to what type
of gyro would work the best with this code? I have a sparkfun
gyro/accelerometer duo board. Also, I am having a problem
understanding the structure of the source code files. Perhaps you
can explain this a bit. Where does the program start and how does it
branch? Have you succeeded in building a balancing bot using this
code? Thanks a lot. --ray

rade95(at)yahoo.com

--- In b..., "camel85kv" wrote:
>
> If any of you have ever considered building a two wheel
balancing
> robot, here is some code that I have written.
>
> http://home.everestkc.net/cvogt/New%20Kalman%20Code.zip
>
> It samples an angular rate gyroscope about 150 times per
second,
> and runs a background task to sample an accelerometer. The
> acceleromter is filtered by sampling 5 times for each reading.
Every
> time a sensor reading is ready, the data is sent to a modified two
> dimentional kalman filter, which ultimately returns the tilt angle
of
> the system in the form of the global variable KalmanAngle.
> The filter subs are set up so that sensor readings do not have
to
> come in at the same time. This is what allows the incredible rate
of
> 150 tilt outputs per second. As it turns out, the gyroscope is
read
> 150 times per second, and I estimate that the accelerometer is read
> about 30 or so times per second.
> I optimized the matrix operations (and the rest of the code) in
> the kalman filter so much that the original formulas are totally
> non-existant. In this setup, many of the terms are 0, so I left
them
> out. It should still be readable enough for anyone to adjust the
> constants for their particular application.
> I hope that this is not too off topic, but I thought someone
out
> there may want to use this. To my knowledge, it is the first
> implementation of kalman filters, specifically for balancing
robots,
> on the BasicX-24. See David P. Anderson's "Nbot" or Larry
Barello's
> "Gyrobot" if you don't know what I am talking about.
>
> -Kyle Vogt
>
Kyle Vogt has not been active here for several years, Ray. His Kalman
code was posted in 2003. I can help answer some of your questions.

Sparkfun's accelerometer/gyro breakout boards should work fine with
Kyle's code, but you will need to make changes to change from PWM
input to analog input.

His code will compile as posted, I believe; execution starts at
Main(). He runs two tasks, the main task that spins and collects rate
gyro data and another task that spins getting acceleration data.
You'll find that some values are fudged, some hard numbers are where
variables should be, and other signs of incomplete code. I found that
it fundamentally works, but you'll need to integrate it into your device.

Kyle didn't indicated if this was successful in a project, but I
suspect it was.
Tom