Labdb fix: sensor.imu에 IMU FIFO 마지막(최신) 샘플 사용

cycle당 IMU 다수 샘플(FIFO 순)이 오는데, 첫 샘플을 쓰면 piezo 캡처
시점보다 ~240~300ms 전의 오래된 자세값이 labdb에 들어감. 마지막
샘플로 바꿔 piezo 측정 시점과 가장 가까운 자세값이 기록되도록 함.
imu_samples 전체는 그대로 보존.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 11:23:46 +09:00
parent ccd4dcbbc3
commit 547e834714
@@ -119,11 +119,12 @@ object LabdbUploader {
val piezo = cycle.optJSONObject("piezo") ?: JSONObject()
val imuArr = cycle.optJSONArray("imu") ?: JSONArray()
// labdb 표준 sensor.imu는 단일 샘플. 우리는 cycle당 15 샘플이라
// 첫 샘플을 sensor.imu에 넣고 전체를 sensor.imu_samples에 free field로 보존.
val firstImu = if (imuArr.length() > 0) imuArr.optJSONObject(0) else null
// labdb 표준 sensor.imu는 단일 샘플. 우리는 cycle당 다수 샘플(FIFO 순)이라
// 마지막(=가장 최근, piezo 캡처 직전) 샘플을 sensor.imu에 넣고
// 전체를 sensor.imu_samples에 free field로 보존.
val latestImu = if (imuArr.length() > 0) imuArr.optJSONObject(imuArr.length() - 1) else null
val sensor = JSONObject().apply {
firstImu?.let {
latestImu?.let {
put("imu", JSONObject().apply {
put("ax", it.optDouble("ax"))
put("ay", it.optDouble("ay"))