commitf0b9b2af67Merge:373d65abbaa7bbAuthor: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Sat Sep 12 18:17:04 2026 +0800 Merge branch 'merge-testing' commit373d65a9d5Merge:28fc652dd0e6fdAuthor: harine <harinesumen@gmail.com> Date: Sat Sep 12 17:34:27 2026 +0800 Merge branch 'master' into Harine commit28fc652097Author: harine <harinesumen@gmail.com> Date: Sat Sep 12 17:34:07 2026 +0800 new stuff added yes commitbbaa7bb04fMerge:1c6ced2610bfd7Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Fri Sep 11 11:18:35 2026 +0800 Merge branch 'Gabriel' into merge-testing commit1c6ced2dceAuthor: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Fri Sep 11 11:12:30 2026 +0800 this good commitdd0e6fdc39Author: DefiantWanderer <yongwei1349@gmail.com> Date: Fri Sep 11 10:32:34 2026 +0800 Revert "fixing compatibility issues" This reverts commit564e7d83f8. commit564e7d83f8Author: DefiantWanderer <yongwei1349@gmail.com> Date: Fri Sep 11 10:28:40 2026 +0800 fixing compatibility issues commit610bfd7991Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Fri Sep 11 10:13:25 2026 +0800 Merged Khalil commitcfe76da1d3Merge:584818b9fcdc13Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Fri Sep 11 10:03:51 2026 +0800 Merge branch 'Khalil' into Gabriel commit584818b95aAuthor: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Thu Sep 10 12:47:06 2026 +0800 added back phase toggle button commit17fad430c1Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Thu Sep 10 12:09:46 2026 +0800 Cleaned up merge UI, added reset step button commitac4366d04dAuthor: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Thu Sep 10 00:31:47 2026 +0800 Added some UI to recording commitd601efcf43Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Thu Sep 10 00:13:06 2026 +0800 Corrected 5 step approach phases & added placeholders for future logic commit7cf217488aAuthor: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Wed Sep 9 22:48:06 2026 +0800 Cleared warnings commit981071ef74Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Wed Sep 9 20:09:18 2026 +0800 Fix Merge, cleaned up UI commitf30bbe2a34Merge:2f451157518594Author: Gabriel Low <73009315+gabriellow1111@users.noreply.github.com> Date: Tue Sep 8 14:11:21 2026 +0800 Merge branch 'au-au' into Gabriel commit9fcdc13699Author: Khalil Belabadia <belabakhalil@gmail.com> Date: Mon Sep 7 22:16:00 2026 +0800 Audio feedback update Added the following files : - AudioCue.kt - AudioFeedbackEngine - AudioFeedbackSettings Edited files : - BowlingCameraActivity (added the triggerAudiofeedback function) commit7518594440Merge:e7a9c2b7af128dAuthor: midnight-masala <2401021@sit.singaporetech.edu.sg> Date: Mon Sep 7 21:26:18 2026 +0800 Merge remote-tracking branch 'origin/au-au' into au-au # Conflicts: # app/src/main/java/com/example/jnicpp/bowling/BowlingCameraActivity.kt # app/src/main/res/layout-land/activity_bowling_camera.xml # app/src/main/res/layout/activity_bowling_camera.xml commite7a9c2b140Author: midnight-masala <2401021@sit.singaporetech.edu.sg> Date: Mon Sep 7 21:22:11 2026 +0800 Add live per-step form feedback based on joint angles Extends pose angle tracking with knee bend (hip-knee-ankle), then uses it alongside the existing elbow/shoulder angles in a new PoseStageAdvisor to give a short live cue for whichever step of the approach is in progress: push-away on step 2, downswing on step 3, backswing on step 4, and knee-bend/arm-extension on the final step. Thresholds are starting defaults, not measured coaching data, and are expected to be retuned against real approach footage. Also fixes a layout bug found while testing this live: the new feedback text was chained via ConstraintLayout's toBottomOf to the step banner above it, so whenever that banner was hidden (GONE) the feedback text rendered at its collapsed zero-height position instead of staying put, landing on top of the recording indicator. Both now sit in a plain vertical LinearLayout, which collapses GONE children correctly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> commit7af128d575Author: midnight-masala <2401021@sit.singaporetech.edu.sg> Date: Mon Sep 7 20:58:03 2026 +0800 steps identify the steps commit2bb7c6ca7bAuthor: midnight-masala <2401021@sit.singaporetech.edu.sg> Date: Mon Sep 7 20:58:03 2026 +0800 Add live final-position feedback and fix step detection accuracy Shows a live banner as each step of the approach is counted, ending in "FINAL POSITION - RELEASE!" once the 5th footfall lands. Also fixes LiveStepDetector's peak-prominence check, which compared a candidate footfall only to its immediate neighboring frame and silently dropped real steps that landed across several closely-spaced frames; it now tracks the true rise/fall trough on each side instead. Switches PoseAnalyzer to ML Kit's faster base pose model (the accurate model was starving the peak detector of frames on unaccelerated hardware), and makes LiveStepDetector's stillness-based reset toggleable, currently off for easier testing against recorded reference clips. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
109 lines
4.7 KiB
Kotlin
109 lines
4.7 KiB
Kotlin
/**
|
|
* @file StepCountingSession.kt
|
|
* @brief Owns pose-frame buffering and live step counting for one recording attempt.
|
|
*/
|
|
package com.example.jnicpp.bowling
|
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
import kotlinx.coroutines.flow.StateFlow
|
|
import kotlinx.coroutines.flow.asStateFlow
|
|
|
|
/**
|
|
* @brief Bundles everything [CameraViewModel] needs to buffer pose frames
|
|
* and run live step counting during a recording, so that ViewModel
|
|
* stays a thin state machine rather than also holding this
|
|
* machinery directly.
|
|
*
|
|
* Knows nothing about CameraX/ML Kit or Android component lifecycle --
|
|
* same reasoning as [CameraXController] and [PoseAnalyzer] -- so it's
|
|
* trivially unit-testable and reusable if a second recording surface is
|
|
* ever added.
|
|
*/
|
|
class StepCountingSession {
|
|
|
|
// Extra SMA smoothing for ankle/hip landmarks specifically, on top of
|
|
// PoseLandmarkSmoother's per-frame EMA -- see AnkleHipMovingAverageFilter.
|
|
private val ankleHipSmoother = AnkleHipMovingAverageFilter()
|
|
|
|
// Live, incremental step counting -- see LiveStepDetector. Resets
|
|
// mid-recording when the bowler holds a hand raised for the gesture's
|
|
// full hold duration, so one recording can capture several practice
|
|
// approaches back to back. Rebuilt fresh (not just .reset()) in
|
|
// startNewSession from whatever DetectorSettings are current at that
|
|
// moment, so tuning changes made in ParameterEditorActivity take
|
|
// effect on the very next recording without needing an app restart.
|
|
private var liveStepDetector = LiveStepDetector()
|
|
|
|
// Time-ordered pose samples for the current/most recent recording
|
|
// session, one appended per analyzed frame while actually recording --
|
|
// see [onFrame]. Cleared at the start of each new session (see
|
|
// [startNewSession]). Exposed as a read-only snapshot;
|
|
// StepDetector.detect() can consume it once a recording finishes.
|
|
private val poseFrameBuffer = mutableListOf<PoseFrame>()
|
|
/** @brief Time-ordered pose samples buffered for the current/most recent recording session. */
|
|
val poseFrames: List<PoseFrame> get() = poseFrameBuffer
|
|
|
|
// Steps detected so far in the current attempt (since the last reset).
|
|
// The UI reads events.size as the "Step N" counter.
|
|
private val _stepEvents = MutableStateFlow<List<StepEvent>>(emptyList())
|
|
/** @brief Steps detected so far in the current attempt, since the last reset. */
|
|
val stepEvents: StateFlow<List<StepEvent>> = _stepEvents.asStateFlow()
|
|
|
|
/**
|
|
* @brief Feeds one analyzed frame's landmarks/angles into buffering and
|
|
* live step counting. Only meant to be called while a recording
|
|
* is actually in progress -- see [CameraViewModel.onPoseFrameUpdated].
|
|
* @param landmarks EMA-smoothed landmarks for this frame, keyed by ML Kit's `PoseLandmark` type constant.
|
|
* @param angles Joint angles computed for this same frame.
|
|
* @param timestampMs Wall-clock time this frame was analyzed, in milliseconds.
|
|
* @param isStartingPosition Whether the bowler is currently in the starting position.
|
|
*/
|
|
fun onFrame(
|
|
landmarks: Map<Int, SmoothedLandmark>,
|
|
angles: PoseAngles,
|
|
timestampMs: Long,
|
|
isStartingPosition: Boolean = false,
|
|
) {
|
|
val smoothedAnkleHip = ankleHipSmoother.smooth(landmarks)
|
|
val frame = buildPoseFrame(
|
|
timestampMs = timestampMs,
|
|
landmarks = landmarks,
|
|
smoothedAnkleHip = smoothedAnkleHip,
|
|
angles = angles,
|
|
)
|
|
poseFrameBuffer.add(frame)
|
|
|
|
val result = liveStepDetector.update(frame, isStartingPosition = isStartingPosition)
|
|
if (result.wasReset) {
|
|
_stepEvents.value = emptyList()
|
|
}
|
|
if (result.newSteps.isNotEmpty()) {
|
|
_stepEvents.value += result.newSteps
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Manually resets live step detector state and clears detected step events.
|
|
*/
|
|
fun resetStepCounter() {
|
|
liveStepDetector.reset()
|
|
_stepEvents.value = emptyList()
|
|
}
|
|
|
|
/**
|
|
* @brief Clears all buffering/detection state and rebuilds the step
|
|
* detector from [settings]; call when a new recording starts.
|
|
* @param settings Tuning parameters to build this session's [LiveStepDetector] with.
|
|
*/
|
|
fun startNewSession(settings: DetectorSettings = DetectorSettings.DEFAULT) {
|
|
poseFrameBuffer.clear()
|
|
ankleHipSmoother.reset()
|
|
liveStepDetector = LiveStepDetector(
|
|
minSpacingMs = settings.minSpacingMs,
|
|
minProminenceRatio = settings.minProminenceRatio,
|
|
maxFrameJumpRatio = settings.maxFrameJumpRatio
|
|
)
|
|
_stepEvents.value = emptyList()
|
|
}
|
|
}
|