2015-04-12 95 views
1

(Python)我正在使用一個IMU(慣性測量單元)裝上覆蓋角度爲[roll,pitch,yaw]的覆盆子pi。Python:我如何「零」或「去皮」3D旋轉座標?

該芯片似乎有一個硬件'零',無法校準,因此在我想要的軟件。

當我打開芯片時,我可能會讀取theta = [10, 5, -80] *並想將其設置爲我的'零'。 *角度的範圍是+ - 180deg並且可以在拉德如果容易

我有一個粗的解決方法,但我的東西更優雅後:

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 

我一直都盼望到這一段時間現在和一些人已經提到四元數和輪換矩陣但我不能讓我的頭。 任何幫助將不勝感激!

這裏是有人在C achieveing它++爲同一庫我使用,以獲得從IMU的數據鏈接: Link

其它潛在有用的(計算器)鏈接: Link

回答

0

你可以像你這樣做得更精確一點:

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] 
0

單向,將你的皮重角度從歐拉映射到旋轉矩陣。 (或者如果你喜歡的話,可以換成quat),然後反轉你的旋轉矩陣(這將是它的轉置) - 作爲rotMatA。把你的傳入歐勒,映射到一個腐爛的墊(作爲rotMatB),並乘以你的皮重腐地圖時間。從那裏,你可以隱蔽回歐拉如果你喜歡就好

rotMatA =eulerToRotMat(tareAngles).transpose() 

rotMatB = eulerToRotMat(incomingAngles) 

netResult= rotMatToEuler(rotMatA * rotMatB) 

從庫中獲得rotMat歐拉轉換(更好),或使用源一樣實現自己的:http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToMatrix/