1

(Python) I am using an IMU (Inertial Measurement Unit) attachated to a raspberry pi that provides angles of [roll, pitch, yaw].

The chip seems to have a hardware 'zero' and cannot calibrate it, therefore in software I want to.

i.e. When I turn on the chip I may get a reading of theta = [10, 5, -80]* and want to set that to my 'zero'. *the angles are in the range +- 180deg and can be in rad if easier

I have a crude workaround but am after something more elegant:

tare = [*read initial angles*] # This only gets set once
    #inside a loop
    theta = [*read the imu*]
    deg = map(operator.sub, theta, tare) #zero correction, deg = actual (theta) - 'zero' (tare)
    for d in deg: # if angle > 180 then put angle in terms of +_ 180
    if d > 180: d = d - 360
    elif d  < -179: d = d + 360
    print deg

Ive been looking into this for a while now and some people have mentioned quaternions and rotation matrices but I cant get my head around it. Any help would be much appreciated!

Here is a link to someone achieveing it in c++ for the same Lib I am using to get the data from the IMU: Link

Other potentially useful (stackoverflow) link: Link

Community
  • 1
  • 1
webb
  • 11
  • 2

2 Answers2

0

You could do exactly what you're doing a little more concisely like this:

def correction(args):
    d = args[0] - args[1]
    return d-360 if d > 180 else d+360 if d < -179 else d

tare = [10, 5, -80]

#inside the loop
theta = [10, 5, -80]
print map(correction, zip(tare, theta))  # --> [0, 0, 0]
martineau
  • 119,623
  • 25
  • 170
  • 301
0

1-way, Map your tare angles from euler to a rotation matrix. (or to a quat if you like) then invert your rotation matrix (which will be its transpose) - as rotMatA. take your incoming euler, map that to a rot mat (as rotMatB), and multiply your tare rot map times it. From there you can covert back to euler if you like like

rotMatA =eulerToRotMat(tareAngles).transpose()

rotMatB = eulerToRotMat( incomingAngles)

netResult= rotMatToEuler( rotMatA * rotMatB)

get the rotMat to Euler conversions from a library (better), or implement your own using a source like: http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToMatrix/

Matt
  • 1