eive-obsw/mission/controller/ThermalController.h

265 lines
9.0 KiB
C
Raw Normal View History

2021-01-08 09:34:43 +01:00
#ifndef MISSION_CONTROLLER_THERMALCONTROLLER_H_
#define MISSION_CONTROLLER_THERMALCONTROLLER_H_
#include <fsfw/controller/ExtendedControllerBase.h>
2023-01-17 15:55:36 +01:00
#include <fsfw/devicehandlers/DeviceHandlerThermalSet.h>
2022-06-17 08:31:36 +02:00
#include <fsfw/timemanager/Countdown.h>
#include <mission/controller/controllerdefinitions/tcsCtrlDefs.h>
#include <mission/devices/devicedefinitions/Max31865Definitions.h>
2022-05-23 00:37:49 +02:00
#include <mission/devices/devicedefinitions/Tmp1075Definitions.h>
2023-02-28 19:14:15 +01:00
#include <mission/devices/devicedefinitions/susMax1227Helpers.h>
2022-11-27 16:58:57 +01:00
#include <list>
#include "mission/devices/HeaterHandler.h"
2023-02-17 11:50:14 +01:00
#include "mission/devices/devicedefinitions/GomspaceDefinitions.h"
2023-02-14 11:18:51 +01:00
#include "mission/trace.h"
2022-11-24 16:40:59 +01:00
2022-11-24 15:51:24 +01:00
/**
* NOP Limit: Hard limit for device, usually from datasheet. Device damage is possible lif NOP limit
* is exceeded.
2022-11-24 16:40:59 +01:00
* OP Limit: Soft limit. Device should be switched off or TCS controller should take action if the
* limit is exceeded to avoid reaching NOP limit
2022-11-24 15:51:24 +01:00
*/
2022-11-16 17:33:19 +01:00
struct TempLimits {
2022-12-13 10:19:28 +01:00
TempLimits(float nopLowerLimit, float opLowerLimit, float cutOffLimit, float opUpperLimit,
float nopUpperLimit)
2022-11-24 16:40:59 +01:00
: opLowerLimit(opLowerLimit),
opUpperLimit(opUpperLimit),
2022-12-12 20:07:54 +01:00
cutOffLimit(cutOffLimit),
2022-11-24 16:40:59 +01:00
nopLowerLimit(nopLowerLimit),
nopUpperLimit(nopUpperLimit) {}
2022-11-24 11:35:05 +01:00
float opLowerLimit;
float opUpperLimit;
2022-12-12 20:07:54 +01:00
float cutOffLimit;
2022-11-24 11:35:05 +01:00
float nopLowerLimit;
float nopUpperLimit;
2022-11-16 17:33:19 +01:00
};
2023-02-22 21:46:56 +01:00
struct ThermalState {
2023-02-22 19:14:35 +01:00
uint8_t errorCounter;
bool heating;
2023-02-22 21:46:56 +01:00
uint32_t heaterStartTime;
2023-02-22 19:14:35 +01:00
};
2023-02-22 21:46:56 +01:00
struct HeaterState {
2023-03-05 13:05:32 +01:00
bool switchTransition;
uint8_t heaterSwitchControlErrorCounter;
2023-02-22 21:46:56 +01:00
};
enum ThermalComponents : uint8_t {
NONE = 0,
2023-02-24 13:39:23 +01:00
ACS_BOARD = 1,
MGT = 2,
RW = 3,
STR = 4,
IF_BOARD = 5,
TCS_BOARD = 6,
OBC = 7,
OBCIF_BOARD = 8,
SBAND_TRANSCEIVER = 9,
PCDUP60_BOARD = 10,
PCDUACU = 11,
PCDUPDU = 12,
PLPCDU_BOARD = 13,
PLOCMISSION_BOARD = 14,
PLOCPROCESSING_BOARD = 15,
DAC = 16,
CAMERA = 17,
DRO = 18,
X8 = 19,
HPA = 20,
TX = 21,
MPA = 22,
SCEX_BOARD = 23,
NUM_ENTRIES
2023-02-10 12:18:16 +01:00
};
class ThermalController : public ExtendedControllerBase {
2022-01-17 15:58:27 +01:00
public:
2022-05-23 00:37:49 +02:00
static const uint16_t INVALID_TEMPERATURE = 999;
2022-11-27 16:58:57 +01:00
static const uint8_t NUMBER_OF_SENSORS = 16;
2022-05-23 00:37:49 +02:00
2022-11-23 19:38:30 +01:00
ThermalController(object_id_t objectId, HeaterHandler& heater);
2021-01-08 09:34:43 +01:00
2022-02-17 16:29:22 +01:00
ReturnValue_t initialize() override;
protected:
void performThermalModuleCtrl();
2023-02-06 17:10:09 +01:00
ReturnValue_t handleCommandMessage(CommandMessage* message) override;
void performControlOperation() override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
2023-02-07 14:28:42 +01:00
LocalDataPoolManager& poolManager) override;
2023-02-06 17:10:09 +01:00
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
// Mode abstract functions
2023-02-06 17:10:09 +01:00
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
2023-02-07 14:28:42 +01:00
uint32_t* msToReachTheMode) override;
private:
2023-03-16 18:28:51 +01:00
static const uint32_t INIT_DELAY = 1500;
2022-11-28 10:06:49 +01:00
static const uint32_t TEMP_OFFSET = 5;
2022-06-17 08:31:36 +02:00
enum class InternalState { STARTUP, INITIAL_DELAY, READY };
InternalState internalState = InternalState::STARTUP;
2022-11-24 16:40:59 +01:00
HeaterHandler& heaterHandler;
2023-02-21 01:53:23 +01:00
tcsCtrl::SensorTemperatures sensorTemperatures;
tcsCtrl::SusTemperatures susTemperatures;
tcsCtrl::DeviceTemperatures deviceTemperatures;
tcsCtrl::HeaterInfo heaterInfo;
2023-01-24 15:46:20 +01:00
lp_vec_t<int16_t, 9> currentVecPdu2 =
lp_vec_t<int16_t, 9>(gp_id_t(objects::PDU2_HANDLER, PDU::pool::PDU_CURRENTS));
2023-01-17 15:45:54 +01:00
DeviceHandlerThermalSet imtqThermalSet;
// Temperature Sensors
2023-03-15 15:13:53 +01:00
MAX31865::PrimarySet maxSet0PlocHspd;
MAX31865::PrimarySet maxSet1PlocMissionBrd;
MAX31865::PrimarySet maxSet2PlCam;
MAX31865::PrimarySet maxSet3DacHspd;
MAX31865::PrimarySet maxSet4Str;
MAX31865::PrimarySet maxSet5Rw1MxMy;
MAX31865::PrimarySet maxSet6Dro;
MAX31865::PrimarySet maxSet7Scex;
MAX31865::PrimarySet maxSet8X8;
MAX31865::PrimarySet maxSet9Hpa;
MAX31865::PrimarySet maxSet10EbandTx;
MAX31865::PrimarySet maxSet11Mpa;
MAX31865::PrimarySet maxSet31865Set12;
MAX31865::PrimarySet maxSet13PlPcduHspd;
MAX31865::PrimarySet maxSet14TcsBrd;
MAX31865::PrimarySet maxSet15Imtq;
2023-01-09 11:57:48 +01:00
2022-11-14 10:04:41 +01:00
TMP1075::Tmp1075Dataset tmp1075SetTcs0;
TMP1075::Tmp1075Dataset tmp1075SetTcs1;
TMP1075::Tmp1075Dataset tmp1075SetPlPcdu0;
2023-01-09 11:57:48 +01:00
// damaged
// TMP1075::Tmp1075Dataset tmp1075SetPlPcdu1;
2022-11-14 10:04:41 +01:00
TMP1075::Tmp1075Dataset tmp1075SetIfBoard;
// SUS
2023-02-28 19:14:15 +01:00
susMax1227::SusDataset susSet0;
susMax1227::SusDataset susSet1;
susMax1227::SusDataset susSet2;
susMax1227::SusDataset susSet3;
susMax1227::SusDataset susSet4;
susMax1227::SusDataset susSet5;
susMax1227::SusDataset susSet6;
susMax1227::SusDataset susSet7;
susMax1227::SusDataset susSet8;
susMax1227::SusDataset susSet9;
susMax1227::SusDataset susSet10;
susMax1227::SusDataset susSet11;
2022-05-23 00:37:49 +02:00
2022-11-24 16:40:59 +01:00
// TempLimits
2022-12-12 20:07:54 +01:00
TempLimits acsBoardLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0);
TempLimits mgtLimits = TempLimits(-40.0, -40.0, 65.0, 70.0, 70.0);
TempLimits rwLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0);
TempLimits strLimits = TempLimits(-30.0, -20.0, 65.0, 70.0, 80.0);
TempLimits ifBoardLimits = TempLimits(-65.0, -40.0, 80.0, 85.0, 150.0);
TempLimits tcsBoardLimits = TempLimits(-60.0, -40.0, 80.0, 85.0, 130.0);
TempLimits obcLimits = TempLimits(-40.0, -40.0, 80.0, 85.0, 85.0);
TempLimits obcIfBoardLimits = TempLimits(-65.0, -40.0, 80.0, 85.0, 125.0);
TempLimits sBandTransceiverLimits = TempLimits(-40.0, -25.0, 35.0, 40.0, 65.0);
TempLimits pcduP60BoardLimits = TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0);
TempLimits pcduAcuLimits = TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0);
TempLimits pcduPduLimits = TempLimits(-35.0, -35.0, 80.0, 85.0, 85.0);
TempLimits plPcduBoardLimits = TempLimits(-55.0, -40.0, 80.0, 85.0, 125.0);
TempLimits plocMissionBoardLimits = TempLimits(-30.0, -10.0, 40.0, 45.0, 60);
TempLimits plocProcessingBoardLimits = TempLimits(-30.0, -10.0, 40.0, 45.0, 60.0);
TempLimits dacLimits = TempLimits(-65.0, -40.0, 113.0, 118.0, 150.0);
TempLimits cameraLimits = TempLimits(-40.0, -30.0, 60.0, 65.0, 85.0);
TempLimits droLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0);
2023-03-08 15:56:05 +01:00
TempLimits x8Limits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0);
TempLimits hpaLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0);
TempLimits txLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0);
TempLimits mpaLimits = TempLimits(-40.0, -30.0, 75.0, 80.0, 90.0);
2022-12-12 20:07:54 +01:00
TempLimits scexBoardLimits = TempLimits(-60.0, -40.0, 80.0, 85.0, 150.0);
2022-11-16 17:33:19 +01:00
2023-02-06 17:10:09 +01:00
double sensorTemp = INVALID_TEMPERATURE;
ThermalComponents thermalComponent = NONE;
2022-12-14 11:24:03 +01:00
bool redSwitchNrInUse = false;
MessageQueueId_t camId = MessageQueueIF::NO_QUEUE;
2023-02-06 17:10:09 +01:00
bool componentAboveCutOffLimit = false;
bool componentAboveUpperLimit = false;
Event overHeatEventToTrigger;
bool eBandTooHotFlag = false;
bool camTooHotOneShotFlag = false;
bool scexTooHotFlag = false;
bool plocTooHotFlag = false;
bool pcduSystemTooHotFlag = false;
bool syrlinksTooHotFlag = false;
bool obcTooHotFlag = false;
bool strTooHotFlag = false;
bool rwTooHotFlag = false;
2023-03-15 16:19:37 +01:00
uint32_t cycles = 0;
2023-02-22 21:46:56 +01:00
std::array<ThermalState, 30> thermalStates{};
std::array<HeaterState, 7> heaterStates{};
2022-12-14 11:24:03 +01:00
2023-03-15 16:19:37 +01:00
// Initial delay to make sure all pool variables have been initialized their owners.
// Also, wait for system initialization to complete.
Countdown initialCountdown = Countdown(INIT_DELAY);
2023-02-14 11:18:51 +01:00
#if OBSW_THREAD_TRACING == 1
uint32_t opCounter = 0;
#endif
2023-02-07 14:28:42 +01:00
std::array<std::pair<bool, double>, 5> sensors;
2023-02-06 17:10:09 +01:00
uint8_t numSensors = 0;
2023-01-24 15:35:56 +01:00
PoolEntry<float> tmp1075Tcs0 = PoolEntry<float>({10.0});
PoolEntry<float> tmp1075Tcs1 = PoolEntry<float>({10.0});
PoolEntry<float> tmp1075PlPcdu0 = PoolEntry<float>({10.0});
PoolEntry<float> tmp1075PlPcdu1 = PoolEntry<float>({10.0});
PoolEntry<float> tmp1075IfBrd = PoolEntry<float>({10.0});
PoolEntry<uint8_t> heaterSwitchStates = PoolEntry<uint8_t>(heater::NUMBER_OF_SWITCHES);
PoolEntry<int16_t> heaterCurrent = PoolEntry<int16_t>();
static constexpr dur_millis_t MUTEX_TIMEOUT = 50;
2022-12-14 11:24:03 +01:00
2023-02-06 17:10:09 +01:00
void resetSensorsArray();
void copySensors();
void copySus();
2022-05-23 00:37:49 +02:00
void copyDevices();
2022-11-28 17:40:29 +01:00
2023-01-23 22:29:29 +01:00
void ctrlComponentTemperature(heater::Switchers switchNr, heater::Switchers redSwitchNr,
2023-03-15 14:36:18 +01:00
const TempLimits& tempLimit);
void checkLimitsAndCtrlHeater(heater::Switchers switchNr, heater::Switchers redSwitchNr,
2023-03-15 14:36:18 +01:00
const TempLimits& tempLimit);
2023-02-06 17:10:09 +01:00
bool chooseHeater(heater::Switchers& switchNr, heater::Switchers redSwitchNr);
2023-02-07 14:28:42 +01:00
bool selectAndReadSensorTemp();
2022-12-13 12:08:53 +01:00
void ctrlAcsBoard();
void ctrlMgt();
void ctrlRw();
void ctrlStr();
void ctrlIfBoard();
void ctrlTcsBoard();
void ctrlObc();
void ctrlObcIfBoard();
void ctrlSBandTransceiver();
void ctrlPcduP60Board();
void ctrlPcduAcu();
void ctrlPcduPdu();
void ctrlPlPcduBoard();
void ctrlPlocMissionBoard();
void ctrlPlocProcessingBoard();
void ctrlDac();
void ctrlCameraBody();
void ctrlDro();
void ctrlX8();
void ctrlHpa();
void ctrlTx();
void ctrlMpa();
void ctrlScexBoard();
2023-02-22 21:46:56 +01:00
void heaterTransitionControl();
uint32_t tempFloatToU32() const;
void tooHotHandler(object_id_t object, bool& oneShotFlag);
2021-01-08 09:34:43 +01:00
};
#endif /* MISSION_CONTROLLER_THERMALCONTROLLER_H_ */