eive-obsw/bsp_q7s/core/acsModeTree.cpp

307 lines
14 KiB
C++
Raw Normal View History

2022-04-25 08:48:22 +02:00
#include "acsModeTree.h"
2022-04-22 17:00:23 +02:00
#include <commonObjects.h>
2022-04-22 17:49:28 +02:00
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
2022-04-22 17:00:23 +02:00
#include <fsfw/modes/HasModesIF.h>
2022-04-25 08:48:22 +02:00
#include <fsfw/subsystem/Subsystem.h>
#include <fsfw/subsystem/modes/ModeDefinitions.h>
2022-04-22 17:00:23 +02:00
2022-04-25 08:48:22 +02:00
#include "mission/controller/controllerdefinitions/AcsControllerDefinitions.h"
2022-04-22 17:49:28 +02:00
// Alias for checker function
const auto CHK = satsystem::checkInsert;
static const auto OFF = HasModesIF::MODE_OFF;
static const auto NML = DeviceHandlerIF::MODE_NORMAL;
2022-04-22 17:00:23 +02:00
2022-04-25 08:48:22 +02:00
auto ACS_SEQUENCE_OFF = std::make_pair(acs::CtrlModes::OFF, FixedArrayList<ModeListEntry, 2>());
auto ACS_TABLE_OFF_TGT =
std::make_pair((acs::CtrlModes::OFF << 8) | 1, FixedArrayList<ModeListEntry, 0>());
auto ACS_TABLE_OFF_TRANS =
std::make_pair((acs::CtrlModes::OFF << 8) | 2, FixedArrayList<ModeListEntry, 6>());
auto ACS_SEQUENCE_DETUMBLE =
2022-04-25 10:08:29 +02:00
std::make_pair(acs::CtrlModes::DETUMBLE, FixedArrayList<ModeListEntry, 3>());
2022-04-25 08:48:22 +02:00
auto ACS_TABLE_DETUMBLE_TGT =
2022-04-25 10:08:29 +02:00
std::make_pair((acs::CtrlModes::DETUMBLE << 8) | 1, FixedArrayList<ModeListEntry, 4>());
2022-04-25 08:48:22 +02:00
auto ACS_TABLE_DETUMBLE_TRANS_0 =
std::make_pair((acs::CtrlModes::DETUMBLE << 8) | 2, FixedArrayList<ModeListEntry, 5>());
auto ACS_TABLE_DETUMBLE_TRANS_1 =
std::make_pair((acs::CtrlModes::DETUMBLE << 8) | 3, FixedArrayList<ModeListEntry, 1>());
2022-04-25 10:08:29 +02:00
auto ACS_SEQUENCE_SAFE =
std::make_pair(acs::CtrlModes::SAFE, FixedArrayList<ModeListEntry, 3>());
auto ACS_TABLE_SAFE_TGT =
std::make_pair((acs::CtrlModes::SAFE << 8) | 1, FixedArrayList<ModeListEntry, 4>());
auto ACS_TABLE_SAFE_TRANS_0 =
std::make_pair((acs::CtrlModes::SAFE << 8) | 2, FixedArrayList<ModeListEntry, 5>());
auto ACS_TABLE_SAFE_TRANS_1 =
std::make_pair((acs::CtrlModes::SAFE << 8) | 3, FixedArrayList<ModeListEntry, 1>());
auto ACS_SEQUENCE_IDLE =
std::make_pair(acs::CtrlModes::IDLE, FixedArrayList<ModeListEntry, 3>());
auto ACS_TABLE_IDLE_TGT =
std::make_pair((acs::CtrlModes::IDLE << 8) | 1, FixedArrayList<ModeListEntry, 5>());
auto ACS_TABLE_IDLE_TRANS_0 =
std::make_pair((acs::CtrlModes::IDLE << 8) | 2, FixedArrayList<ModeListEntry, 5>());
auto ACS_TABLE_IDLE_TRANS_1 =
std::make_pair((acs::CtrlModes::IDLE << 8) | 3, FixedArrayList<ModeListEntry, 1>());
auto ACS_SEQUENCE_TARGET_PT =
std::make_pair(acs::CtrlModes::TARGET_PT, FixedArrayList<ModeListEntry, 3>());
auto ACS_TABLE_TARGET_PT_TGT =
std::make_pair((acs::CtrlModes::TARGET_PT << 8) | 1, FixedArrayList<ModeListEntry, 5>());
auto ACS_TABLE_TARGET_PT_TRANS_0 =
std::make_pair((acs::CtrlModes::TARGET_PT << 8) | 2, FixedArrayList<ModeListEntry, 5>());
auto ACS_TABLE_TARGET_PT_TRANS_1 =
std::make_pair((acs::CtrlModes::TARGET_PT << 8) | 3, FixedArrayList<ModeListEntry, 1>());
enum InsertType {
TABLE,
SEQ
};
2022-04-22 17:00:23 +02:00
void satsystem::acsSubsystemInit() {
ModeListEntry entry;
2022-04-25 08:48:22 +02:00
Subsystem* acsSubsystem = new Subsystem(objects::ACS_SUBSYSTEM, objects::EIVE_SYSTEM, 20, 20);
2022-04-22 17:00:23 +02:00
buildOffSequence(acsSubsystem, entry);
2022-04-25 10:08:29 +02:00
buildSafeSequence(acsSubsystem, entry);
2022-04-22 17:49:28 +02:00
buildDetumbleSequence(acsSubsystem, entry);
2022-04-25 10:08:29 +02:00
buildIdleSequence(acsSubsystem, entry);
buildTargetPtSequence(acsSubsystem, entry);
2022-04-22 17:49:28 +02:00
acsSubsystem->setInitialMode(HasModesIF::MODE_OFF);
2022-04-22 17:00:23 +02:00
}
void satsystem::buildOffSequence(Subsystem* ss, ModeListEntry& eh) {
2022-04-22 17:49:28 +02:00
std::string context = "satsystem::buildOffSequence";
auto ctxc = context.c_str();
2022-04-25 10:08:29 +02:00
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode,
ArrayList<ModeListEntry>& table) {
2022-04-25 08:48:22 +02:00
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
2022-04-25 10:08:29 +02:00
CHK(table.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&]( ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
2022-04-25 08:48:22 +02:00
CHK(sequence.insert(eh), ctxc);
};
2022-04-22 17:00:23 +02:00
2022-04-25 10:08:29 +02:00
// OFF Target table is empty
ss->addTable(&ACS_TABLE_OFF_TGT.second, ACS_TABLE_OFF_TGT.first, false, true);
2022-04-22 17:00:23 +02:00
// Build OFF transition
2022-04-25 10:08:29 +02:00
iht(objects::ACS_CONTROLLER, OFF, 0, ACS_TABLE_OFF_TRANS.second);
iht(objects::IMTQ_HANDLER, OFF, 0, ACS_TABLE_OFF_TRANS.second);
iht(objects::STAR_TRACKER, OFF, 0, ACS_TABLE_OFF_TRANS.second);
iht(objects::ACS_BOARD_ASS, OFF, 0, ACS_TABLE_OFF_TRANS.second);
iht(objects::SUS_BOARD_ASS, OFF, 0, ACS_TABLE_OFF_TRANS.second);
iht(objects::RW_ASS, OFF, 0, ACS_TABLE_OFF_TRANS.second);
ss->addTable(&ACS_TABLE_OFF_TRANS.second, ACS_TABLE_OFF_TRANS.first, false, true);
2022-04-22 17:00:23 +02:00
// Build OFF sequence
2022-04-25 10:08:29 +02:00
ihs(ACS_SEQUENCE_OFF.second, ACS_TABLE_OFF_TGT.first, 0, false);
ihs(ACS_SEQUENCE_OFF.second, ACS_TABLE_OFF_TRANS.first, 0, false);
ss->addSequence(&ACS_SEQUENCE_OFF.second, ACS_SEQUENCE_OFF.first, ACS_SEQUENCE_OFF.first, false,
true);
}
2022-04-22 17:00:23 +02:00
2022-04-25 10:08:29 +02:00
void satsystem::buildSafeSequence(Subsystem* ss, ModeListEntry& eh) {
std::string context = "satsystem::buildSafeSequence";
auto ctxc = context.c_str();
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode,
ArrayList<ModeListEntry>& sequence) {
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
CHK(sequence.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&]( ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
CHK(sequence.insert(eh), ctxc);
};
// Build SAFE target
iht(objects::ACS_CONTROLLER, acs::CtrlModes::SAFE, 0, ACS_TABLE_SAFE_TGT.second);
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_SAFE_TGT.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_SAFE_TGT.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_SAFE_TGT.second);
ss->addTable(&ACS_TABLE_SAFE_TGT.second, ACS_TABLE_OFF_TGT.first, false, true);
2022-04-22 17:00:23 +02:00
2022-04-25 10:08:29 +02:00
// Build SAFE transition 0
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_SAFE_TRANS_0.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_SAFE_TRANS_0.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_SAFE_TRANS_0.second);
iht(objects::STAR_TRACKER, OFF, 0, ACS_TABLE_SAFE_TRANS_0.second);
iht(objects::RW_ASS, OFF, 0, ACS_TABLE_SAFE_TRANS_0.second);
ss->addTable(&ACS_TABLE_SAFE_TRANS_0.second, ACS_TABLE_SAFE_TRANS_0.first, false, true);
// Build SAFE transition 1
iht(objects::ACS_CONTROLLER, acs::CtrlModes::SAFE, 0, ACS_TABLE_SAFE_TRANS_1.second);
ss->addTable(&ACS_TABLE_SAFE_TRANS_1.second, ACS_TABLE_SAFE_TRANS_1.first, false, true);
// Build SAFE sequence
ihs(ACS_SEQUENCE_SAFE.second, ACS_TABLE_SAFE_TGT.first, 0, false);
ihs(ACS_SEQUENCE_SAFE.second, ACS_TABLE_SAFE_TRANS_0.first, 0, false);
ihs(ACS_SEQUENCE_SAFE.second, ACS_TABLE_SAFE_TRANS_1.first, 0, false);
ss->addSequence(&ACS_SEQUENCE_SAFE.second, ACS_SEQUENCE_SAFE.first, ACS_SEQUENCE_OFF.first, false,
2022-04-25 08:48:22 +02:00
true);
2022-04-22 17:49:28 +02:00
}
void satsystem::buildDetumbleSequence(Subsystem* ss, ModeListEntry& eh) {
std::string context = "satsystem::buildDetumbleSequence";
auto ctxc = context.c_str();
2022-04-25 10:08:29 +02:00
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode,
2022-04-25 08:48:22 +02:00
ArrayList<ModeListEntry>& sequence) {
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
CHK(sequence.insert(eh), ctxc);
};
2022-04-25 10:08:29 +02:00
// Insert Helper Sequence
auto ihs = [&]( ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
CHK(sequence.insert(eh), ctxc);
};
2022-04-22 17:49:28 +02:00
// Build DETUMBLE target
2022-04-25 10:08:29 +02:00
iht(objects::ACS_CONTROLLER, acs::CtrlModes::DETUMBLE, 0, ACS_TABLE_DETUMBLE_TGT.second);
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_DETUMBLE_TGT.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_DETUMBLE_TGT.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_DETUMBLE_TGT.second);
2022-04-25 08:48:22 +02:00
ss->addTable(&ACS_TABLE_DETUMBLE_TGT.second, ACS_TABLE_DETUMBLE_TGT.first, false, true);
2022-04-22 17:49:28 +02:00
// Build DETUMBLE transition 0
2022-04-25 10:08:29 +02:00
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::STAR_TRACKER, OFF, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::RW_ASS, OFF, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
ss->addTable(&ACS_TABLE_DETUMBLE_TRANS_0.second, ACS_TABLE_DETUMBLE_TRANS_0.first, false, true);
2022-04-22 17:49:28 +02:00
// Build DETUMBLE transition 1
2022-04-25 10:08:29 +02:00
iht(objects::ACS_CONTROLLER, acs::CtrlModes::DETUMBLE, 0, ACS_TABLE_DETUMBLE_TRANS_1.second);
2022-04-25 08:48:22 +02:00
ss->addTable(&ACS_TABLE_DETUMBLE_TRANS_1.second, ACS_TABLE_DETUMBLE_TRANS_1.first, false, true);
2022-04-25 10:08:29 +02:00
// Build DETUMBLE sequence
ihs(ACS_SEQUENCE_DETUMBLE.second, ACS_TABLE_DETUMBLE_TGT.first, 0, false);
ihs(ACS_SEQUENCE_DETUMBLE.second, ACS_TABLE_DETUMBLE_TRANS_0.first, 0, false);
ihs(ACS_SEQUENCE_DETUMBLE.second, ACS_TABLE_DETUMBLE_TRANS_1.first, 0, false);
2022-04-25 08:48:22 +02:00
ss->addSequence(&ACS_SEQUENCE_DETUMBLE.second, ACS_SEQUENCE_DETUMBLE.first,
ACS_SEQUENCE_DETUMBLE.first, false, true);
2022-04-22 17:49:28 +02:00
}
2022-04-25 10:08:29 +02:00
void satsystem::buildIdleSequence(Subsystem* ss, ModeListEntry& eh) {
std::string context = "satsystem::buildIdleSequence";
auto ctxc = context.c_str();
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode,
ArrayList<ModeListEntry>& sequence) {
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
CHK(sequence.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&]( ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
CHK(sequence.insert(eh), ctxc);
};
// Build IDLE target
iht(objects::ACS_CONTROLLER, acs::CtrlModes::IDLE, 0, ACS_TABLE_IDLE_TGT.second);
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_IDLE_TGT.second);
iht(objects::RW_ASS, NML, 0, ACS_TABLE_IDLE_TGT.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_IDLE_TGT.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_IDLE_TGT.second);
ss->addTable(&ACS_TABLE_IDLE_TGT.second, ACS_TABLE_IDLE_TGT.first, false, true);
// Build IDLE transition 0
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::RW_ASS, NML, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
iht(objects::STAR_TRACKER, OFF, 0, ACS_TABLE_DETUMBLE_TRANS_0.second);
ss->addTable(&ACS_TABLE_IDLE_TRANS_0.second, ACS_TABLE_IDLE_TRANS_0.first, false, true);
// Build IDLE transition 1
iht(objects::ACS_CONTROLLER, acs::CtrlModes::IDLE, 0, ACS_TABLE_DETUMBLE_TRANS_1.second);
ss->addTable(&ACS_TABLE_IDLE_TRANS_1.second, ACS_TABLE_IDLE_TRANS_1.first, false, true);
// Build IDLE sequence
ihs(ACS_SEQUENCE_IDLE.second, ACS_TABLE_IDLE_TGT.first, 0, false);
ihs(ACS_SEQUENCE_IDLE.second, ACS_TABLE_IDLE_TRANS_0.first, 0, false);
ihs(ACS_SEQUENCE_IDLE.second, ACS_TABLE_IDLE_TRANS_1.first, 0, false);
ss->addSequence(&ACS_SEQUENCE_IDLE.second, ACS_SEQUENCE_IDLE.first,
ACS_SEQUENCE_IDLE.first, false, true);
}
void satsystem::buildTargetPtSequence(Subsystem* ss, ModeListEntry& eh) {
std::string context = "satsystem::buildTargetPtSequence";
auto ctxc = context.c_str();
// Insert Helper Table
auto iht = [&](object_id_t obj, Mode_t mode, Submode_t submode,
ArrayList<ModeListEntry>& sequence) {
eh.setObject(obj);
eh.setMode(mode);
eh.setSubmode(submode);
CHK(sequence.insert(eh), ctxc);
};
// Insert Helper Sequence
auto ihs = [&]( ArrayList<ModeListEntry>& sequence, Mode_t tableId, uint32_t waitSeconds,
bool checkSuccess) {
eh.setTableId(tableId);
eh.setWaitSeconds(waitSeconds);
eh.setCheckSuccess(checkSuccess);
CHK(sequence.insert(eh), ctxc);
};
// Build TARGET PT table
iht(objects::ACS_CONTROLLER, acs::CtrlModes::TARGET_PT, 0, ACS_TABLE_TARGET_PT_TGT.second);
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_TARGET_PT_TGT.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_TARGET_PT_TGT.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_TARGET_PT_TGT.second);
iht(objects::RW_ASS, NML, 0, ACS_TABLE_TARGET_PT_TGT.second);
iht(objects::STAR_TRACKER, NML, 0, ACS_TABLE_TARGET_PT_TGT.second);
ss->addTable(&ACS_TABLE_TARGET_PT_TGT.second, ACS_TABLE_TARGET_PT_TGT.first, false, true);
2022-04-22 17:49:28 +02:00
2022-04-25 10:08:29 +02:00
// Build TARGET PT transition 0
iht(objects::IMTQ_HANDLER, NML, 0, ACS_TABLE_TARGET_PT_TRANS_0.second);
iht(objects::SUS_BOARD_ASS, NML, 0, ACS_TABLE_TARGET_PT_TRANS_0.second);
iht(objects::ACS_BOARD_ASS, NML, 0, ACS_TABLE_TARGET_PT_TRANS_0.second);
iht(objects::RW_ASS, NML, 0, ACS_TABLE_TARGET_PT_TRANS_0.second);
iht(objects::STAR_TRACKER, NML, 0, ACS_TABLE_TARGET_PT_TRANS_0.second);
ss->addTable(&ACS_TABLE_TARGET_PT_TRANS_0.second, ACS_TABLE_TARGET_PT_TRANS_0.first, false, true);
// Build TARGET PT transition 1
iht(objects::ACS_CONTROLLER, acs::CtrlModes::TARGET_PT, 0, ACS_TABLE_TARGET_PT_TRANS_1.second);
ss->addTable(&ACS_TABLE_TARGET_PT_TRANS_1.second, ACS_TABLE_TARGET_PT_TRANS_1.first, false, true);
// Build IDLE sequence
ihs(ACS_SEQUENCE_TARGET_PT.second, ACS_TABLE_TARGET_PT_TGT.first, 0, false);
ihs(ACS_SEQUENCE_TARGET_PT.second, ACS_TABLE_TARGET_PT_TRANS_0.first, 0, false);
ihs(ACS_SEQUENCE_TARGET_PT.second, ACS_TABLE_TARGET_PT_TRANS_1.first, 0, false);
ss->addSequence(&ACS_SEQUENCE_TARGET_PT.second, ACS_SEQUENCE_TARGET_PT.first,
ACS_SEQUENCE_TARGET_PT.first, false, true);
}
2022-04-22 17:49:28 +02:00
void satsystem::checkInsert(ReturnValue_t result, const char* ctx) {
2022-04-25 08:48:22 +02:00
if (result != HasReturnvaluesIF::RETURN_OK) {
2022-04-22 17:49:28 +02:00
sif::error << "Insertion failed at " << ctx << std::endl;
}
2022-04-22 17:00:23 +02:00
}