diff --git a/hal/src/main/native/athena/DIO.cpp b/hal/src/main/native/athena/DIO.cpp index 23c5ab331b..38c90e455f 100644 --- a/hal/src/main/native/athena/DIO.cpp +++ b/hal/src/main/native/athena/DIO.cpp @@ -191,8 +191,8 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) { if (*status != 0) { return; } - uint16_t pwmPeriodPower = static_cast( - std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0) + 0.5); + uint16_t pwmPeriodPower = + std::lround(std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0)); digitalSystem->writePWMPeriodPower(pwmPeriodPower, status); } diff --git a/hal/src/main/native/athena/DigitalInternal.cpp b/hal/src/main/native/athena/DigitalInternal.cpp index d47cedfb45..c75c66b3ba 100644 --- a/hal/src/main/native/athena/DigitalInternal.cpp +++ b/hal/src/main/native/athena/DigitalInternal.cpp @@ -5,6 +5,7 @@ #include "DigitalInternal.h" #include +#include #include #include @@ -108,10 +109,10 @@ void initializeDigital(int32_t* status) { double loopTime = pwmSystem->readLoopTiming(status) / (kSystemClockTicksPerMicrosecond * 1e3); - pwmSystem->writeConfig_Period( - static_cast(kDefaultPwmPeriod / loopTime + 0.5), status); - uint16_t minHigh = static_cast( - (kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + 0.5); + pwmSystem->writeConfig_Period(std::lround(kDefaultPwmPeriod / loopTime), + status); + uint16_t minHigh = std::lround( + (kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime); pwmSystem->writeConfig_MinHigh(minHigh, status); // Ensure that PWM output values are set to OFF for (uint8_t pwmIndex = 0; pwmIndex < kNumPWMChannels; pwmIndex++) { diff --git a/hal/src/main/native/athena/PWM.cpp b/hal/src/main/native/athena/PWM.cpp index 873d447ee4..19b7b49f69 100644 --- a/hal/src/main/native/athena/PWM.cpp +++ b/hal/src/main/native/athena/PWM.cpp @@ -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( - speed * static_cast(GetPositiveScaleFactor(dPort)) + - static_cast(GetMinPositivePwm(dPort)) + 0.5); + rawValue = + std::lround(speed * static_cast(GetPositiveScaleFactor(dPort)) + + static_cast(GetMinPositivePwm(dPort))); } else { - rawValue = static_cast( - speed * static_cast(GetNegativeScaleFactor(dPort)) + - static_cast(GetMaxNegativePwm(dPort)) + 0.5); + rawValue = + std::lround(speed * static_cast(GetNegativeScaleFactor(dPort)) + + static_cast(GetMaxNegativePwm(dPort))); } if (!((rawValue >= GetMinNegativePwm(dPort)) &&