diff --git a/libraries/protobuf-definitions b/libraries/protobuf-definitions index 41b8356d..20a75201 160000 --- a/libraries/protobuf-definitions +++ b/libraries/protobuf-definitions @@ -1 +1 @@ -Subproject commit 41b8356d5c8396c62ebb0ef1c64e9b06f1a2fffa +Subproject commit 20a7520179b61c458cacf7d57f31b401e82822e9 diff --git a/src/IO/ArduinoProxy.cpp b/src/IO/ArduinoProxy.cpp index 2f200371..b94e431c 100644 --- a/src/IO/ArduinoProxy.cpp +++ b/src/IO/ArduinoProxy.cpp @@ -126,6 +126,13 @@ void ArduinoProxy::handleArduinoMessage(const RocketryProto::ArduinoOut &arduino dcMotorState.maxlimitswitch(), std::chrono::steady_clock::now()}; } break; + case RocketryProto::ArduinoOut::kLoadCellState: { + std::lock_guard lockGuard(stateMutex); + + const auto &state = arduinoOut.loadcellstate(); + loadCellState = {state.value(), std::chrono::steady_clock::now()}; + } + break; case RocketryProto::ArduinoOut::DATA_NOT_SET: SPDLOG_LOGGER_WARN(logger, "Data field not set in Arduino message. "); break; @@ -211,4 +218,23 @@ DCMotorState ArduinoProxy::getDCMotorState(int forwardPin, int reversePin) } } +uint32_t ArduinoProxy::getLoadCellState() +{ + std::lock_guard lockGuard(stateMutex); + + auto state = loadCellState; + auto now = std::chrono::steady_clock::now(); + + if (now - state.second >= pinStateTimeout) + { + loadCellState = {-1, std::chrono::steady_clock::now()}; + SPDLOG_ERROR("Arduino stopped reporting load cell state"); + return -1; + } + else + { + return state.first; + } +} + #endif \ No newline at end of file diff --git a/src/IO/ArduinoProxy.h b/src/IO/ArduinoProxy.h index 7b300225..6e4ed87d 100644 --- a/src/IO/ArduinoProxy.h +++ b/src/IO/ArduinoProxy.h @@ -25,6 +25,7 @@ class ArduinoProxy : IO bool getDigitalState(int pin); int getServoState(int pin); DCMotorState getDCMotorState(int forwardPin, int reversePin); + uint32_t getLoadCellState(); ArduinoProxy(ArduinoProxy const &) = delete; void operator=(ArduinoProxy const &) = delete; @@ -33,6 +34,7 @@ class ArduinoProxy : IO std::map>> digitalStates; std::map>> servoStates; std::map, DCMotorState> dcMotorStates; + std::pair> loadCellState; std::mutex stateMutex; int fd = 0; diff --git a/src/IO/SensorLogger.cpp b/src/IO/SensorLogger.cpp index 121506e2..334b71b6 100644 --- a/src/IO/SensorLogger.cpp +++ b/src/IO/SensorLogger.cpp @@ -334,6 +334,9 @@ void SensorLogger::writeData(std::ofstream &fileStream, const StateData ¤t { fileStream << output.second << sep; } + + + fileStream << currentState.gpioState.loadCellState << sep; #endif #if USE_SBG == 1 diff --git a/src/IO/gpio/Gpio.cpp b/src/IO/gpio/Gpio.cpp index 6bab4796..11bed425 100644 --- a/src/IO/gpio/Gpio.cpp +++ b/src/IO/gpio/Gpio.cpp @@ -92,6 +92,8 @@ GpioState Gpio::getCurrentState() state.dcMotorStateMap.insert({i.first, i.second.getCurrentState()}); } + state.loadCellState = loadCell.getCurrentState(); + return state; } diff --git a/src/IO/gpio/Gpio.h b/src/IO/gpio/Gpio.h index fa972575..fdf3dc90 100644 --- a/src/IO/gpio/Gpio.h +++ b/src/IO/gpio/Gpio.h @@ -7,6 +7,7 @@ #include "IO/gpio/DCMotor.h" #include "IO/gpio/DigitalOutput.h" #include "IO/gpio/PwmOutput.h" +#include "IO/gpio/LoadCell.h" #include "data/GpioData.h" #include #include @@ -44,6 +45,7 @@ class Gpio : public IO std::map digitalOutputsMap; std::map pwmOutputsMap; std::map dcMotorOutputsMap; + LoadCell loadCell; struct InitFlags { diff --git a/src/IO/gpio/LoadCell.cpp b/src/IO/gpio/LoadCell.cpp new file mode 100644 index 00000000..a32bf5be --- /dev/null +++ b/src/IO/gpio/LoadCell.cpp @@ -0,0 +1,48 @@ +#include "config.h" + +#if USE_GPIO == 1 + +#include "LoadCell.h" +#include +#include +#include +#include + +LoadCell::LoadCell() +{ + createThread = false; + logger = spdlog::default_logger(); + + SPDLOG_LOGGER_DEBUG(logger, "Created LoadCell"); + +#if USE_ARDUINO_PROXY == 1 + arduinoProxy = ArduinoProxy::getInstance(); +#endif +} + +uint32_t LoadCell::getCurrentState() +{ +#if USE_ARDUINO_PROXY == 1 + try + { + return arduinoProxy->getLoadCellState(); + } + catch (std::out_of_range &error) + { + return -1; + } +#else + return -1; +#endif +} + +void LoadCell::run() +{ +} + +bool LoadCell::isInitialized() +{ + return true; +} + +#endif \ No newline at end of file diff --git a/src/IO/gpio/LoadCell.h b/src/IO/gpio/LoadCell.h new file mode 100644 index 00000000..88195b4a --- /dev/null +++ b/src/IO/gpio/LoadCell.h @@ -0,0 +1,35 @@ +#pragma once + +#include "config.h" + +#if USE_GPIO == 1 + +#include "IO/IO.h" +#include "Output.h" +#include "arduino/DCMotorState.h" + +#if USE_ARDUINO_PROXY +#include "IO/ArduinoProxy.h" +#endif + +#include +#include + +class LoadCell : public IO +{ + public: + LoadCell(); + + uint32_t getCurrentState(); + void run() override; + bool isInitialized() override; + + private: + std::shared_ptr logger; + +#if USE_ARDUINO_PROXY == 1 + ArduinoProxy *arduinoProxy; +#endif +}; + +#endif \ No newline at end of file diff --git a/src/data/GpioData.h b/src/data/GpioData.h index 1e11bec4..52b8a1f1 100644 --- a/src/data/GpioData.h +++ b/src/data/GpioData.h @@ -16,4 +16,5 @@ struct GpioState std::map digitalStateMap; std::map pwmStateMap; std::map dcMotorStateMap; + uint32_t loadCellState; }; diff --git a/src/data/StateData.cpp b/src/data/StateData.cpp index a6ebad6d..40fbd15f 100644 --- a/src/data/StateData.cpp +++ b/src/data/StateData.cpp @@ -126,6 +126,9 @@ std::string StateData::convertToReducedString() const data += std::to_string(output.second.maxLimitSwitch); data += ","; } + + data += std::to_string(gpioState.loadCellState); + data += ","; #endif #if USE_SENSOR_SUITE == 1 diff --git a/src/stateMachine/HotFire/HotFireGpioConfig.h b/src/stateMachine/HotFire/HotFireGpioConfig.h index ba5580d7..76b0dfec 100644 --- a/src/stateMachine/HotFire/HotFireGpioConfig.h +++ b/src/stateMachine/HotFire/HotFireGpioConfig.h @@ -16,13 +16,15 @@ #define USE_PWM_FILL 1 + #define USE_PURGE 1 + #define USE_HEATER 1 #define EVENT_ENABLE_MASK 0b1 #if USE_VENT #define VENT_NAME "VENT" - #define VENT_PIN 8 + #define VENT_PIN 13 #define VENT_OPEN 1 #define VENT_CLOSE 0 #define VENT_SAFE 1 @@ -32,8 +34,8 @@ #if USE_IGNITER #define IGNITER_NAME "IGNITER" #define IGNITER_PIN 12 - #define IGNITER_ON 1 - #define IGNITER_OFF 0 + #define IGNITER_ON 0 + #define IGNITER_OFF 1 #define IGNITER_EVENT_ENABLE_MASK 0b100 #endif @@ -46,7 +48,7 @@ #define MAIN_POTENTIOMETER_PIN 0 #define MAIN_MOTOR_POWER 255 #define MAIN_OPEN 0 - #define MAIN_IGNITION 400 + #define MAIN_IGNITION_BURN 400 #define MAIN_CLOSE 1023 #define MAIN_EVENT_ENABLE_MASK 0b1000 #endif @@ -71,6 +73,16 @@ #define FILL_SOFTPWM true #endif + #if USE_PURGE + #define PURGE_NAME "PURGE" + #define PURGE_PIN 3 + #define PURGE_OPEN 180 + #define PURGE_CLOSE 0 + #define PURGE_SAFE 0 + #define PURGE_EVENT_ENABLE_MASK 0b1000000 + #define PURGE_SOFTPWM true + #endif + #if USE_HEATER #define HEATER_NAME "HEATER" #define HEATER_PIN 7 diff --git a/src/stateMachine/HotFire/HotFireStateMachine.cpp b/src/stateMachine/HotFire/HotFireStateMachine.cpp index 4c54b412..d0520137 100644 --- a/src/stateMachine/HotFire/HotFireStateMachine.cpp +++ b/src/stateMachine/HotFire/HotFireStateMachine.cpp @@ -22,22 +22,23 @@ HotFireStateMachine::HotFireStateMachine(Interface *anInterface) : InterfacingSt } // StartFilling external event -void HotFireStateMachine::ReadyEXT() -{ - BEGIN_TRANSITION_MAP // - Current State - - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(ST_WAIT_FOR_FILLING) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_FILLING - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_ABORT_FILLING - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_ABORT_BURN - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_SERVO_CONTROL +void HotFireStateMachine::PurgeEXT() +{ + BEGIN_TRANSITION_MAP // - Current State - + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT + TRANSITION_MAP_ENTRY(ST_PURGE) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING + TRANSITION_MAP_ENTRY(ST_PURGE) // ST_DONE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_ABORT_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_ABORT_BURN + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_SERVO_CONTROL END_TRANSITION_MAP } @@ -47,11 +48,12 @@ void HotFireStateMachine::StartFillingEXT() BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(ST_FILLING) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(ST_FILLING) // ST_PURGE TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION + TRANSITION_MAP_ENTRY(ST_FILLING) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE @@ -67,11 +69,12 @@ void HotFireStateMachine::AbortEXT() BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(ST_ABORT_FILLING) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(ST_ABORT_FILLING) // ST_PURGE TRANSITION_MAP_ENTRY(ST_ABORT_FILLING) // ST_FILLING TRANSITION_MAP_ENTRY(ST_ABORT_FILLING) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(ST_ABORT_BURN) // ST_IGNITION + TRANSITION_MAP_ENTRY(ST_ABORT_BURN) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(ST_ABORT_BURN) // ST_FULL_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE @@ -87,11 +90,12 @@ void HotFireStateMachine::StopFillingEXT() BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_PURGE TRANSITION_MAP_ENTRY(ST_WAIT_FOR_IGNITION) // ST_FILLING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE @@ -107,11 +111,12 @@ void HotFireStateMachine::IgnitionEXT() BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_PURGE TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING TRANSITION_MAP_ENTRY(ST_IGNITION) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE @@ -121,17 +126,39 @@ void HotFireStateMachine::IgnitionEXT() END_TRANSITION_MAP } +// IgnitionBurn external event +void HotFireStateMachine::IgnitionBurnEXT() +{ + BEGIN_TRANSITION_MAP // - Current State - + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION + TRANSITION_MAP_ENTRY(ST_IGNITION_BURN) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_ABORT_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_ABORT_BURN + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_SERVO_CONTROL + END_TRANSITION_MAP +} + // FinalVenting external event void HotFireStateMachine::FinalVentingEXT() { BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_PURGE TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(ST_FINAL_VENTING) // ST_FULL_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE @@ -147,11 +174,12 @@ void HotFireStateMachine::DoneEXT() BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_INIT TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_PURGE TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FILLING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION + TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_FULL_BURN TRANSITION_MAP_ENTRY(ST_DONE) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(EVENT_IGNORED) // ST_DONE @@ -167,11 +195,12 @@ void HotFireStateMachine::ServoControlEXT() { BEGIN_TRANSITION_MAP // - Current State - TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_INIT TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_WAIT_FOR_INIT - TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_WAIT_FOR_READY - TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_WAIT_FOR_FILLING + TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_WAIT_FOR_PURGE + TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_PURGE TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_FILLING TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_WAIT_FOR_IGNITION TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_IGNITION + TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_IGNITION_BURN TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_FULL_BURN TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_FINAL_VENTING TRANSITION_MAP_ENTRY(ST_SERVO_CONTROL) // ST_DONE @@ -214,6 +243,10 @@ STATE_DEFINE(HotFireStateMachine, Init, UOSMData) interface->createNewGpioPwmOutput(FILL_NAME, FILL_PIN, FILL_SAFE, FILL_SOFTPWM); #endif +#if USE_PURGE + interface->createNewGpioPwmOutput(PURGE_NAME, PURGE_PIN, PURGE_SAFE, PURGE_SOFTPWM); +#endif + #endif NoEventData eventData; InternalEvent(ST_WAIT_FOR_INIT, eventData); @@ -236,7 +269,7 @@ STATE_DEFINE(HotFireStateMachine, WaitForInit, UOSMData) NoEventData eventData; if (interfaceData->isInitialized()) { - InternalEvent(ST_WAIT_FOR_READY, eventData); + InternalEvent(ST_WAIT_FOR_PURGE, eventData); } // showInfo(interfaceData); @@ -249,35 +282,64 @@ EXIT_DEFINE(HotFireStateMachine, ExitWaitForInit) SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitWaitForInit"); } -ENTRY_DEFINE(HotFireStateMachine, EnterWaitForReady, UOSMData) +ENTRY_DEFINE(HotFireStateMachine, EnterWaitForPurge, UOSMData) { - SPDLOG_LOGGER_INFO(logger, "HotFireSM::EnterWaitForReady"); - enterNewState(ST_WAIT_FOR_READY); + SPDLOG_LOGGER_INFO(logger, "HotFireSM::EnterWaitForPurge"); + enterNewState(ST_WAIT_FOR_PURGE); } -STATE_DEFINE(HotFireStateMachine, WaitForReady, UOSMData) +STATE_DEFINE(HotFireStateMachine, WaitForPurge, UOSMData) { - interfaceData = updateInterface(&data, ST_WAIT_FOR_READY); + interfaceData = updateInterface(&data, ST_WAIT_FOR_PURGE); + +#if USE_GPIO == 1 + GpioData &gpioData = interfaceData->gpioData; + +#if USE_VENT + gpioData.digitalOutputMap.insert({VENT_NAME, VENT_OPEN}); +#endif + +#if USE_IGNITER + gpioData.digitalOutputMap.insert({IGNITER_NAME, IGNITER_OFF}); +#endif + +#if USE_PWM_MAIN + gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_CLOSE}); +#endif + +#if USE_PWM_PINHOLE + gpioData.pwmOutputMap.insert({PINHOLE_NAME, PINHOLE_OPEN}); +#endif + +#if USE_PWM_FILL + gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); +#endif + +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_CLOSE}); +#endif + +#endif detectExternEvent(interfaceData); interface->updateOutputs(interfaceData); } -EXIT_DEFINE(HotFireStateMachine, ExitWaitForReady) +EXIT_DEFINE(HotFireStateMachine, ExitWaitForPurge) { - SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitWaitForReady"); + SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitWaitForPurge"); } -ENTRY_DEFINE(HotFireStateMachine, EnterWaitForFilling, UOSMData) +ENTRY_DEFINE(HotFireStateMachine, EnterPurge, UOSMData) { - SPDLOG_LOGGER_INFO(logger, "HotFireSM::EnterWaitForFilling"); - enterNewState(ST_WAIT_FOR_FILLING); + SPDLOG_LOGGER_INFO(logger, "HotFireSM::EnterWaitForPurge"); + enterNewState(ST_PURGE); } -STATE_DEFINE(HotFireStateMachine, WaitForFilling, UOSMData) +STATE_DEFINE(HotFireStateMachine, Purge, UOSMData) { - interfaceData = updateInterface(&data, ST_WAIT_FOR_FILLING); + interfaceData = updateInterface(&data, ST_PURGE); #if USE_GPIO == 1 GpioData &gpioData = interfaceData->gpioData; @@ -291,7 +353,7 @@ STATE_DEFINE(HotFireStateMachine, WaitForFilling, UOSMData) #endif #if USE_PWM_MAIN - gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_CLOSE}); + gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_OPEN}); #endif #if USE_PWM_PINHOLE @@ -302,6 +364,10 @@ STATE_DEFINE(HotFireStateMachine, WaitForFilling, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -309,9 +375,9 @@ STATE_DEFINE(HotFireStateMachine, WaitForFilling, UOSMData) interface->updateOutputs(interfaceData); } -EXIT_DEFINE(HotFireStateMachine, ExitWaitForFilling) +EXIT_DEFINE(HotFireStateMachine, ExitPurge) { - SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitWaitForFilling"); + SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitPurge"); } ENTRY_DEFINE(HotFireStateMachine, EnterFilling, UOSMData) @@ -347,6 +413,10 @@ STATE_DEFINE(HotFireStateMachine, Filling, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_OPEN}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -392,6 +462,10 @@ STATE_DEFINE(HotFireStateMachine, WaitForIgnition, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -426,7 +500,56 @@ STATE_DEFINE(HotFireStateMachine, Ignition, UOSMData) #endif #if USE_PWM_MAIN - gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_IGNITION}); + gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_CLOSE}); +#endif + +#if USE_PWM_PINHOLE + gpioData.pwmOutputMap.insert({PINHOLE_NAME, PINHOLE_CLOSE}); +#endif + +#if USE_PWM_FILL + gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); +#endif + +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + +#endif + EventData eventData; + detectExternEvent(interfaceData); + + interface->updateOutputs(interfaceData); +} + +EXIT_DEFINE(HotFireStateMachine, ExitIgnition) +{ + SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitIgnition"); +} + +ENTRY_DEFINE(HotFireStateMachine, EnterIgnitionBurn, UOSMData) +{ + SPDLOG_LOGGER_INFO(logger, "HotFireSM::EnterIgnition"); + enterNewState(ST_IGNITION_BURN); +} + +STATE_DEFINE(HotFireStateMachine, IgnitionBurn, UOSMData) +{ + interfaceData = updateInterface(&data, ST_IGNITION_BURN); + +#if USE_GPIO + GpioData &gpioData = interfaceData->gpioData; + +#if USE_VENT + gpioData.digitalOutputMap.insert({VENT_NAME, VENT_CLOSE}); +#endif + +#if USE_IGNITER + gpioData.digitalOutputMap.insert({IGNITER_NAME, IGNITER_OFF}); +#endif + +#if USE_PWM_MAIN + gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_IGNITION_BURN}); #endif #if USE_PWM_PINHOLE @@ -437,6 +560,10 @@ STATE_DEFINE(HotFireStateMachine, Ignition, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif EventData eventData; detectExternEvent(interfaceData); @@ -445,7 +572,7 @@ STATE_DEFINE(HotFireStateMachine, Ignition, UOSMData) interface->updateOutputs(interfaceData); } -EXIT_DEFINE(HotFireStateMachine, ExitIgnition) +EXIT_DEFINE(HotFireStateMachine, ExitIgnitionBurn) { SPDLOG_LOGGER_INFO(logger, "HotFireSM::ExitIgnition"); } @@ -483,6 +610,10 @@ STATE_DEFINE(HotFireStateMachine, FullBurn, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -509,7 +640,7 @@ STATE_DEFINE(HotFireStateMachine, FinalVenting, UOSMData) GpioData &gpioData = interfaceData->gpioData; #if USE_VENT - gpioData.digitalOutputMap.insert({VENT_NAME, VENT_OPEN}); + gpioData.digitalOutputMap.insert({VENT_NAME, VENT_CLOSE}); #endif #if USE_IGNITER @@ -517,17 +648,21 @@ STATE_DEFINE(HotFireStateMachine, FinalVenting, UOSMData) #endif #if USE_PWM_MAIN - gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_CLOSE}); + gpioData.dcOutputMap.insert({MAIN_NAME, MAIN_OPEN}); #endif #if USE_PWM_PINHOLE - gpioData.pwmOutputMap.insert({PINHOLE_NAME, PINHOLE_OPEN}); + gpioData.pwmOutputMap.insert({PINHOLE_NAME, PINHOLE_CLOSE}); #endif #if USE_PWM_FILL gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -555,7 +690,7 @@ STATE_DEFINE(HotFireStateMachine, Done, UOSMData) GpioData &gpioData = interfaceData->gpioData; #if USE_VENT - gpioData.digitalOutputMap.insert({VENT_NAME, VENT_CLOSE}); + gpioData.digitalOutputMap.insert({VENT_NAME, VENT_OPEN}); #endif #if USE_IGNITER @@ -574,6 +709,10 @@ STATE_DEFINE(HotFireStateMachine, Done, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_CLOSE}); +#endif + #endif detectExternEvent(interfaceData); @@ -614,6 +753,10 @@ STATE_DEFINE(HotFireStateMachine, AbortFilling, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -654,6 +797,10 @@ STATE_DEFINE(HotFireStateMachine, AbortBurn, UOSMData) gpioData.pwmOutputMap.insert({FILL_NAME, FILL_CLOSE}); #endif +#if USE_PURGE + gpioData.pwmOutputMap.insert({PURGE_NAME, PURGE_OPEN}); +#endif + #endif detectExternEvent(interfaceData); @@ -687,13 +834,14 @@ STATE_DEFINE(HotFireStateMachine, ServoControl, UOSMData) * whether the valves are open/closed. * A '1' means to open the valve and a '0' to close it. * - * 0 0 0 0 0 0 - * | | | | | ^--------- Enable bit - * | | | | ^----------- USE_VENT - * | | | ^------------- USE_IGNITER - * | | ^--------------- USE_PWM_MAIN - * | ^----------------- USE_PWM_PINHOLE - * ^------------------- USE_PWM_FILL + * 0 0 0 0 0 0 0 + * | | | | | | ^--------- Enable bit + * | | | | | ^----------- USE_VENT + * | | | | ^------------- USE_IGNITER + * | | | ^--------------- USE_PWM_MAIN + * | | ^----------------- USE_PWM_PINHOLE + * | ^------------------- USE_PWM_FILL + * ^--------------------- USE_PWM_PURGE */ bool enabled = eventNbr > 0 && (eventNbr & EVENT_ENABLE_MASK); @@ -748,6 +896,15 @@ STATE_DEFINE(HotFireStateMachine, ServoControl, UOSMData) logValveStatus(FILL_NAME, open); } +#endif +#if USE_PURGE == 1 + { + bool open = (eventNbr & PURGE_EVENT_ENABLE_MASK) > 0; + + gpioData.pwmOutputMap.insert({PURGE_NAME, open ? PURGE_OPEN : PURGE_CLOSE}); + + logValveStatus(PURGE_NAME, open); + } #endif } else @@ -820,7 +977,7 @@ void HotFireStateMachine::detectExternEvent(const std::shared_ptr &da ServoControlEXT(); break; case 7: - ReadyEXT(); + PurgeEXT(); break; case 8: heaterOn = true; @@ -831,6 +988,9 @@ void HotFireStateMachine::detectExternEvent(const std::shared_ptr &da case 10: interface->restartLogger(); break; + case 11: + IgnitionBurnEXT(); + break; default: break; } diff --git a/src/stateMachine/HotFire/HotFireStateMachine.h b/src/stateMachine/HotFire/HotFireStateMachine.h index c3aa96f7..8553b26f 100644 --- a/src/stateMachine/HotFire/HotFireStateMachine.h +++ b/src/stateMachine/HotFire/HotFireStateMachine.h @@ -10,11 +10,12 @@ class HotFireStateMachine : public InterfacingStateMachine HotFireStateMachine(Interface *anInterface); // External events taken by this state machine - void ReadyEXT(); + void PurgeEXT(); void StartFillingEXT(); void AbortEXT(); void StopFillingEXT(); void IgnitionEXT(); + void IgnitionBurnEXT(); void FinalVentingEXT(); void DoneEXT(); void ServoControlEXT(); @@ -36,11 +37,12 @@ class HotFireStateMachine : public InterfacingStateMachine { ST_INIT, ST_WAIT_FOR_INIT, - ST_WAIT_FOR_READY, - ST_WAIT_FOR_FILLING, + ST_WAIT_FOR_PURGE, + ST_PURGE, ST_FILLING, ST_WAIT_FOR_IGNITION, ST_IGNITION, + ST_IGNITION_BURN, ST_FULL_BURN, ST_FINAL_VENTING, ST_DONE, @@ -59,13 +61,13 @@ class HotFireStateMachine : public InterfacingStateMachine STATE_DECLARE(HotFireStateMachine, WaitForInit, UOSMData) EXIT_DECLARE(HotFireStateMachine, ExitWaitForInit) // WaitForReady - ENTRY_DECLARE(HotFireStateMachine, EnterWaitForReady, UOSMData) - STATE_DECLARE(HotFireStateMachine, WaitForReady, UOSMData) - EXIT_DECLARE(HotFireStateMachine, ExitWaitForReady) + ENTRY_DECLARE(HotFireStateMachine, EnterWaitForPurge, UOSMData) + STATE_DECLARE(HotFireStateMachine, WaitForPurge, UOSMData) + EXIT_DECLARE(HotFireStateMachine, ExitWaitForPurge) // WaitForFilling - ENTRY_DECLARE(HotFireStateMachine, EnterWaitForFilling, UOSMData) - STATE_DECLARE(HotFireStateMachine, WaitForFilling, UOSMData) - EXIT_DECLARE(HotFireStateMachine, ExitWaitForFilling) + ENTRY_DECLARE(HotFireStateMachine, EnterPurge, UOSMData) + STATE_DECLARE(HotFireStateMachine, Purge, UOSMData) + EXIT_DECLARE(HotFireStateMachine, ExitPurge) // Filling ENTRY_DECLARE(HotFireStateMachine, EnterFilling, UOSMData) STATE_DECLARE(HotFireStateMachine, Filling, UOSMData) @@ -78,6 +80,10 @@ class HotFireStateMachine : public InterfacingStateMachine ENTRY_DECLARE(HotFireStateMachine, EnterIgnition, UOSMData) STATE_DECLARE(HotFireStateMachine, Ignition, UOSMData) EXIT_DECLARE(HotFireStateMachine, ExitIgnition) + // IgnitionBurn + ENTRY_DECLARE(HotFireStateMachine, EnterIgnitionBurn, UOSMData) + STATE_DECLARE(HotFireStateMachine, IgnitionBurn, UOSMData) + EXIT_DECLARE(HotFireStateMachine, ExitIgnitionBurn) // FullBurn ENTRY_DECLARE(HotFireStateMachine, EnterFullBurn, UOSMData) STATE_DECLARE(HotFireStateMachine, FullBurn, UOSMData) @@ -102,11 +108,12 @@ class HotFireStateMachine : public InterfacingStateMachine BEGIN_STATE_MAP_EX STATE_MAP_ENTRY_ALL_EX(&Init, nullptr, nullptr, &ExitInit) STATE_MAP_ENTRY_ALL_EX(&WaitForInit, nullptr, &EnterWaitForInit, &ExitWaitForInit) - STATE_MAP_ENTRY_ALL_EX(&WaitForReady, nullptr, &EnterWaitForReady, &ExitWaitForReady) - STATE_MAP_ENTRY_ALL_EX(&WaitForFilling, nullptr, &EnterWaitForFilling, &ExitWaitForFilling) + STATE_MAP_ENTRY_ALL_EX(&WaitForPurge, nullptr, &EnterWaitForPurge, &ExitWaitForPurge) + STATE_MAP_ENTRY_ALL_EX(&Purge, nullptr, &EnterPurge, &ExitPurge) STATE_MAP_ENTRY_ALL_EX(&Filling, nullptr, &EnterFilling, &ExitFilling) STATE_MAP_ENTRY_ALL_EX(&WaitForIgnition, nullptr, &EnterWaitForIgnition, &ExitWaitForIgnition) STATE_MAP_ENTRY_ALL_EX(&Ignition, nullptr, &EnterIgnition, &ExitIgnition) + STATE_MAP_ENTRY_ALL_EX(&IgnitionBurn, nullptr, &EnterIgnitionBurn, &ExitIgnitionBurn) STATE_MAP_ENTRY_ALL_EX(&FullBurn, nullptr, &EnterFullBurn, &ExitFullBurn) STATE_MAP_ENTRY_ALL_EX(&FinalVenting, nullptr, &EnterFinalVenting, &ExitFinalVenting) STATE_MAP_ENTRY_ALL_EX(&Done, nullptr, &EnterDone, nullptr)