Re-do sensor orientation setting method.

pull/578/head
Eric Westphal 2017-02-16 16:57:30 -05:00
rodzic e78afed4d4
commit f2cfe3344b
3 zmienionych plików z 22 dodań i 16 usunięć

Wyświetl plik

@ -1039,7 +1039,7 @@ type settings struct {
DisplayTrafficSource bool DisplayTrafficSource bool
DEBUG bool DEBUG bool
ReplayLog bool ReplayLog bool
IMUMapping [3]int // Map from aircraft axis to sensor axis: accelerometer IMUMapping [2]int // Map from aircraft axis to sensor axis: accelerometer
PPM int PPM int
OwnshipModeS string OwnshipModeS string
WatchList string WatchList string
@ -1108,7 +1108,7 @@ func defaultSettings() {
globalSettings.DEBUG = false globalSettings.DEBUG = false
globalSettings.DisplayTrafficSource = false globalSettings.DisplayTrafficSource = false
globalSettings.ReplayLog = false //TODO: 'true' for debug builds. globalSettings.ReplayLog = false //TODO: 'true' for debug builds.
globalSettings.IMUMapping = [3]int{2, -1, 3} // RY83XAI orientation mapping globalSettings.IMUMapping = [2]int{-1, -3} // OpenFlightBox AHRS normal mapping
globalSettings.OwnshipModeS = "F00000" globalSettings.OwnshipModeS = "F00000"
globalSettings.DeveloperMode = false globalSettings.DeveloperMode = false
} }

Wyświetl plik

@ -286,8 +286,8 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
globalSettings.ReplayLog = v globalSettings.ReplayLog = v
} }
case "IMUMapping": case "IMUMapping":
if globalSettings.IMUMapping != val.([3]int) { if globalSettings.IMUMapping != val.([2]int) {
globalSettings.IMUMapping = val.([3]int) globalSettings.IMUMapping = val.([2]int)
globalStatus.IMUConnected = false // Force a restart of the IMU reader globalStatus.IMUConnected = false // Force a restart of the IMU reader
} }
case "PPM": case "PPM":
@ -384,7 +384,7 @@ func handleOrientAHRS(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" { if r.Method == "POST" {
var ( var (
action []byte = make([]byte, 1) action []byte = make([]byte, 1)
u, l int u int
err error err error
) )
@ -415,11 +415,10 @@ func handleOrientAHRS(w http.ResponseWriter, r *http.Request) {
return return
} }
l = 6 / f / u globalSettings.IMUMapping = [2]int{f, u}
globalSettings.IMUMapping = [3]int{f, l, u}
saveSettings() saveSettings()
globalStatus.IMUConnected = false // restart the processes depending on the orientation globalStatus.IMUConnected = false // restart the processes depending on the orientation
log.Printf("AHRS Info: sensor orientation success! forward: %d; left: %d; up: %d\n", f, l, u) log.Printf("AHRS Info: sensor orientation success! forward: %d; up: %d\n", f, u)
default: // Cancel the sensor calibration. default: // Cancel the sensor calibration.
log.Println("AHRS Info: sensor orientation: canceled") log.Println("AHRS Info: sensor orientation: canceled")
} }

Wyświetl plik

@ -181,19 +181,26 @@ func sensorAttitudeSender() {
for { for {
if globalSettings.IMUMapping[0]==0 { // if unset, default to RY836AI if globalSettings.IMUMapping[0]==0 { // if unset, default to RY836AI
globalSettings.IMUMapping[0] = -1 // +2 globalSettings.IMUMapping[0] = -1 // +2
globalSettings.IMUMapping[1] = +2 // -1 globalSettings.IMUMapping[1] = -3 // +3
globalSettings.IMUMapping[2] = -3 // +3
saveSettings() saveSettings()
} }
f := globalSettings.IMUMapping f := globalSettings.IMUMapping
// Set up orientation matrix; a bit ugly for now
ff = new([3][3]float64) ff = new([3][3]float64)
for i := 0; i < 3; i++ { if f[0] < 0 {
if f[i] < 0 { ff[0][-f[0] - 1] = -1
ff[i][-f[i] - 1] = -1 } else {
} else { ff[0][+f[0] - 1] = +1
ff[i][f[i] - 1] = +1
}
} }
if f[1] < 0 {
ff[2][-f[1] - 1] = -1
} else {
ff[2][+f[1] - 1] = +1
}
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]
ff[1][2] = ff[2][0] * ff[0][1] - ff[2][1] * ff[0][0]
failnum = 0 failnum = 0
<-timer.C <-timer.C