You are here: Forum Home → ANT+ Forums → ANT+ Bike Power → Thread
Ian Haigh
Ian Haigh
Ian Haigh
# The event counter has reached 256, so the next event_count value equals 1, thus ...
if event_count < event_count_old:
# It's a rollover condition; adjust the previous value to an arbitrary value of 1
event_count_old = event_count_old - 255
# Allow the equation to run under specific conditions
if (event_count - event_count_old) > 0 and ((wheel_period - wheel_period_old) / 2048) > 0:
# The wheel is turning...run the formula (km/h)
speed = (3600/1000) * ((2.133 * (event_count - event_count_old)) / ((wheel_period - wheel_period_old) / 2048))
# Compare this value to the speed displayed in the Joule GPS head unit
print(f"speed... {speed:.1f}")
# Some condition statement is likely needed here...
else:
# The wheel isn't turning, speed is zero.
speed = 0.0
# Compare the value...
print(f"speed... {speed:.1f}\n")
# See what's happening with the other parts of the formula
print(f"events new, old: {event_count} {event_count_old}\n"
f"wheel periods new, old: {wheel_period} {wheel_period_old} {(wheel_period - wheel_period_old) / 2048} seconds\n"
f"partial formula: {(event_count - event_cound_old) / ((wheel_period - wheel_period_old) / 2048)}")
event_count_old = event_count
wheel_period_old = wheel_period
Ian Haigh