|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Pressure-based State Machine for Propulsion System. More...
#include <PressureStateMachine.hpp>
Classes | |
| struct | PressureReadings |
| Pressure sensor readings. More... | |
| struct | PressureThresholds |
| Configuration for pressure thresholds. More... | |
Public Types | |
| enum class | SystemState { DEBUG_STATE , IDLE , ARMED , FUEL_FILL , OX_FILL , GN2_LOW_PRESS , GN2_VENT , FUEL_PRESS , FUEL_VENT , OX_PRESS , OX_VENT , GN2_HIGH_PRESS , GN2_HIGH_VENT , VENT , CALIBRATE , READY , FIRE , ABORT } |
| System states matching the state machine diagram. More... | |
| enum class | ActuatorID { LOX_MAIN = 0 , FUEL_MAIN = 1 , LOX_VENT = 2 , FUEL_VENT = 3 , LOX_PRESS = 4 , FUEL_PRESS = 5 , PRESSURE_VENT = 6 } |
| Actuator identifiers matching config. More... | |
| enum class | CommandType : uint8_t { OPEN = 1 , CLOSE = 2 , PULSE = 3 , SET_POSITION = 4 } |
| Command types for actuators. More... | |
Public Member Functions | |
| PressureStateMachine () | |
| ~PressureStateMachine () | |
| bool | initialize (std::shared_ptr< elodin::ElodinClient > elodin_client, std::shared_ptr< config::BoardDiscovery > board_discovery, const PressureThresholds &thresholds) |
| Initialize the state machine. | |
| void | start () |
| Start the state machine. | |
| void | stop () |
| Stop the state machine. | |
| SystemState | getCurrentState () const |
| Get current state. | |
| std::string | getCurrentStateName () const |
| Get current state name as string. | |
| bool | requestTransition (SystemState target_state) |
| Request transition to a specific state (manual override). | |
| void | requestAbort () |
| Request abort. | |
| PressureReadings | getLatestPressures () const |
| Get latest pressure readings. | |
Private Member Functions | |
| void | stateMachineLoop () |
| Main state machine loop. | |
| void | readPressureData () |
| Read pressure data from Elodin. | |
| void | checkTransitions () |
| Check transition conditions based on current state and pressures. | |
| void | executeStateEntryActions (SystemState state) |
| Execute state entry actions. | |
| void | executeStateActions (SystemState state) |
| Execute state actions (while in state). | |
| void | sendActuatorCommand (ActuatorID actuator, CommandType command, float value=0.0f) |
| Send actuator command. | |
| uint16_t | actuatorToMessageID (ActuatorID actuator) const |
| Convert actuator ID to message ID from config. | |
| void | sendActuatorCommandUDP (ActuatorID actuator, CommandType command, float value=0.0f) |
| Send actuator command via UDP to board. | |
| void | registerPSMVTables () |
| Register Elodin VTables for PSM actuator commands and state transitions. | |
| std::pair< std::string, uint16_t > | getActuatorBoardAddress (ActuatorID actuator) const |
| Get board IP and port for actuator. | |
Private Attributes | |
| std::atomic< bool > | running_ |
| std::atomic< SystemState > | current_state_ |
| std::atomic< bool > | abort_requested_ |
| std::chrono::steady_clock::time_point | state_entry_time_ |
| std::shared_ptr< elodin::ElodinClient > | elodin_client_ |
| std::shared_ptr< config::BoardDiscovery > | board_discovery_ |
| std::unique_ptr< daq_comms::transport::UDPSocket > | command_socket_ |
| std::string | actuator_board_ip_ |
| uint16_t | actuator_board_port_ |
| std::mutex | pressure_mutex_ |
| PressureReadings | latest_pressures_ |
| PressureThresholds | thresholds_ |
| uint16_t | pt_hp_message_id_ = 0x2016 |
| uint16_t | pt_lp_message_id_ = 0x2011 |
| uint16_t | pt_fup_message_id_ = 0x2011 |
| uint16_t | pt_fdp_message_id_ = 0x2013 |
| uint16_t | pt_oup_message_id_ = 0x2015 |
| uint16_t | pt_odp_message_id_ = 0x2017 |
| std::map< ActuatorID, uint16_t > | actuator_message_ids_ |
| std::thread | state_machine_thread_ |
| std::mutex | state_mutex_ |
| std::chrono::milliseconds | state_machine_period_ {100} |
| std::chrono::milliseconds | pressure_read_period_ {50} |
Pressure-based State Machine for Propulsion System.
Reads pressure data from Elodin and sends actuator commands based on state transitions. Implements the propulsion system state machine with pressure-based transitions.
Definition at line 26 of file PressureStateMachine.hpp.
|
strong |
Actuator identifiers matching config.
| Enumerator | |
|---|---|
| LOX_MAIN | |
| FUEL_MAIN | |
| LOX_VENT | |
| FUEL_VENT | |
| LOX_PRESS | |
| FUEL_PRESS | |
| PRESSURE_VENT | |
Definition at line 55 of file PressureStateMachine.hpp.
|
strong |
Command types for actuators.
| Enumerator | |
|---|---|
| OPEN | |
| CLOSE | |
| PULSE | |
| SET_POSITION | |
Definition at line 68 of file PressureStateMachine.hpp.
|
strong |
System states matching the state machine diagram.
| Enumerator | |
|---|---|
| DEBUG_STATE | |
| IDLE | |
| ARMED | |
| FUEL_FILL | |
| OX_FILL | |
| GN2_LOW_PRESS | |
| GN2_VENT | |
| FUEL_PRESS | |
| FUEL_VENT | |
| OX_PRESS | |
| OX_VENT | |
| GN2_HIGH_PRESS | |
| GN2_HIGH_VENT | |
| VENT | |
| CALIBRATE | |
| READY | |
| FIRE | |
| ABORT | |
Definition at line 31 of file PressureStateMachine.hpp.
| fsw::control::PressureStateMachine::PressureStateMachine | ( | ) |
Definition at line 23 of file PressureStateMachine.cpp.
References abort_requested_, actuator_message_ids_, current_state_, FUEL_MAIN, FUEL_PRESS, FUEL_VENT, IDLE, LOX_MAIN, LOX_PRESS, LOX_VENT, PRESSURE_VENT, running_, and state_entry_time_.
| fsw::control::PressureStateMachine::~PressureStateMachine | ( | ) |
Definition at line 38 of file PressureStateMachine.cpp.
References stop().
|
private |
Convert actuator ID to message ID from config.
Definition at line 721 of file PressureStateMachine.cpp.
References actuator_message_ids_.
Referenced by sendActuatorCommand().
|
private |
Check transition conditions based on current state and pressures.
Definition at line 307 of file PressureStateMachine.cpp.
References ABORT, abort_requested_, CALIBRATE, current_state_, executeStateEntryActions(), FUEL_PRESS, fsw::control::PressureStateMachine::PressureReadings::fuel_pressure_psi, FUEL_VENT, GN2_HIGH_PRESS, GN2_HIGH_VENT, GN2_LOW_PRESS, fsw::control::PressureStateMachine::PressureReadings::gn2_pressure_psi, GN2_VENT, latest_pressures_, lock, OX_PRESS, fsw::control::PressureStateMachine::PressureReadings::ox_pressure_psi, OX_VENT, pressure_mutex_, state_entry_time_, state_mutex_, thresholds_, fsw::control::PressureStateMachine::PressureReadings::valid, and VENT.
Referenced by stateMachineLoop().
|
private |
Execute state actions (while in state).
Definition at line 607 of file PressureStateMachine.cpp.
References state.
Referenced by stateMachineLoop().
|
private |
Execute state entry actions.
Definition at line 457 of file PressureStateMachine.cpp.
References ABORT, abort_requested_, ARMED, CLOSE, current_state_, elodin_client_, comms::CommsMessage< Fields >::fields, FIRE, FUEL_FILL, FUEL_MAIN, FUEL_PRESS, FUEL_VENT, getCurrentStateName(), GN2_HIGH_PRESS, GN2_HIGH_VENT, GN2_LOW_PRESS, GN2_VENT, LOX_MAIN, LOX_PRESS, LOX_VENT, OPEN, OX_FILL, OX_PRESS, OX_VENT, PRESSURE_VENT, READY, sendActuatorCommand(), state, and VENT.
Referenced by checkTransitions(), requestAbort(), and requestTransition().
|
private |
Get board IP and port for actuator.
Definition at line 696 of file PressureStateMachine.cpp.
References board(), board_discovery_, and fsw::daq_wire::kActuator.
Referenced by initialize().
| PressureStateMachine::SystemState fsw::control::PressureStateMachine::getCurrentState | ( | ) | const |
Get current state.
Definition at line 120 of file PressureStateMachine.cpp.
References current_state_.
| std::string fsw::control::PressureStateMachine::getCurrentStateName | ( | ) | const |
Get current state name as string.
Definition at line 124 of file PressureStateMachine.cpp.
References ABORT, ARMED, CALIBRATE, current_state_, DEBUG_STATE, FIRE, FUEL_FILL, FUEL_PRESS, FUEL_VENT, GN2_HIGH_PRESS, GN2_HIGH_VENT, GN2_LOW_PRESS, GN2_VENT, IDLE, OX_FILL, OX_PRESS, OX_VENT, READY, and VENT.
Referenced by executeStateEntryActions(), and requestTransition().
| PressureStateMachine::PressureReadings fsw::control::PressureStateMachine::getLatestPressures | ( | ) | const |
Get latest pressure readings.
Definition at line 213 of file PressureStateMachine.cpp.
References latest_pressures_, lock, and pressure_mutex_.
| bool fsw::control::PressureStateMachine::initialize | ( | std::shared_ptr< elodin::ElodinClient > | elodin_client, |
| std::shared_ptr< config::BoardDiscovery > | board_discovery, | ||
| const PressureThresholds & | thresholds ) |
Initialize the state machine.
| elodin_client | Connected Elodin client for reading pressure data |
| board_discovery | Board discovery instance for getting board IPs |
| thresholds | Pressure thresholds configuration |
Definition at line 42 of file PressureStateMachine.cpp.
References abort_requested_, actuator_board_ip_, actuator_board_port_, board_discovery_, command_socket_, current_state_, elodin_client_, getActuatorBoardAddress(), IDLE, LOX_MAIN, registerPSMVTables(), and thresholds_.
|
private |
Read pressure data from Elodin.
Definition at line 240 of file PressureStateMachine.cpp.
References elodin_client_, latest_pressures_, lock, MAX_PACKET_SIZE, pressure_mutex_, pt_fdp_message_id_, pt_fup_message_id_, pt_hp_message_id_, pt_lp_message_id_, pt_odp_message_id_, and pt_oup_message_id_.
Referenced by stateMachineLoop().
|
private |
Register Elodin VTables for PSM actuator commands and state transitions.
Definition at line 729 of file PressureStateMachine.cpp.
References elodin_client_.
Referenced by initialize().
| void fsw::control::PressureStateMachine::requestAbort | ( | ) |
Request abort.
Definition at line 204 of file PressureStateMachine.cpp.
References ABORT, abort_requested_, current_state_, executeStateEntryActions(), lock, state_entry_time_, and state_mutex_.
| bool fsw::control::PressureStateMachine::requestTransition | ( | SystemState | target_state | ) |
Request transition to a specific state (manual override).
Definition at line 166 of file PressureStateMachine.cpp.
References ABORT, ARMED, current_state_, DEBUG_STATE, executeStateEntryActions(), FUEL_FILL, getCurrentStateName(), IDLE, lock, state_entry_time_, and state_mutex_.
|
private |
Send actuator command.
Definition at line 612 of file PressureStateMachine.cpp.
References actuatorToMessageID(), elodin_client_, comms::CommsMessage< Fields >::fields, and sendActuatorCommandUDP().
Referenced by executeStateEntryActions().
|
private |
Send actuator command via UDP to board.
Definition at line 635 of file PressureStateMachine.cpp.
References actuator_board_ip_, actuator_board_port_, CLOSE, command_socket_, commands, daq::create_actuator_command_packet(), OPEN, PULSE, and SET_POSITION.
Referenced by sendActuatorCommand().
| void fsw::control::PressureStateMachine::start | ( | ) |
Start the state machine.
Definition at line 97 of file PressureStateMachine.cpp.
References running_, state_machine_thread_, and stateMachineLoop().
|
private |
Main state machine loop.
Definition at line 218 of file PressureStateMachine.cpp.
References checkTransitions(), count(), current_state_, executeStateActions(), pressure_read_period_, readPressureData(), running_, and state_machine_period_.
Referenced by start().
| void fsw::control::PressureStateMachine::stop | ( | ) |
Stop the state machine.
Definition at line 108 of file PressureStateMachine.cpp.
References running_, and state_machine_thread_.
Referenced by ~PressureStateMachine().
|
private |
Definition at line 198 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), executeStateEntryActions(), initialize(), PressureStateMachine(), and requestAbort().
|
private |
Definition at line 211 of file PressureStateMachine.hpp.
Referenced by initialize(), and sendActuatorCommandUDP().
|
private |
Definition at line 212 of file PressureStateMachine.hpp.
Referenced by initialize(), and sendActuatorCommandUDP().
|
private |
Definition at line 232 of file PressureStateMachine.hpp.
Referenced by actuatorToMessageID(), and PressureStateMachine().
|
private |
Definition at line 205 of file PressureStateMachine.hpp.
Referenced by getActuatorBoardAddress(), and initialize().
|
private |
Definition at line 208 of file PressureStateMachine.hpp.
Referenced by initialize(), and sendActuatorCommandUDP().
|
private |
Definition at line 197 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), executeStateEntryActions(), getCurrentState(), getCurrentStateName(), initialize(), PressureStateMachine(), requestAbort(), requestTransition(), and stateMachineLoop().
|
private |
Definition at line 202 of file PressureStateMachine.hpp.
Referenced by executeStateEntryActions(), initialize(), readPressureData(), registerPSMVTables(), and sendActuatorCommand().
|
private |
Definition at line 216 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), getLatestPressures(), and readPressureData().
|
mutableprivate |
Definition at line 215 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), getLatestPressures(), and readPressureData().
|
private |
Definition at line 240 of file PressureStateMachine.hpp.
Referenced by stateMachineLoop().
|
private |
Definition at line 227 of file PressureStateMachine.hpp.
Referenced by readPressureData().
|
private |
Definition at line 226 of file PressureStateMachine.hpp.
Referenced by readPressureData().
|
private |
Definition at line 224 of file PressureStateMachine.hpp.
Referenced by readPressureData().
|
private |
Definition at line 225 of file PressureStateMachine.hpp.
Referenced by readPressureData().
|
private |
Definition at line 229 of file PressureStateMachine.hpp.
Referenced by readPressureData().
|
private |
Definition at line 228 of file PressureStateMachine.hpp.
Referenced by readPressureData().
|
private |
Definition at line 196 of file PressureStateMachine.hpp.
Referenced by PressureStateMachine(), start(), stateMachineLoop(), and stop().
|
private |
Definition at line 199 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), PressureStateMachine(), requestAbort(), and requestTransition().
|
private |
Definition at line 239 of file PressureStateMachine.hpp.
Referenced by stateMachineLoop().
|
private |
Definition at line 235 of file PressureStateMachine.hpp.
|
private |
Definition at line 236 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), requestAbort(), and requestTransition().
|
private |
Definition at line 219 of file PressureStateMachine.hpp.
Referenced by checkTransitions(), and initialize().