Decompose rotation matrix into x, y, z basis vectors.

pull/592/head
Eric Westphal 2017-04-01 09:14:13 -04:00
rodzic a998ede17b
commit effa8da5a9
1 zmienionych plików z 37 dodań i 19 usunięć

Wyświetl plik

@ -308,31 +308,49 @@ func sensorAttitudeSender() {
} }
} }
func makeSensorRotationMatrix(mCal *ahrs.Measurement) (ff *[3][3]float64) { func makeSensorRotationMatrix(mCal *ahrs.Measurement) *[3][3]float64 {
if globalSettings.IMUMapping[0] == 0 { // if unset, default to RY836AI in standard orientation f := globalSettings.IMUMapping
globalSettings.IMUMapping[0] = -1 // +2 if globalSettings.IMUMapping[0] == 0 { // if unset, default to some standard orientation
globalSettings.IMUMapping[1] = -3 // +3 globalSettings.IMUMapping[0] = -1 // +2 for RY836AI
globalSettings.IMUMapping[1] = -3 // +3 for RY836AI
saveSettings() saveSettings()
} }
f := globalSettings.IMUMapping
ff = new([3][3]float64) var x, y, z [3]float64
// TODO westphae: remove the projection on the measured gravity vector so it's orthogonal.
if f[0] < 0 { // This is the "forward direction" chosen for the sensor. // This is the "forward direction" chosen during the orientation process.
ff[0][-f[0]-1] = -1 if f[0] < 0 {
x[-f[0]-1] = -1
} else { } else {
ff[0][+f[0]-1] = +1 x[+f[0]-1] = +1
} }
//TODO westphae: replace "up direction" with opposite of measured gravity.
if f[1] < 0 { // This is the "up direction" chosen for the sensor. // This is the "up direction" chosen during the orientation process.
ff[2][-f[1]-1] = -1 if f[1] < 0 {
z[-f[1]-1] = -1
} else { } else {
ff[2][+f[1]-1] = +1 z[+f[1]-1] = +1
} }
// This specifies the "left wing" direction for a right-handed coordinate system. //TODO westphae: replace "up direction" with measured gravity.
ff[1][0] = ff[2][1]*ff[0][2] - ff[2][2]*ff[0][1]
ff[1][1] = ff[2][2]*ff[0][0] - ff[2][0]*ff[0][2] // Normalize the gravity vector to be 1 G.
ff[1][2] = ff[2][0]*ff[0][1] - ff[2][1]*ff[0][0] gg := z[0]*z[0] + z[1]*z[1] + z[2]*z[2]
return ff z[0] /= gg
z[1] /= gg
z[2] /= gg
// Remove the projection on the measured gravity vector from x so it's orthogonal to z.
dp := x[0]*z[0] + x[1]*z[1] + x[2]*z[2]
x[0] = x[0] - dp * z[0]
x[1] = x[1] - dp * z[1]
x[2] = x[2] - dp * z[2]
// Specify the "left wing" direction for a right-handed coordinate system using the cross product.
y[0] = z[1]*x[2] - z[2]*x[1]
y[1] = z[2]*x[0] - z[0]*x[2]
y[2] = z[0]*x[1] - z[1]*x[0]
return &[3][3]float64 {x, y, z}
} }
// This is used in the orientation process where the user specifies the forward and up directions. // This is used in the orientation process where the user specifies the forward and up directions.