2 Commits
Author SHA1 Message Date
茂之钳 756da44f4f feat: global crash handler saves log to app files dir
Build APK / build (push) Failing after 4s
SensToolsApp now installs a default uncaught exception handler that
writes crash stack traces to filesDir/crashes/crash_YYYY-MM-DD_HH-mm-ss.txt
before passing to the default handler. This makes debugging easy without
adb/root.
2026-05-28 10:44:16 +00:00
茂之钳 d3791c5514 fix: EKFAttitude array index out of bounds in Kalman gain calculation
Build APK / build (push) Failing after 3s
P[i][k] accessed k up to 5, but P is 4x4 (only indices 0..3 valid).
Split P * H^T multiplication into two explicit steps:
1. PHT = P * H^T (4x6, k over 0..3)
2. K = PHT * SInv (4x6, k over 0..5)
2026-05-28 06:42:08 +00:00
2 changed files with 50 additions and 6 deletions
@@ -1,12 +1,49 @@
package com.senstools
import android.app.Application
import android.os.Environment
import java.io.File
import java.io.FileWriter
import java.io.StringWriter
import java.io.PrintWriter
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class SensToolsApp : Application() {
override fun onCreate() {
super.onCreate()
instance = this
// Install global crash handler
val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
saveCrashLog(throwable)
defaultHandler?.uncaughtException(thread, throwable)
}
}
private fun saveCrashLog(throwable: Throwable) {
try {
val crashDir = File(filesDir, "crashes")
crashDir.mkdirs()
val dateStr = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US).format(Date())
val file = File(crashDir, "crash_$dateStr.txt")
val sw = StringWriter()
val pw = PrintWriter(sw)
pw.println("=== CRASH ===")
pw.println("Time: ${System.currentTimeMillis()}")
pw.println("Thread: ${Thread.currentThread().name}")
throwable.printStackTrace(pw)
pw.close()
FileWriter(file).use { it.write(sw.toString()) }
} catch (_: Exception) {
// Silent
}
}
companion object {
@@ -347,17 +347,24 @@ class EKFAttitude {
val SInv = invert6x6(S)
// Kalman gain: K = P * H^T * S^(-1)
// Step 1: P * H^T (4x4 * 4x6 => 4x6 intermediate)
val PHT = Array(4) { FloatArray(6) }
for (i in 0..3) {
for (j in 0..5) {
var sum = 0f
for (k in 0..3) {
sum += P[i][k] * H[j][k]
}
PHT[i][j] = sum
}
}
// Step 2: K = PHT * SInv (4x6 * 6x6 => 4x6)
val K = Array(4) { FloatArray(6) }
for (i in 0..3) {
for (j in 0..5) {
K[i][j] = 0f
for (k in 0..5) {
K[i][j] += P[i][k] * H[j][k]
}
// Multiply by SInv
var sum = 0f
for (k in 0..5) {
sum += K[i][k] * SInv[k][j]
sum += PHT[i][k] * SInv[k][j]
}
K[i][j] = sum
}