diff --git a/app/src/main/java/com/example/medilightv2android/managers/WalkingDetector.kt b/app/src/main/java/com/example/medilightv2android/managers/WalkingDetector.kt index 0fbe542..341d5b3 100644 --- a/app/src/main/java/com/example/medilightv2android/managers/WalkingDetector.kt +++ b/app/src/main/java/com/example/medilightv2android/managers/WalkingDetector.kt @@ -44,6 +44,8 @@ class WalkingDetector { private var startCondSinceMs: Long? = null /** WALKING 에서 유지 조건 마지막 만족 시각. */ private var keepCondLastOkMs: Long? = null + /** 직전 cycle 의 pitchOk — false→true 전이 시 buffer reset (sit-to-stand burst 차단). */ + private var lastPitchOk: Boolean = false val isWalking: Boolean get() = walking @@ -52,6 +54,7 @@ class WalkingDetector { walking = false startCondSinceMs = null keepCondLastOkMs = null + lastPitchOk = false } /** @@ -59,6 +62,19 @@ class WalkingDetector { * pitchDeg = 같은 cycle 의 pitch (ImuPostureClassifier 가 계산한 값). */ fun update(samples: List, pitchDeg: Float, nowMs: Long): Snapshot { + val minPitch = GreenZoneConstants.walkingMinPitchDeg + val pitchOk = abs(pitchDeg) > minPitch + + // Pitch false→true 전이 (sit-to-stand 등) — buffer 비움. + // 이유: 일어남 burst 가 pitch<45° 일 때 발생 → window 에 누적 → pitch 가 통과한 + // 순간 wmean 이 이미 큰 값 → 즉시 start cond 만족 → 가짜 walking trigger. + // pitch 가 true 가 된 직후엔 새 데이터만으로 measure 하도록. + if (pitchOk && !lastPitchOk && !walking) { + buffer.clear() + startCondSinceMs = null + } + lastPitchOk = pitchOk + // 1) sample buffer 에 추가 (timestamp 단순 분배 — cycle 내 균등 간격 가정) val windowMs = GreenZoneConstants.walkingWindowMs if (samples.isNotEmpty()) { @@ -89,10 +105,7 @@ class WalkingDetector { } val wstd = sqrt(sqSum / n) - // 4) state machine - val minPitch = GreenZoneConstants.walkingMinPitchDeg - val pitchOk = abs(pitchDeg) > minPitch - + // 4) state machine (pitchOk 은 위에서 이미 계산됨) if (!walking) { // IDLE → WALKING 검사 (4-2) val cond = pitchOk &&