From the other post couple of days ago, where I have investigated in a simple way and tried to solve the problem with the drift on yaw for the current version of the 9DOF – Razor IMU from Sparkfun (at present in Nov. 2011 – as they have other version and you do not know how many would they have in the future)
Just to summarize from the last post:
As this problem is driving me nuts I am checking the RAW signals from the 9DOF Razor IMU in Matlab using the X-IMU library to try and to locate where the issues come from.
So we need to aquire all the signals using a serial to file monitor and then load them into matlab using the X-IMU to see where the problem comes from.
1st thing you can use this processing sketch for logging the raw accelerometer, gyro and magnetometer signals. Load the example file FreeIMU_Raw into the arduino then execute the sketch and move the board around a bit. Then open the file.txt and remove the first line of data as it has some strange characters until the data got syncronized with the computer.
One line of data should be: accelerometer – 3 values, gyro – 3 values, magneto -3 values. Now lets open it in Matlab and type in command line:
load ('file.txt') Accelerometer=[file(:,1) file(:,2) file(:,3) ]/200; Gyroscope=[file(:,4) file(:,5) file(:,6) ]/14; Magnetometer=[file(:,7) file(:,8) file(:,9) ]/400;
The divisions ‘/200′ ,’/14′ , and ‘/400′ is to achieve a very quick conversion between the ADC units and measument units (e.g. g units or acc… and so on)
Now comes the problem with establishing time vector. Unless you modify the firmware to include a time line to take time each sample and send it to serial, let’s presume that our sampling frequency is (i am not sure about this, needs to be checked) : fs=approx. 57600/ 8 bits / 9 data col / 3 fig =266.67 = 267 — I will check this and get back to you.
fs=267; time=0:1/fs:length(Accelerometer)/fs-1/fs
Here is some modified code (from X-IMU library) for displayed the signals:
figure('Name', 'Raw Data'); axis(1) = subplot(3,1,1); hold on; plot(time, Accelerometer(:,1), 'red'); plot(time, Accelerometer(:,2), 'green'); plot(time, Accelerometer(:,3), 'black'); legend('X', 'Y', 'Z'); xlabel('Time (s)'); ylabel('Acceleration (g)'); title('Accelerometer'); hold off; axis(2) = subplot(3,1,2); hold on; plot(time, Gyroscope(:,1), 'red'); plot(time, Gyroscope(:,2), 'green'); plot(time, Gyroscope(:,3), 'black'); legend('X', 'Y', 'Z'); xlabel('Time (s)'); ylabel('Angular rate (deg/s)'); title('Gyroscope'); hold off; axis(3) = subplot(3,1,3); hold on; plot(time, Magnetometer(:,1), 'red'); plot(time, Magnetometer(:,2), 'green'); plot(time, Magnetometer(:,3), 'black'); legend('X', 'Y', 'Z'); xlabel('Time (s)'); ylabel('Flux '); title('Magnetometer'); hold off; linkaxes(axis, 'x');
So far we have couple of assumptions:
1 ) we assume that the time formula si the one use above – to overcome this assumption we need to change the FreeIMU_Raw firmware to output a time line as well or use the quaternion Firmware code as that one includes time line, as well, for the integration and then convert into eulers.
2) we assume that the FreeIMU library uses the same implementation as the X-IMU library - well yes it does the algorithms look the same, because it is Mahonys filter.
3) we assume that the orientation of the X-IMU is the same as Razor IMU – yes it is the same.
4) We assume that the levels of the signals are the same in the X-IMU as Razor IMU – solving this assumption by looking at the C code. – yes they are with some minor converstions.
Update on the 18th of Dec 2011:
I have tested it and the X-IMU matlab code works brilliantly, the same can be said for the FreeIMU.
It seems that kp 0.1 and kip 0.005 works better at a faster sample rate for relatively dynamic ranges.
However I have noticed that removing the gyroscopic feed-back items (both in X-IMU and FreeIMU) for some reson improves the drift. I presume this is not recommended, but it works for me.
For X-IMU go to MahonyAHRS.m and comment the line 97:
% Apply feedback terms %Gyroscope = Gyroscope + obj.Kp * e + obj.Ki * obj.eInt;
For FreeIMU open FreeIMU.cpp from the library and go to lines 236-239 and comment out the feedback items:
// adjusted gyroscope measurements //gx = gx + Kp*ex + exInt; //gy = gy + Kp*ey + eyInt; //gz = gz + Kp*ez + ezInt;
LINKS
Tags: 9DOF, accelerometer, arduino, gyro, magnetometer, Matlab, Processing
I Have to say that Fabio has commented on his website and he is right. you can find the comment here http://www.varesano.net/blog/fabio/freeimu-designing-free-speech-9-domdof-marg-imu#comment-20653.
I am changing the name of the post to workaround.
UPDATE: I have found that after doing this it still drifts a little bit after powering up. However what corrected the problem was hitting reset button on the 9DOF IMU board. After resetting 2-3 times it solve it.
This somehow suggests that there is an initialtion problem somewhere. I’ll get back to you.
I’m trying to learn how to use the Madgwick code. Did you figure out why you needed to reset to 9DOF IMU 2-3 times? Have you made any other changes to the code since your last update?
Unfortunatelly I did not have time yet, But I will make time in the next 2 weeks. Sorry for this. However I found out why you need to reset 2-3 time before it works, it is to do with variables initiation, I’ll also try to suggest a workaround.