FIX distance calculation in speedometer.
This commit is contained in:
parent
69047369f0
commit
a7c28c0e52
@ -109,7 +109,7 @@ void Speedometer::computeSpeed() {
|
||||
|
||||
// TODO : done
|
||||
//Distance run with one pedal turn = tray size / rear gear size * circumference of the wheel
|
||||
float ms_in_hour = static_cast<float>(3600 * 1000);
|
||||
constexpr float ms_in_hour = static_cast<float>(3600 * 1000);
|
||||
float pedal_rotation_per_hour = ms_in_hour / static_cast<float>(_pedalRotationTime.count());
|
||||
float gear_ratio = static_cast<float>(kTraySize) / static_cast<float>(this->_gearSize);
|
||||
float wheel_dist_km = static_cast<float>(this->kWheelCircumference) / 1000.0;
|
||||
@ -128,11 +128,17 @@ void Speedometer::computeDistance() {
|
||||
// TODO : done
|
||||
Speedometer::computeSpeed();
|
||||
// compute distance
|
||||
float last_time_in_hour = static_cast<float>(std::chrono::duration_cast<std::chrono::hours>(this->_lastTime).count());
|
||||
float traveled_dist = this->_currentSpeed * last_time_in_hour;
|
||||
|
||||
const std::chrono::microseconds timeNow = _timer.elapsed_time();
|
||||
const std::chrono::microseconds timeDiff = timeNow - _lastTime;
|
||||
constexpr float ms_in_hour = static_cast<float>(3600 * 1000);
|
||||
float traveled_dist = _currentSpeed * timeDiff.count() / (ms_in_hour*1000.0/*μs*/);
|
||||
|
||||
this->_totalDistanceMutex.lock();
|
||||
this->_totalDistance += traveled_dist;
|
||||
this->_totalDistanceMutex.unlock();
|
||||
|
||||
_lastTime = _timer.elapsed_time();
|
||||
}
|
||||
|
||||
} // namespace bike_computer
|
Loading…
x
Reference in New Issue
Block a user