11 years, 4 months ago.

Gyroscope and accelerometer for roll and pitch angle measurement using minimu9-v2

Could anyone write a program for measuring the roll angle and pitch angle using a minimu9-v2 on the mbed online compiler and commit it please. Thanks

https://github.com/pololu/LSM303 and https://github.com/pololu/L3G may come in handy for writing this code. The code could quite easily be ported.

posted by Matthew Else 07 Aug 2013

3 Answers

Isi Obazele
poster
11 years, 4 months ago.

Thanks but I can read the values from the gyro already. My problem is converting these values to pitch and roll angles

11 years, 4 months ago.

Try this for size

        _work.pitch = (atan2((-zaraw * 0.004), (-xaraw * 0.004)) * RAD2DEG) + 90.0;
        _work.roll = (atan2((-zaraw * 0.004), (-yaraw * 0.004)) * RAD2DEG) + 90.0;

The code was written for ADXL 345 where the LSB resolution is 4 mg/bit.

Hope this helps Henrik

11 years, 4 months ago.

Hey Isi

if you already have your acc readings and gyro readings in deg/s then i should recommend using the complementary filter like so:

sample

         pitch = (0.98)*(pitch+GyroX*deltaTime) + (0.02)*(accangle[0]);
          roll  = (0.98)*(roll+ GyroY*deltaTime) + (0.02)*(accangle[1]);

where the acc angle is calculated as follows:

sample

accangle[0] = ToDeg(atan2(AccX,sqrt(AccY*AccY+AccZ*AccZ)));

for more info you should check out this pdf:

Source http://www.filedump.net/dumped/filter1285099462.pdf More about the filter