implemented core switch on state machine
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2022-02-10 18:02:49 +01:00
parent 656eaf4dea
commit ce566b0fa8
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 150 additions and 44 deletions

View File

@ -87,10 +87,10 @@ static constexpr char PDEC_RESET[] = "pdec_reset";
static constexpr char PL_PCDU_ENABLE_VBAT0[] = "enable_plpcdu_vbat0";
static constexpr char PL_PCDU_ENABLE_VBAT1[] = "enable_plpcdu_vbat1";
static constexpr char PL_PCDU_ENABLE_DRO[] = "enable_plpcdu_dro";
static constexpr char PL_PCDU_ENABLE_HPA[] = "enable_plpcdu_hpa";
static constexpr char PL_PCDU_ENABLE_MPA[] = "enable_plpcdu_mpa";
static constexpr char PL_PCDU_ENABLE_X8[] = "enable_plpcdu_x8";
static constexpr char PL_PCDU_ENABLE_TX[] = "enable_plpcdu_tx";
static constexpr char PL_PCDU_ENABLE_HPA[] = "enable_plpcdu_hpa";
static constexpr char PL_PCDU_ENABLE_MPA[] = "enable_plpcdu_mpa";
static constexpr char PL_PCDU_ADC_CS[] = "plpcdu_adc_chip_select";
} // namespace gpioNames

View File

@ -4,50 +4,120 @@
PayloadPcduHandler::PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie,
GpioIF* gpioIF)
: DeviceHandlerBase(objectId, comIF, cookie), state(States::ADC_OFF_PL_OFF), gpioIF(gpioIF) {}
: DeviceHandlerBase(objectId, comIF, cookie), gpioIF(gpioIF) {}
void PayloadPcduHandler::doStartUp() {
switch (state) {
case (States::ADC_OFF_PL_OFF): {
if((state != States::PCDU_OFF) and (state != States::ON_TRANS_SSR)) {
// Config error
sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl;
}
if (state == States::PCDU_OFF) {
// Switch on relays here
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT0);
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_VBAT1);
state = States::SWITCH_ON_RELAY_TRANSITION;
break;
state = States::ON_TRANS_SSR;
transitionOk = true;
}
case (States::SWITCH_ON_RELAY_TRANSITION): {
if (state == States::ON_TRANS_SSR) {
// If necessary, check whether a certain amount of time has elapsed
state = States::ADC_OFF_PL_OFF;
break;
if(transitionOk) {
transitionOk = false;
// We are now in ON mode
setMode(MODE_ON);
// The ADC can now be read. If the values are not close to zero, we should not allow
// transition
monMode = MonitoringMode::CLOSE_TO_ZERO;
}
default:
// Config error
sif::error << "PayloadPcduHandler::doStartUp: Invalid state" << std::endl;
}
}
void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
if (mode == _MODE_TO_NORMAL) {
switch (state) {
case (States::ADC_OFF_PL_OFF): {
// Switch on HPA here
if (state == States::ON_TRANS_ADC_CLOSE_ZERO) {
if(not commandExecuted) {
countdown.resetTimer();
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if(transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_DRO;
// Now start monitoring for negative voltages instead
monMode = MonitoringMode::NEGATIVE;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_DRO) {
if(not commandExecuted) {
// Switch on DRO and start monitoring for negative voltagea
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO);
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA);
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if(transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_X8;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_X8) {
if(not commandExecuted) {
// Switch on X8
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if(transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_TX;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if(state == States::ON_TRANS_TX) {
if(not commandExecuted) {
// Switch on TX
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if(transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_MPA;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if(state == States::ON_TRANS_MPA) {
if(not commandExecuted) {
// Switch on MPA
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if(transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_HPA;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
if(state == States::ON_TRANS_HPA) {
if(not commandExecuted) {
// Switch on HPA
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA);
state = States::SWITCH_ON_HPA_TRANSITION;
break;
commandExecuted = true;
}
case (States::SWITCH_ON_HPA_TRANSITION): {
// If necessary, check whether a certain amount of time has elapsed
state = States::ADC_ON_PL_ON;
// ADC values are ok, 5 seconds have elapsed
if(transitionOk and countdown.hasTimedOut()) {
state = States::PCDU_ON;
setMode(MODE_NORMAL);
break;
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
default:
// Config error
sif::error << "PayloadPcduHandler::doTransition: Invalid state" << std::endl;
}
}
}

View File

@ -2,25 +2,61 @@
#define LINUX_DEVICES_PLPCDUHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <fsfw/timemanager/Countdown.h>
#include "fsfw_hal/common/gpio/GpioIF.h"
/**
* @brief Device handler for the EIVE Payload PCDU
* @details
* Documentation:
* https://egit.irs.uni-stuttgart.de/eive/eive_dokumente/src/branch/master/400_Raumsegment/412_PayloaPCDUDocumentation/release/EIVE-D-421-001_PLPCDU_Documentation.pdf
*
* Important components:
* - SSR - Solid State Relay: Decouples voltages from battery
* - DRO - Dielectric Resonsant Oscillator: Generates modulation signal
* - X8: Frequency X8 Multiplicator
* - TX: Transmitter/Sender module. Modulates data onto carrier signal
* - MPA - Medium Power Amplifier
* - HPA - High Power Amplifier
*/
class PayloadPcduHandler : DeviceHandlerBase {
public:
PayloadPcduHandler(object_id_t objectId, object_id_t comIF, CookieIF* cookie, GpioIF* gpioIF);
private:
enum class States {
ADC_OFF_PL_OFF,
SWITCH_ON_RELAY_TRANSITION,
// In this mode, the handler can start polling the ADC. This is the ON mode
ADC_ON_PL_OFF,
SWITCH_ON_HPA_TRANSITION,
// Now the ADC is actually spitting out sensible values. This is the normal mode with the
// experiment being on.
ADC_ON_PL_ON
};
States state;
PCDU_OFF,
// Solid State Relay, enable battery voltages VBAT0 and VBAT1. This will also switch on
// the ADC
ON_TRANS_SSR,
ON_TRANS_ADC_CLOSE_ZERO,
// Enable Dielectric Resonant Oscillator and start monitoring voltages as
// soon as DRO voltage reaches 6V
ON_TRANS_DRO,
// Switch on X8 compoennt and monitor voltages for 5 seconds
ON_TRANS_X8,
// Switch on TX component and monitor voltages for 5 seconds
ON_TRANS_TX,
// Switch on MPA component and monitor voltages for 5 seconds
ON_TRANS_MPA,
// Switch on HPA component and monitor voltages for 5 seconds
ON_TRANS_HPA,
// All components of the experiment are on
PCDU_ON,
} state = States::PCDU_OFF;
enum class MonitoringMode {
NONE,
CLOSE_TO_ZERO,
NEGATIVE
} monMode = MonitoringMode::NONE;
// This variable is tied to DRO +6 V voltage. Voltages, currents are monitored and the experiment
// is shut down immediately if there is a negative voltage.
bool transitionOk = false;
bool commandExecuted = false;
Countdown countdown = Countdown(5000);
GpioIF* gpioIF;
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;

View File

@ -115,10 +115,10 @@ enum gpioId_t {
PLPCDU_ENB_VBAT0,
PLPCDU_ENB_VBAT1,
PLPCDU_ENB_DRO,
PLPCDU_ENB_HPA,
PLPCDU_ENB_MPA,
PLPCDU_ENB_X8,
PLPCDU_ENB_TX,
PLPCDU_ENB_HPA,
PLPCDU_ENB_MPA,
PLPCDU_ADC_CS
};
}