Jingyi Zou commited on
Commit
da167ee
·
unverified ·
1 Parent(s): 8c3be6c

contact entry debounce (0.2s): approach brushes no longer spam contact/drop pairs; verified on sotac raw ep6, 33 events -> 15

Browse files
Files changed (1) hide show
  1. src/lib/eventDetection.ts +23 -12
src/lib/eventDetection.ts CHANGED
@@ -116,6 +116,10 @@ export interface DetectionThresholds {
116
  * filters single-frame zero dropouts from the recording path. */
117
  const EXIT_MIN_S = 0.3;
118
 
 
 
 
 
119
  export const DEFAULT_THRESHOLDS: DetectionThresholds = {
120
  contactEnterN: 0.15,
121
  contactExitN: 0.1,
@@ -591,25 +595,32 @@ export function detectEvents(
591
  let liftActive = -1;
592
  let lastPlaceEnd = -Infinity;
593
  let belowSince = -1;
 
594
  const dFn = derivative(f.fn, t);
595
  const dFs = derivative(f.fs, t);
596
  const stableWin = Math.max(3, Math.round(th.stableWindowS * rateHz));
597
 
598
  for (let i = 0; i < n; i++) {
599
  const fn = f.fn[i];
600
- // contact enter/exit with hysteresis
601
  if (!inContact && fn > th.contactEnterN) {
602
- inContact = true;
603
- contactStart = i;
604
- stableMarked = false;
605
- events.push({
606
- label: "contact_onset",
607
- startS: t[i],
608
- endS: t[i],
609
- finger: fi,
610
- confidence: "medium",
611
- order: events.length,
612
- });
 
 
 
 
 
 
613
  } else if (inContact && fn < th.contactExitN) {
614
  // Debounced exit: require the force to stay below the exit level for
615
  // a minimum duration. Single-frame zero dropouts (recording-path
 
116
  * filters single-frame zero dropouts from the recording path. */
117
  const EXIT_MIN_S = 0.3;
118
 
119
+ /** Contact entry must persist this long before contact_onset fires —
120
+ * momentary brushes during approach otherwise spam contact/drop pairs. */
121
+ const ENTER_MIN_S = 0.2;
122
+
123
  export const DEFAULT_THRESHOLDS: DetectionThresholds = {
124
  contactEnterN: 0.15,
125
  contactExitN: 0.1,
 
595
  let liftActive = -1;
596
  let lastPlaceEnd = -Infinity;
597
  let belowSince = -1;
598
+ let aboveSince = -1;
599
  const dFn = derivative(f.fn, t);
600
  const dFs = derivative(f.fs, t);
601
  const stableWin = Math.max(3, Math.round(th.stableWindowS * rateHz));
602
 
603
  for (let i = 0; i < n; i++) {
604
  const fn = f.fn[i];
605
+ // contact enter/exit with hysteresis, both edges debounced
606
  if (!inContact && fn > th.contactEnterN) {
607
+ if (aboveSince < 0) aboveSince = i;
608
+ if (t[i] - t[aboveSince] >= ENTER_MIN_S) {
609
+ inContact = true;
610
+ contactStart = aboveSince;
611
+ stableMarked = false;
612
+ events.push({
613
+ label: "contact_onset",
614
+ startS: t[aboveSince],
615
+ endS: t[aboveSince],
616
+ finger: fi,
617
+ confidence: "medium",
618
+ order: events.length,
619
+ });
620
+ aboveSince = -1;
621
+ }
622
+ } else if (!inContact) {
623
+ aboveSince = -1;
624
  } else if (inContact && fn < th.contactExitN) {
625
  // Debounced exit: require the force to stay below the exit level for
626
  // a minimum duration. Single-frame zero dropouts (recording-path