ADD speedometer implementation

This commit is contained in:
fastium 2024-11-05 15:30:12 +01:00
parent 0d18073562
commit ac8e030089

View File

@ -107,10 +107,13 @@ void Speedometer::computeSpeed() {
// = 6.99m If you ride at 80 pedal turns / min, you run a distance of 6.99 * 80 / min // = 6.99m If you ride at 80 pedal turns / min, you run a distance of 6.99 * 80 / min
// ~= 560 m / min = 33.6 km/h // ~= 560 m / min = 33.6 km/h
// TODO // TODO : done
//Distance run with one pedal turn = tray size / rear gear size * circumference of the wheel //Distance run with one pedal turn = tray size / rear gear size * circumference of the wheel
std::chrono::seconds pedal_rotation_time = std::chrono::duration_cast<std::chrono::seconds>(this->_pedalRotationTime).count(); float ms_in_hour = static_cast<float>(3600 * 1000);
this->_currentSpeed = static_cast<float>(kTraySize) / this->_gearSize * this->kWheelCircumference * ; 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;
this->_currentSpeed = gear_ratio * wheel_dist_km * pedal_rotation_per_hour;
} }
void Speedometer::computeDistance() { void Speedometer::computeDistance() {
@ -122,8 +125,14 @@ void Speedometer::computeDistance() {
// ~= 560 m / min = 33.6 km/h. We then multiply the speed by the time for getting the // ~= 560 m / min = 33.6 km/h. We then multiply the speed by the time for getting the
// distance traveled. // distance traveled.
// TODO // 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;
this->_totalDistanceMutex.lock();
this->_totalDistance += traveled_dist;
this->_totalDistanceMutex.unlock();
} }
} // namespace bike_computer } // namespace bike_computer