diff --git a/mission/controller/PowerController.cpp b/mission/controller/PowerController.cpp index 7b7db9e8..202e9906 100644 --- a/mission/controller/PowerController.cpp +++ b/mission/controller/PowerController.cpp @@ -156,7 +156,7 @@ ReturnValue_t PowerController::checkModeCommand(Mode_t mode, Submode_t submode, void PowerController::calculateStateOfCharge() { // get time - Clock::getClock_timeval(&now); + Clock::getClockMonotonic(&now); // update EPS HK values ReturnValue_t result = updateEpsData(); @@ -285,7 +285,12 @@ ReturnValue_t PowerController::calculateOpenCircuitVoltageCharge() { } ReturnValue_t PowerController::calculateCoulombCounterCharge() { - double timeDiff = timevalOperations::toDouble(now - oldTime); + double timeDiff = 0.0; + if (timevalOperations::toDouble(oldTime) != 0) { + timeDiff = timevalOperations::toDouble(now - oldTime); + } else { + return returnvalue::FAILED; + } if (timeDiff > maxAllowedTimeDiff) { // should not be a permanent state so no spam protection required triggerEvent(power::TIMEDELTA_OUT_OF_BOUNDS, static_cast(timeDiff * 10));