Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine Gyroscope and Accelerometer Data

I am building a balancing robot using the Lego Mindstorm's NXT system. I am using two sensors from HiTechnic, the first being an Accelerometer and the second being a Gyroscope. I've successfully filtered out noise from both sensors and derived angles for both in a range between -90 and 90 degrees, with 0 degrees being perfectly balanced.

My next challenge is to combine both of the sensor values to correct for the Gyroscope's drift over time. Below is an example graph I created from actual data to demonstrate the drift from the gyroscope:

enter image description here

The most commonly used approach I've seen to make combining these sensors rock solid is by using a Kalman filter. However, I'm not an expert in calculus and I really don't understand mathematical symbols, I do understand math in source code though.

I'm using RobotC (which is like any other C derivative) and would really appreciate if someone can give me examples of how to accomplish this in C.

Thank you for your help!

SOLUTION RESULTS:

Alright, kersny solved my problem by introducing me to complementary filters. This is a graph illustrating my results:

Result #1

enter image description here

Result #2

enter image description here

As you can see, the filter corrects for gyroscopic drift and combines both signals into a single smooth signal.

Edit: Since I was fixing the broken images anyways, I thought it would be fun to show the rig I used to generate this data:

enter image description here

like image 464
Dylan Vester Avatar asked Oct 19 '09 01:10

Dylan Vester


People also ask

What is the combined function of gyro sensor and accelerometer?

Accelerometer and gyroscope Accelerometers in mobile phones are used to detect the orientation of the phone. The gyroscope, or gyro for short, adds an additional dimension to the information supplied by the accelerometer by tracking rotation or twist.

Can you use an accelerometer as a gyroscope?

Yes they both can be used to together describe the motion of a device, but they can also be used to correct each other. For example, I read and experimented that the drift in the gyroscope can be corrected by using the accelerometer even though they don't essentially measure the same thing.

How do we determine the position of an object with accelerometer and gyroscope sensor data?

How do we determine the position of an object with accelerometer and gyroscope sensor data? The double integration of acceleration gives the position of an object.

What data does gyroscope collect?

The gyroscope measures the angular velocity (units of radians/second) about each axis, which indicates the direction and speed that the phone is spinning about the axis. The accelerometer measures the acceleration along each axis in units of g (1 g = 9.81 m/s/s).


1 Answers

Kalman Filters are great and all, but I find the Complementary Filter much easier to implement with similar results. The best articles that I have found for coding a Complementary Filter are this wiki (along with this article about converting sensors to Engineering units) and a PDF in the zip file on this page (Under Technical Documentation, I believe the file name in the zip is filter.pdf);

PS. If your stuck on a Kalman Filter, here is some C-syntax code for the Arduino that implements it.

like image 108
kersny Avatar answered Oct 05 '22 22:10

kersny