Kalman filter and complimentary filter IMU code

Hi everyone

So I've been looking into Kalman filtering and complimentary filtering and figured I would compare results. I found two libraries/sets of code, one for complimentary and one for Kalman (which also happens to have complimentary filter code as well).

However I have a question.

In the first link below, in the code (gy_521_send_serial.ino) you will see A LOT of defining with #Define and then varying details and variables for the mpu (just check it out) and then the code goes on to do some calculations.
Yes the URL is amusing, lol.(download link down the bottom of the page)

However the second link for the kalman filtering (mpu6050.ino) has none of this. I see it goes almost straight into the kalman filter calculations with a few references to I2C. I think it looks like it gets the data from here:
while (i2cRead(0x3B, i2cData, 14));
accX = ((i2cData[0] << 8 ) | i2cData[1]);

(download zip file)

Is the first complimentary filter code just super inefficient? Is there something I am missing or different? Is the data just structured differently? I don't know what to make of it, if someone could "enlighten" me, that would be great.

Also which would be better to use? I know the the two filters come up with very similar results with the kalman being more reliable and the complimentary being fine for most tasks. Just based on the code, which will take up less computing power and communication from the Arduino?

The first link's code just seems like a massive mess and waste of lines of code comparatively to the relatively sleek and minimal code of the second link!

Thanks :slight_smile: