Calibrating accelerometers and magnetometers

When deriving sensory data from IMU chips it is always an issue that the gain and offset of the readings is not known, and varies from chip to chip. I have written a short Python script which uses a least squares fit to calibrate these devices. All you need to do is capture a set of XYZ readings while moving the device through different orientations, and put the readings in a text file. You can get this script from my github.