diff --git a/mission/controller/PowerController.cpp b/mission/controller/PowerController.cpp index 054fcfd2..a7dbd37c 100644 --- a/mission/controller/PowerController.cpp +++ b/mission/controller/PowerController.cpp @@ -4,7 +4,8 @@ PowerController::PowerController(object_id_t objectId, bool enableHkSets) : ExtendedControllerBase(objectId), enableHkSets(enableHkSets), parameterHelper(this), - pwrCtrlCoreHk(this) {} + pwrCtrlCoreHk(this), + enablePl(this) {} ReturnValue_t PowerController::initialize() { ReturnValue_t result = parameterHelper.initialize(); @@ -54,9 +55,12 @@ ReturnValue_t PowerController::getParameter(uint8_t domainId, uint8_t parameterI parameterWrapper->set(maxAllowedTimeDiff); break; case 0x4: - parameterWrapper->set(payloadLimit); + parameterWrapper->set(payloadOpLimitOn); break; case 0x5: + parameterWrapper->set(payloadOpLimitLow); + break; + case 0x6: parameterWrapper->set(higherModesLimit); break; default: @@ -110,6 +114,8 @@ ReturnValue_t PowerController::initializeLocalDataPool(localpool::DataPool &loca new PoolEntry({0.0})); localDataPoolMap.emplace(pwrctrl::PoolIds::COULOMB_COUNTER_CHARGE, new PoolEntry({0.0})); poolManager.subscribeForRegularPeriodicPacket({pwrCtrlCoreHk.getSid(), enableHkSets, 60.0}); + localDataPoolMap.emplace(pwrctrl::PoolIds::PAYLOAD_FLAG, new PoolEntry({false})); + poolManager.subscribeForRegularPeriodicPacket({enablePl.getSid(), false, 60.0}); return returnvalue::OK; } @@ -117,6 +123,8 @@ LocalPoolDataSetBase *PowerController::getDataSetHandle(sid_t sid) { switch (sid.ownerSetId) { case pwrctrl::CORE_HK: return &pwrCtrlCoreHk; + case pwrctrl::ENABLE_PL: + return &enablePl; default: return nullptr; } @@ -217,7 +225,20 @@ void PowerController::calculateStateOfCharge() { void PowerController::watchStateOfCharge() { if (pwrCtrlCoreHk.coulombCounterCharge.isValid()) { - if (not pwrLvlLowFlag and pwrCtrlCoreHk.coulombCounterCharge.value < payloadLimit) { + if (pwrCtrlCoreHk.coulombCounterCharge.value < payloadOpLimitOn) { + PoolReadGuard pg(&enablePl); + if (pg.getReadResult() == returnvalue::OK) { + enablePl.plUseAllowed.value = false; + enablePl.plUseAllowed.setValid(true); + } + } else { + PoolReadGuard pg(&enablePl); + if (pg.getReadResult() == returnvalue::OK) { + enablePl.plUseAllowed.value = true; + enablePl.plUseAllowed.setValid(true); + } + } + if (not pwrLvlLowFlag and pwrCtrlCoreHk.coulombCounterCharge.value < payloadOpLimitLow) { triggerEvent(power::POWER_LEVEL_LOW); pwrLvlLowFlag = true; } else { @@ -229,6 +250,12 @@ void PowerController::watchStateOfCharge() { } else { pwrLvlCriticalFlag = false; } + } else { + PoolReadGuard pg(&enablePl); + if (pg.getReadResult() == returnvalue::OK) { + enablePl.plUseAllowed.value = false; + enablePl.plUseAllowed.setValid(true); + } } } diff --git a/mission/controller/PowerController.h b/mission/controller/PowerController.h index e374391e..afab21b4 100644 --- a/mission/controller/PowerController.h +++ b/mission/controller/PowerController.h @@ -57,7 +57,8 @@ class PowerController : public ExtendedControllerBase, public ReceivesParameterM float batteryMaximumCapacity = 2.6 * 2; // [Ah] float coulombCounterVoltageUpperThreshold = 16.2; // [V] double maxAllowedTimeDiff = 0.5; // [s] - float payloadLimit = 0.75; // [%] + float payloadOpLimitOn = 0.90; // [%] + float payloadOpLimitLow = 0.75; // [%] float higherModesLimit = 0.6; // [%] // OCV Look-up-Table {[Ah],[V]} @@ -121,6 +122,8 @@ class PowerController : public ExtendedControllerBase, public ReceivesParameterM P60Dock::CoreHkSet p60CoreHk = P60Dock::CoreHkSet(objects::P60DOCK_HANDLER); // Output Dataset pwrctrl::CoreHk pwrCtrlCoreHk; + // Dataset for PL Flag + pwrctrl::EnablePl enablePl; }; #endif /* MISSION_CONTROLLER_POWERCONTROLLER_H_ */ diff --git a/mission/controller/controllerdefinitions/PowerCtrlDefinitions.h b/mission/controller/controllerdefinitions/PowerCtrlDefinitions.h index f7cce708..ff090e5b 100644 --- a/mission/controller/controllerdefinitions/PowerCtrlDefinitions.h +++ b/mission/controller/controllerdefinitions/PowerCtrlDefinitions.h @@ -10,15 +10,17 @@ namespace pwrctrl { -enum SetIds : uint32_t { CORE_HK }; +enum SetIds : uint32_t { CORE_HK, ENABLE_PL }; enum PoolIds : lp_id_t { TOTAL_BATTERY_CURRENT, OPEN_CIRCUIT_VOLTAGE_CHARGE, COULOMB_COUNTER_CHARGE, + PAYLOAD_FLAG }; static constexpr uint8_t CORE_HK_ENTRIES = 3; +static constexpr uint8_t ENABLE_PL_ENTRIES = 1; class CoreHk : public StaticLocalDataSet { public: @@ -34,6 +36,15 @@ class CoreHk : public StaticLocalDataSet { private: }; +class EnablePl : public StaticLocalDataSet { + public: + EnablePl(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, ENABLE_PL) {} + + lp_var_t plUseAllowed = lp_var_t(sid.objectId, PAYLOAD_FLAG, this); + + private: +}; + } // namespace pwrctrl #endif /* MISSION_CONTROLLER_CONTROLLERDEFINITIONS_POWERCTRLDEFINITIONS_H_ */