Better tap detection (#778)

This commit is contained in:
Collin authored and GitHub committed 2023-07-20 11:06:48 +03:00
1 parent b6a681b1bb
commit e18bd2d382
9 files changed
+98 -40

No files matched your search

@@ -142,7 +142,8 @@ public class RPCSettingsBuilder {
tapDetectionConfig.getMountingResetDelay(),
tapDetectionConfig.getMountingResetEnabled(),
tapDetectionConfig.getMountingResetTaps(),
tapDetectionConfig.getSetupMode()
tapDetectionConfig.getSetupMode(),
tapDetectionConfig.getNumberTrackersOverThreshold()
);
}
@@ -220,6 +220,15 @@ public class RPCSettingsHandler {
.setMountingResetEnabled(tapDetectionSettings.mountingResetEnabled());
tapDetectionConfig.setSetupMode(tapDetectionSettings.setupMode());
// set number of trackers that can have high accel before taps
// are rejected
if (tapDetectionSettings.hasNumberTrackersOverThreshold()) {
tapDetectionConfig
.setNumberTrackersOverThreshold(
tapDetectionSettings.numberTrackersOverThreshold()
);
}
// set tap detection delays
if (tapDetectionSettings.hasYawResetDelay()) {
tapDetectionConfig.setYawResetDelay(tapDetectionSettings.yawResetDelay());
@@ -510,6 +510,9 @@ public class HumanSkeleton {
// Rebuild the bone list
resetBones();
// Update tap detection's trackers
tapDetectionManager.updateConfig();
}
protected void setComputedTracker(Tracker tracker) {
@@ -23,9 +23,9 @@ public class TapDetection {
// hyperparameters
private static final float NS_CONVERTER = 1.0e9f;
private static final float NEEDED_ACCEL_DELTA = 6.0f;
private static final float ALLOWED_BODY_ACCEL = 1.5f;
private static final float ALLOWED_BODY_ACCEL = 2.5f;
private static final float ALLOWED_BODY_ACCEL_SQUARED = ALLOWED_BODY_ACCEL * ALLOWED_BODY_ACCEL;
private static final float CLUMP_TIME_NS = 0.08f * NS_CONVERTER;
private static final float CLUMP_TIME_NS = 0.06f * NS_CONVERTER;
private float timeWindowNS = 0.6f * NS_CONVERTER;
// state
@@ -114,8 +114,9 @@ public class TapDetection {
}
// if waiting for low accel
if (accelDelta < ALLOWED_BODY_ACCEL)
if (getMaxAccel() < ALLOWED_BODY_ACCEL) {
waitForLowAccel = false;
}
// remove old taps from the list (if they are too old)
if (!tapTimes.isEmpty()) {
@@ -134,12 +135,15 @@ public class TapDetection {
// get the amount of taps in the list
// and set the detection time
int newTaps = getTapEvents();
int newTaps = tapTimes.size();
if (newTaps > taps) {
taps = newTaps;
detectionTime = time;
}
if (time - detectionTime > timeWindowNS) {
tapTimes.clear();
}
}
private float getAccelDelta() {
@@ -154,20 +158,14 @@ public class TapDetection {
return max - min;
}
// return the number of distinct tap events in tapTimes
private int getTapEvents() {
if (tapTimes.isEmpty())
return 0;
int tapEvents = 1;
float lastTapTime = tapTimes.getFirst();
for (Float tapTime : tapTimes) {
if (tapTime - lastTapTime > CLUMP_TIME_NS) {
tapEvents++;
lastTapTime = tapTime;
private float getMaxAccel() {
float max = 0.0f;
for (float[] val : accelList) {
if (val[0] > max) {
max = val[0];
}
}
return tapEvents;
return max;
}
// returns true if the user is not imparting more than allowedBodyAccel of
@@ -68,10 +68,6 @@ public class TapDetectionManager {
this.resetHandler = resetHandler;
this.tapSetupHandler = tapSetupHandler;
yawResetDetector = new TapDetection(skeleton, getTrackerToWatchYawReset());
fullResetDetector = new TapDetection(skeleton, getTrackerToWatchFullReset());
mountingResetDetector = new TapDetection(skeleton, getTrackerToWatchMountingReset());
// a list of tap detectors for each tracker
tapDetectors = new ArrayList<>();
for (Tracker tracker : trackers) {
@@ -80,25 +76,19 @@ public class TapDetectionManager {
tapDetectors.add(tapDetector);
}
// since this config value is only modified by editing the config file,
// we can set it here
yawResetDetector
.setNumberTrackersOverThreshold(
config.getNumberTrackersOverThreshold()
);
fullResetDetector
.setNumberTrackersOverThreshold(
config.getNumberTrackersOverThreshold()
);
mountingResetDetector
.setNumberTrackersOverThreshold(
config.getNumberTrackersOverThreshold()
);
updateConfig();
}
public void updateConfig() {
// check the skeleton for new trackers
yawResetDetector = new TapDetection(skeleton, getTrackerToWatchYawReset());
fullResetDetector = new TapDetection(skeleton, getTrackerToWatchFullReset());
mountingResetDetector = new TapDetection(skeleton, getTrackerToWatchMountingReset());
if (this.config == null) {
return;
}
this.yawResetDelayNs = config.getYawResetDelay() * NS_CONVERTER;
this.fullResetDelayNs = config.getFullResetDelay() * NS_CONVERTER;
this.mountingResetDelayNs = config.getMountingResetDelay() * NS_CONVERTER;
@@ -111,6 +101,18 @@ public class TapDetectionManager {
yawResetDetector.setMaxTaps(yawResetTaps);
fullResetDetector.setMaxTaps(fullResetTaps);
mountingResetDetector.setMaxTaps(mountingResetTaps);
yawResetDetector
.setNumberTrackersOverThreshold(
config.getNumberTrackersOverThreshold()
);
fullResetDetector
.setNumberTrackersOverThreshold(
config.getNumberTrackersOverThreshold()
);
mountingResetDetector
.setNumberTrackersOverThreshold(
config.getNumberTrackersOverThreshold()
);
}
public void update() {