[hal] Use std::lround() instead of adding 0.5 and truncating (#3012)

This commit is contained in:
Peter Johnson
2021-03-19 14:24:46 -07:00
committed by GitHub
parent 48e9f39513
commit 160fb740f4
3 changed files with 13 additions and 12 deletions

View File

@@ -277,13 +277,13 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
if (speed == 0.0) {
rawValue = GetCenterPwm(dPort);
} else if (speed > 0.0) {
rawValue = static_cast<int32_t>(
speed * static_cast<double>(GetPositiveScaleFactor(dPort)) +
static_cast<double>(GetMinPositivePwm(dPort)) + 0.5);
rawValue =
std::lround(speed * static_cast<double>(GetPositiveScaleFactor(dPort)) +
static_cast<double>(GetMinPositivePwm(dPort)));
} else {
rawValue = static_cast<int32_t>(
speed * static_cast<double>(GetNegativeScaleFactor(dPort)) +
static_cast<double>(GetMaxNegativePwm(dPort)) + 0.5);
rawValue =
std::lround(speed * static_cast<double>(GetNegativeScaleFactor(dPort)) +
static_cast<double>(GetMaxNegativePwm(dPort)));
}
if (!((rawValue >= GetMinNegativePwm(dPort)) &&