From 2210c461623b97eea1ec700cae4cc27ab5042376 Mon Sep 17 00:00:00 2001 From: Lars Berning <151194+laberning@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:55:27 +0100 Subject: [PATCH] improves metrics of first stroke by setting reasonable initial values --- app/engine/RowingEngine.js | 17 ++++++++++++----- app/engine/RowingEngine.test.js | 4 ++-- app/engine/WorkoutRecorder.js | 1 - 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/engine/RowingEngine.js b/app/engine/RowingEngine.js index 3db1723..ef8ea5a 100644 --- a/app/engine/RowingEngine.js +++ b/app/engine/RowingEngine.js @@ -34,8 +34,8 @@ function createRowingEngine (rowerSettings) { let drivePhaseAngularDisplacement let driveLinearDistance let recoveryPhaseStartTime - let recoveryPhaseStartAngularDisplacement let recoveryPhaseAngularDisplacement + let recoveryPhaseStartAngularDisplacement let recoveryPhaseLength let recoveryStartAngularVelocity let recoveryEndAngularVelocity @@ -293,6 +293,9 @@ function createRowingEngine (rowerSettings) { } function reset () { + // to init displacements with plausible defaults we assume, that one rowing cycle transforms to nine meters of distance... + const defaultDisplacementForRowingCycle = 8.0 / Math.pow(((rowerSettings.dragFactor / 1000000) / rowerSettings.magicConstant), 1.0 / 3.0) + movingDragAverage.reset() cyclePhase = 'Recovery' totalTime = 0.0 @@ -301,11 +304,15 @@ function createRowingEngine (rowerSettings) { drivePhaseStartTime = 0.0 drivePhaseStartAngularDisplacement = 0.0 drivePhaseLength = 2.0 * rowerSettings.minimumDriveTime - drivePhaseAngularDisplacement = rowerSettings.numOfImpulsesPerRevolution + // split defaultDisplacementForRowingCycle to aprox 1/3 for the drive phase + drivePhaseAngularDisplacement = (1.0 / 3.0) * defaultDisplacementForRowingCycle driveLinearDistance = 0.0 - recoveryPhaseStartTime = -2 * rowerSettings.minimumRecoveryTime // Make sure that the first CurrentDt will trigger a detected stroke by faking a recovery phase that is long enough - recoveryPhaseStartAngularDisplacement = -1.0 * rowerSettings.numOfImpulsesPerRevolution - recoveryPhaseAngularDisplacement = rowerSettings.numOfImpulsesPerRevolution + // Make sure that the first CurrentDt will trigger a detected stroke by faking a recovery phase that is long enough + recoveryPhaseStartTime = -2 * rowerSettings.minimumRecoveryTime + // and split defaultDisplacementForRowingCycle to aprox 2/3 for the recovery phase + recoveryPhaseAngularDisplacement = (2.0 / 3.0) * defaultDisplacementForRowingCycle + // set this to the number of impulses required to generate the angular displacement as assumed above + recoveryPhaseStartAngularDisplacement = Math.round(-1.0 * (2.0 / 3.0) * defaultDisplacementForRowingCycle / angularDisplacementPerImpulse) recoveryPhaseLength = 2.0 * rowerSettings.minimumRecoveryTime recoveryStartAngularVelocity = angularDisplacementPerImpulse / rowerSettings.minimumTimeBetweenImpulses recoveryEndAngularVelocity = angularDisplacementPerImpulse / rowerSettings.maximumTimeBetweenImpulses diff --git a/app/engine/RowingEngine.test.js b/app/engine/RowingEngine.test.js index 0685bbf..5c4d224 100644 --- a/app/engine/RowingEngine.test.js +++ b/app/engine/RowingEngine.test.js @@ -61,7 +61,7 @@ test('sample data for WRX700 should produce plausible results with rower profile await replayRowingSession(rowingEngine.handleRotationImpulse, { filename: 'recordings/WRX700_2magnets.csv' }) assert.is(workoutEvaluator.getNumOfStrokes(), 16, 'number of strokes does not meet expectation') assertPowerRange(workoutEvaluator, 50, 220) - assertDistanceRange(workoutEvaluator, 159, 163) + assertDistanceRange(workoutEvaluator, 165, 168) assertStrokeDistanceSumMatchesTotal(workoutEvaluator) }) @@ -72,7 +72,7 @@ test('sample data for DKNR320 should produce plausible results with rower profil await replayRowingSession(rowingEngine.handleRotationImpulse, { filename: 'recordings/DKNR320.csv' }) assert.is(workoutEvaluator.getNumOfStrokes(), 10, 'number of strokes does not meet expectation') assertPowerRange(workoutEvaluator, 75, 200) - assertDistanceRange(workoutEvaluator, 65, 68) + assertDistanceRange(workoutEvaluator, 71, 73) assertStrokeDistanceSumMatchesTotal(workoutEvaluator) }) diff --git a/app/engine/WorkoutRecorder.js b/app/engine/WorkoutRecorder.js index d7ea77f..0cbd312 100644 --- a/app/engine/WorkoutRecorder.js +++ b/app/engine/WorkoutRecorder.js @@ -186,7 +186,6 @@ function createWorkoutRecorder () { const minimumRecordingTimeInSeconds = 10 const rotationImpulseTimeTotal = rotationImpulses.reduce((acc, impulse) => acc + impulse, 0) const strokeTimeTotal = strokes.reduce((acc, stroke) => acc + stroke.strokeTime, 0) - console.log(`strokeTimeTotal: ${strokeTimeTotal} rotationImpulseTimeTotal: ${rotationImpulseTimeTotal} `) if (rotationImpulseTimeTotal < minimumRecordingTimeInSeconds || strokeTimeTotal < minimumRecordingTimeInSeconds) { log.debug(`recording time is less than ${minimumRecordingTimeInSeconds}s, skipping creation of recording files...`) return