Closed jeremydk closed 4 years ago
Added some logging -- we're passing a nextPedalTime that ends up being in the past, which causes these to rapid-fire through.
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.185Z] received stats from bike [power=0W cadence=0rpm]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.490Z] received stats from bike [power=0W cadence=25rpm]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173497 timeSinceLast: 43374.333251953125 nextPedalTime: 1601864132522.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.504Z] pedal stroke [timestamp=1601864132522.6667 revolutions=3 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173509 timeSinceLast: 40986.333251953125 nextPedalTime: 1601864134922.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.515Z] pedal stroke [timestamp=1601864134922.6667 revolutions=4 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173520 timeSinceLast: 38597.333251953125 nextPedalTime: 1601864137322.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.526Z] pedal stroke [timestamp=1601864137322.6667 revolutions=5 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173530 timeSinceLast: 36207.333251953125 nextPedalTime: 1601864139722.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.537Z] pedal stroke [timestamp=1601864139722.6667 revolutions=6 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173542 timeSinceLast: 33819.333251953125 nextPedalTime: 1601864142122.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.548Z] pedal stroke [timestamp=1601864142122.6667 revolutions=7 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173553 timeSinceLast: 31430.333251953125 nextPedalTime: 1601864144522.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.559Z] pedal stroke [timestamp=1601864144522.6667 revolutions=8 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173563 timeSinceLast: 29040.333251953125 nextPedalTime: 1601864146922.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.570Z] pedal stroke [timestamp=1601864146922.6667 revolutions=9 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173575 timeSinceLast: 26652.333251953125 nextPedalTime: 1601864149322.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.580Z] pedal stroke [timestamp=1601864149322.6667 revolutions=10 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173586 timeSinceLast: 24263.333251953125 nextPedalTime: 1601864151722.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.593Z] pedal stroke [timestamp=1601864151722.6667 revolutions=11 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173596 timeSinceLast: 21873.333251953125 nextPedalTime: 1601864154122.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.602Z] pedal stroke [timestamp=1601864154122.6667 revolutions=12 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173605 timeSinceLast: 19482.333251953125 nextPedalTime: 1601864156522.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.610Z] pedal stroke [timestamp=1601864156522.6667 revolutions=13 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173613 timeSinceLast: 17090.333251953125 nextPedalTime: 1601864158922.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.618Z] pedal stroke [timestamp=1601864158922.6667 revolutions=14 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173621 timeSinceLast: 14698.333251953125 nextPedalTime: 1601864161322.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.626Z] pedal stroke [timestamp=1601864161322.6667 revolutions=15 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173629 timeSinceLast: 12306.333251953125 nextPedalTime: 1601864163722.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.633Z] pedal stroke [timestamp=1601864163722.6667 revolutions=16 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173636 timeSinceLast: 9913.333251953125 nextPedalTime: 1601864166122.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.641Z] pedal stroke [timestamp=1601864166122.6667 revolutions=17 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173644 timeSinceLast: 7521.333251953125 nextPedalTime: 1601864168522.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.649Z] pedal stroke [timestamp=1601864168522.6667 revolutions=18 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173652 timeSinceLast: 5129.333251953125 nextPedalTime: 1601864170922.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.656Z] pedal stroke [timestamp=1601864170922.6667 revolutions=19 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173659 timeSinceLast: 2736.333251953125 nextPedalTime: 1601864173322.6667
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:13.664Z] pedal stroke [timestamp=1601864173322.6667 revolutions=20 power=0W]
Oct 04 22:16:13 gymnasticon gymnasticon[1946]: now: 1601864173667 timeSinceLast: 344.333251953125 nextPedalTime: 1601864175722.6667
Oct 04 22:16:14 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:14.098Z] received stats from bike [power=3W cadence=24rpm]
Oct 04 22:16:14 gymnasticon gymnasticon[1946]: now: 1601864174102 timeSinceLast: 779.333251953125 nextPedalTime: 1601864175822.6667
Oct 04 22:16:14 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:14.700Z] received stats from bike [power=3W cadence=24rpm]
Oct 04 22:16:14 gymnasticon gymnasticon[1946]: now: 1601864174705 timeSinceLast: 1382.333251953125 nextPedalTime: 1601864175822.6667
Oct 04 22:16:15 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:15.003Z] received stats from bike [power=3W cadence=24rpm]
Oct 04 22:16:15 gymnasticon gymnasticon[1946]: now: 1601864175009 timeSinceLast: 1686.333251953125 nextPedalTime: 1601864175822.6667
Oct 04 22:16:15 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:15.609Z] received stats from bike [power=3W cadence=23rpm]
Oct 04 22:16:15 gymnasticon gymnasticon[1946]: now: 1601864175620 timeSinceLast: 2297.333251953125 nextPedalTime: 1601864175931.3623
Oct 04 22:16:15 gymnasticon gymnasticon[1946]: [2020-10-05T02:16:15.936Z] pedal stroke [timestamp=1601864175931.3623 revolutions=21 power=3W]
Initial testing of clamping nextPedalTime looks like a good call for now - only did one test ride to confirm for now, need to think through how we can add some tests around this behavior.
src/app/simulation.js
62: let nextPedalTime = Math.max(now, (now - timeSinceLast + this._interval));
Thanks for reporting this! I agree it would be good to add some tests here. I'll have a look at pushing out this fix tomorrow morning.
I just pushed up #18 but can't actually test it with a bike right now. I think it should fix this issue, hopefully also the Garmin issue you mentioned earlier, and also adds some tests around pedal timestamps and cadence changes. As soon as I have a chance to test it properly I'll push out a fix -- if you have a chance in the meantime, let me know how it goes!
Initial test last night looked good.
Nice, just tested here too and looks good.
After a period of time sitting at zero cadence, the first non-zero cadence update will generate a bunch of pedal events:
An initial readthrough of
src/app/simulation.js
leads me to believe this has to do with the early return in schedulePedal(), but I'd need to tease through this logic a bit more directly.