Last updated on Thu, 2012-11-15 09:30. Originally submitted by fabio on 2012-10-18 17:45.
I'm working on a user friendly calibration program, since I'm completely aware that what I released some time ago using a python script and Octave is very complex to use for FreeIMU library users.
So, I'm creating a new calibration software which will use Python, Numpy and its linalg component to provide an easy to use libre calibration software.
I started by trying what Nirav Patel suggested but wasn't much successful with it. So, I simply ported the Matlab/Octave code into Python+Numpy+linalg.
Below is the code for you to enjoy and here a sample input file.
cal_lib.py - Ellipsoid into Sphere calibration library based upon numpy and linalg
Copyright (C) 2012 Fabio Varesano
Development of this code has been supported by the Department of Computer Science,
Universita' degli Studi di Torino, Italy within the Piemonte Project
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
from numpy import linalg
def calibrate(x, y, z):
H = numpy.array([x, y, z, -y**2, -z**2, numpy.ones([len(x), 1])])
H = numpy.transpose(H)
w = x**2
(X, residues, rank, shape) = linalg.lstsq(H, w)
OSx = X / 2
OSy = X / (2 * X)
OSz = X / (2 * X)
A = X + OSx**2 + X * OSy**2 + X * OSz**2
B = A / X
C = A / X
SCx = numpy.sqrt(A)
SCy = numpy.sqrt(B)
SCz = numpy.sqrt(C)
return ([OSx, OSy, OSz], [SCx, SCy, SCz])
if __name__ == "__main__":
acc_f = open("acc.txt", 'r')
acc_x = 
acc_y = 
acc_z = 
for line in acc_f:
reading = line.split()
(offsets, scale) = calibrate(numpy.array(acc_x), numpy.array(acc_y), numpy.array(acc_z))