adc check handling done
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
2022-02-25 19:07:47 +01:00
parent a5e2208e01
commit 49e58b2365
9 changed files with 638 additions and 489 deletions

View File

@ -39,6 +39,8 @@ void PayloadPcduHandler::doStartUp() {
transitionOk = false;
// We are now in ON mode
startTransition(MODE_NORMAL, 0);
adcCountdown.setTimeout(50);
adcCountdown.resetTimer();
adcState = AdcStates::BOOT_DELAY;
// The ADC can now be read. If the values are not close to zero, we should not allow
// transition
@ -47,6 +49,139 @@ void PayloadPcduHandler::doStartUp() {
}
}
void PayloadPcduHandler::stateMachineToNormal() {
using namespace plpcdu;
if (adcState == AdcStates::BOOT_DELAY) {
if (adcCountdown.hasTimedOut()) {
adcState = AdcStates::SEND_SETUP;
adcCmdExecuted = false;
}
}
if (adcState == AdcStates::SEND_SETUP) {
if (adcCmdExecuted) {
adcState = AdcStates::NORMAL;
setMode(MODE_NORMAL, NORMAL_ADC_ONLY);
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
adcCmdExecuted = false;
}
}
if (submode == plpcdu::NORMAL_ALL_ON) {
if (state == States::ON_TRANS_ADC_CLOSE_ZERO) {
if (not commandExecuted) {
float waitTime = SSR_TO_DRO_WAIT_TIME;
params.getValue(PlPcduParameter::SSR_TO_DRO_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
commandExecuted = true;
// TODO: For now, skip ADC check
transitionOk = 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;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_DRO) {
if (not commandExecuted) {
float waitTime = DRO_TO_X8_WAIT_TIME;
params.getValue(PlPcduParameter::DRO_TO_X8_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// Switch on DRO and start monitoring for negative voltages
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO);
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_X8;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_X8) {
if (not commandExecuted) {
float waitTime = X8_TO_TX_WAIT_TIME;
params.getValue(PlPcduParameter::X8_TO_TX_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// Switch on X8
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_X8);
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_TX;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_TX) {
if (not commandExecuted) {
float waitTime = TX_TO_MPA_WAIT_TIME;
params.getValue(PlPcduParameter::TX_TO_MPA_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// Switch on TX
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_TX);
// Wait for 100 ms before checking ADC values
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_MPA;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_MPA) {
if (not commandExecuted) {
float waitTime = MPA_TO_HPA_WAIT_TIME;
params.getValue(PlPcduParameter::MPA_TO_HPA_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// Switch on MPA
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_MPA);
// Wait for 100 ms before checking ADC values
adcCountdown.setTimeout(100);
adcCountdown.resetTimer();
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_HPA;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_HPA) {
if (not commandExecuted) {
// Switch on HPA
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::PCDU_ON;
setMode(MODE_NORMAL, plpcdu::NORMAL_ALL_ON);
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
}
}
void PayloadPcduHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
if (mode == _MODE_TO_NORMAL) {
stateMachineToNormal();
@ -269,152 +404,126 @@ void PayloadPcduHandler::checkAdcValues() {
adcSet.processed[U_X8_DIV_6] = static_cast<float>(adcSet.channels[9]) * SCALE_VOLTAGE;
adcSet.processed[I_DRO] = static_cast<float>(adcSet.channels[10]) * SCALE_CURRENT_DRO * 1000.0;
adcSet.processed[U_DRO_DIV_6] = static_cast<float>(adcSet.channels[11]) * SCALE_VOLTAGE;
if(state >= States::ON_TRANS_DRO) {
if(adcSet.processed[U_BAT_DIV_6] < -6.0 or adcSet.processed[U_BAT_DIV_6] > -3.3) {
bool tooLarge = false;
if(adcSet.processed[U_BAT_DIV_6] > -3.3) {
tooLarge = true;
}
uint32_t rawVoltage = 0;
size_t serSize = 0;
SerializeAdapter::serialize(&adcSet.processed[U_BAT_DIV_6],
reinterpret_cast<uint8_t*>(&rawVoltage), &serSize, 4, SerializeIF::Endianness::NETWORK);
triggerEvent(NEG_V_OUT_OF_BOUNDS, tooLarge, rawVoltage);
transitionBackToOff();
float lowerBound = 0.0;
float upperBound = 0.0;
bool adcTransition = false;
adcTransition = state == States::ON_TRANS_DRO and adcCountdown.isBusy();
// Now check against voltage and current limits, depending on state
if (state >= States::ON_TRANS_DRO and not adcTransition) {
params.getValue(PlPcduParameter::NEG_V_LOWER_BOUND_K, lowerBound);
params.getValue(PlPcduParameter::NEG_V_UPPER_BOUND_K, upperBound);
if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound,
NEG_V_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PlPcduParameter::DRO_U_LOWER_BOUND_K, lowerBound);
params.getValue(PlPcduParameter::DRO_U_UPPER_BOUND_K, upperBound);
if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound,
U_DRO_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PlPcduParameter::DRO_I_UPPER_BOUND_K, upperBound);
if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) {
return;
}
}
adcTransition = state == States::ON_TRANS_X8 and adcCountdown.isBusy();
if (state >= States::ON_TRANS_X8 and not adcTransition) {
params.getValue(PlPcduParameter::X8_U_LOWER_BOUND_K, lowerBound);
params.getValue(PlPcduParameter::X8_U_UPPER_BOUND_K, upperBound);
if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound,
U_X8_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PlPcduParameter::X8_I_UPPER_BOUND_K, upperBound);
if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) {
return;
}
}
adcTransition = state == States::ON_TRANS_TX and adcCountdown.isBusy();
if (state >= States::ON_TRANS_TX and not adcTransition) {
params.getValue(PlPcduParameter::TX_U_LOWER_BOUND_K, lowerBound);
params.getValue(PlPcduParameter::TX_U_UPPER_BOUND_K, upperBound);
if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound,
U_TX_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PlPcduParameter::TX_I_UPPER_BOUND_K, upperBound);
if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) {
return;
}
}
adcTransition = state == States::ON_TRANS_MPA and adcCountdown.isBusy();
if (state >= States::ON_TRANS_MPA and not adcTransition) {
params.getValue(PlPcduParameter::MPA_U_LOWER_BOUND_K, lowerBound);
params.getValue(PlPcduParameter::MPA_U_UPPER_BOUND_K, upperBound);
if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound,
U_MPA_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PlPcduParameter::MPA_I_UPPER_BOUND_K, upperBound);
if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) {
return;
}
}
adcTransition = state == States::ON_TRANS_HPA and adcCountdown.isBusy();
if (state >= States::ON_TRANS_HPA and not adcTransition) {
params.getValue(PlPcduParameter::HPA_U_LOWER_BOUND_K, lowerBound);
params.getValue(PlPcduParameter::HPA_U_UPPER_BOUND_K, upperBound);
if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound,
U_HPA_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PlPcduParameter::HPA_I_UPPER_BOUND_K, upperBound);
if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) {
return;
}
}
}
void PayloadPcduHandler::checkJsonFileInit() {
if(not jsonFileInitComplete) {
if (not jsonFileInitComplete) {
sd::SdCard prefSd;
sdcMan->getPreferredSdCard(prefSd);
if(sdcMan->isSdCardMounted(prefSd)) {
if (sdcMan->isSdCardMounted(prefSd)) {
params.initialize(sdcMan->getCurrentMountPrefix(prefSd));
jsonFileInitComplete = true;
}
}
}
void PayloadPcduHandler::stateMachineToNormal() {
using namespace plpcdu;
if (adcState == AdcStates::BOOT_DELAY) {
if (adcCountdown.hasTimedOut()) {
adcState = AdcStates::SEND_SETUP;
adcCmdExecuted = false;
bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBound, Event event) {
bool tooLarge = false;
if (val < lowerBound or val > upperBound) {
if (val > upperBound) {
tooLarge = true;
} else {
tooLarge = false;
}
uint32_t p2 = 0;
serializeFloat(p2, val);
triggerEvent(event, tooLarge, p2);
transitionBackToOff();
return false;
}
if (adcState == AdcStates::SEND_SETUP) {
if (adcCmdExecuted) {
adcState = AdcStates::NORMAL;
setMode(MODE_NORMAL, NORMAL_ADC_ONLY);
adcCmdExecuted = false;
}
}
if (submode == plpcdu::NORMAL_ALL_ON) {
if (state == States::ON_TRANS_ADC_CLOSE_ZERO) {
if (not commandExecuted) {
float waitTime = SSR_TO_DRO_WAIT_TIME;
params.getValue(PlPcduParameter::SSR_TO_DRO_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
commandExecuted = true;
// TODO: For now, skip ADC check
transitionOk = 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;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_DRO) {
if (not commandExecuted) {
float waitTime = DRO_TO_X8_WAIT_TIME;
params.getValue(PlPcduParameter::DRO_TO_X8_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// Switch on DRO and start monitoring for negative voltages
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_DRO);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::ON_TRANS_X8;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_X8) {
if (not commandExecuted) {
float waitTime = X8_TO_TX_WAIT_TIME;
params.getValue(PlPcduParameter::X8_TO_TX_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// 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;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_TX) {
if (not commandExecuted) {
float waitTime = TX_TO_MPA_WAIT_TIME;
params.getValue(PlPcduParameter::TX_TO_MPA_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// 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;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_MPA) {
if (not commandExecuted) {
float waitTime = MPA_TO_HPA_WAIT_TIME;
params.getValue(PlPcduParameter::MPA_TO_HPA_WAIT_TIME_K, waitTime);
countdown.setTimeout(std::round(waitTime * 1000));
countdown.resetTimer();
// 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;
commandExecuted = false;
transitionOk = false;
}
}
if (state == States::ON_TRANS_HPA) {
if (not commandExecuted) {
// Switch on HPA
gpioIF->pullHigh(gpioIds::PLPCDU_ENB_HPA);
commandExecuted = true;
}
// ADC values are ok, 5 seconds have elapsed
if (transitionOk and countdown.hasTimedOut()) {
state = States::PCDU_ON;
setMode(MODE_NORMAL, plpcdu::NORMAL_ALL_ON);
countdown.resetTimer();
commandExecuted = false;
transitionOk = false;
}
}
return true;
}
bool PayloadPcduHandler::checkCurrent(float val, float upperBound, Event event) {
if (val > upperBound) {
uint32_t p2 = 0;
serializeFloat(p2, val);
triggerEvent(event, true, p2);
transitionBackToOff();
return false;
}
return true;
}
ReturnValue_t PayloadPcduHandler::serializeFloat(uint32_t& param, float val) {
size_t dummy = 0;
return SerializeAdapter::serialize(&val, reinterpret_cast<uint8_t*>(&param), &dummy, 4,
SerializeIF::Endianness::NETWORK);
}
#ifdef FSFW_OSAL_LINUX
@ -546,4 +655,5 @@ ReturnValue_t PayloadPcduHandler::transferAsTwo(SpiComIF* comIf, SpiCookie* cook
}
return HasReturnvaluesIF::RETURN_OK;
}
#endif