STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
fsw::control::PressureStateMachine Class Reference

Pressure-based State Machine for Propulsion System. More...

#include <PressureStateMachine.hpp>

Collaboration diagram for fsw::control::PressureStateMachine:
[legend]

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}

Detailed Description

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.

Member Enumeration Documentation

◆ ActuatorID

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.

◆ CommandType

Command types for actuators.

Enumerator
OPEN 
CLOSE 
PULSE 
SET_POSITION 

Definition at line 68 of file PressureStateMachine.hpp.

◆ SystemState

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.

Constructor & Destructor Documentation

◆ PressureStateMachine()

fsw::control::PressureStateMachine::PressureStateMachine ( )

◆ ~PressureStateMachine()

fsw::control::PressureStateMachine::~PressureStateMachine ( )

Definition at line 38 of file PressureStateMachine.cpp.

References stop().

Member Function Documentation

◆ actuatorToMessageID()

uint16_t fsw::control::PressureStateMachine::actuatorToMessageID ( ActuatorID actuator) const
private

Convert actuator ID to message ID from config.

Definition at line 721 of file PressureStateMachine.cpp.

References actuator_message_ids_.

Referenced by sendActuatorCommand().

◆ checkTransitions()

◆ executeStateActions()

void fsw::control::PressureStateMachine::executeStateActions ( SystemState state)
private

Execute state actions (while in state).

Definition at line 607 of file PressureStateMachine.cpp.

References state.

Referenced by stateMachineLoop().

◆ executeStateEntryActions()

◆ getActuatorBoardAddress()

std::pair< std::string, uint16_t > fsw::control::PressureStateMachine::getActuatorBoardAddress ( ActuatorID actuator) const
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().

◆ getCurrentState()

PressureStateMachine::SystemState fsw::control::PressureStateMachine::getCurrentState ( ) const

Get current state.

Definition at line 120 of file PressureStateMachine.cpp.

References current_state_.

◆ getCurrentStateName()

std::string fsw::control::PressureStateMachine::getCurrentStateName ( ) const

◆ getLatestPressures()

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_.

◆ initialize()

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.

Parameters
elodin_clientConnected Elodin client for reading pressure data
board_discoveryBoard discovery instance for getting board IPs
thresholdsPressure thresholds configuration
Returns
true if initialization successful

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_.

◆ readPressureData()

void fsw::control::PressureStateMachine::readPressureData ( )
private

◆ registerPSMVTables()

void fsw::control::PressureStateMachine::registerPSMVTables ( )
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().

◆ requestAbort()

void fsw::control::PressureStateMachine::requestAbort ( )

◆ requestTransition()

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_.

◆ sendActuatorCommand()

void fsw::control::PressureStateMachine::sendActuatorCommand ( ActuatorID actuator,
CommandType command,
float value = 0.0f )
private

◆ sendActuatorCommandUDP()

void fsw::control::PressureStateMachine::sendActuatorCommandUDP ( ActuatorID actuator,
CommandType command,
float value = 0.0f )
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().

◆ start()

void fsw::control::PressureStateMachine::start ( )

Start the state machine.

Definition at line 97 of file PressureStateMachine.cpp.

References running_, state_machine_thread_, and stateMachineLoop().

◆ stateMachineLoop()

void fsw::control::PressureStateMachine::stateMachineLoop ( )
private

◆ stop()

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().

Member Data Documentation

◆ abort_requested_

std::atomic<bool> fsw::control::PressureStateMachine::abort_requested_
private

◆ actuator_board_ip_

std::string fsw::control::PressureStateMachine::actuator_board_ip_
private

Definition at line 211 of file PressureStateMachine.hpp.

Referenced by initialize(), and sendActuatorCommandUDP().

◆ actuator_board_port_

uint16_t fsw::control::PressureStateMachine::actuator_board_port_
private

Definition at line 212 of file PressureStateMachine.hpp.

Referenced by initialize(), and sendActuatorCommandUDP().

◆ actuator_message_ids_

std::map<ActuatorID, uint16_t> fsw::control::PressureStateMachine::actuator_message_ids_
private

Definition at line 232 of file PressureStateMachine.hpp.

Referenced by actuatorToMessageID(), and PressureStateMachine().

◆ board_discovery_

std::shared_ptr<config::BoardDiscovery> fsw::control::PressureStateMachine::board_discovery_
private

Definition at line 205 of file PressureStateMachine.hpp.

Referenced by getActuatorBoardAddress(), and initialize().

◆ command_socket_

std::unique_ptr<daq_comms::transport::UDPSocket> fsw::control::PressureStateMachine::command_socket_
private

Definition at line 208 of file PressureStateMachine.hpp.

Referenced by initialize(), and sendActuatorCommandUDP().

◆ current_state_

std::atomic<SystemState> fsw::control::PressureStateMachine::current_state_
private

◆ elodin_client_

std::shared_ptr<elodin::ElodinClient> fsw::control::PressureStateMachine::elodin_client_
private

◆ latest_pressures_

PressureReadings fsw::control::PressureStateMachine::latest_pressures_
private

◆ pressure_mutex_

std::mutex fsw::control::PressureStateMachine::pressure_mutex_
mutableprivate

◆ pressure_read_period_

std::chrono::milliseconds fsw::control::PressureStateMachine::pressure_read_period_ {50}
private

Definition at line 240 of file PressureStateMachine.hpp.

Referenced by stateMachineLoop().

◆ pt_fdp_message_id_

uint16_t fsw::control::PressureStateMachine::pt_fdp_message_id_ = 0x2013
private

Definition at line 227 of file PressureStateMachine.hpp.

Referenced by readPressureData().

◆ pt_fup_message_id_

uint16_t fsw::control::PressureStateMachine::pt_fup_message_id_ = 0x2011
private

Definition at line 226 of file PressureStateMachine.hpp.

Referenced by readPressureData().

◆ pt_hp_message_id_

uint16_t fsw::control::PressureStateMachine::pt_hp_message_id_ = 0x2016
private

Definition at line 224 of file PressureStateMachine.hpp.

Referenced by readPressureData().

◆ pt_lp_message_id_

uint16_t fsw::control::PressureStateMachine::pt_lp_message_id_ = 0x2011
private

Definition at line 225 of file PressureStateMachine.hpp.

Referenced by readPressureData().

◆ pt_odp_message_id_

uint16_t fsw::control::PressureStateMachine::pt_odp_message_id_ = 0x2017
private

Definition at line 229 of file PressureStateMachine.hpp.

Referenced by readPressureData().

◆ pt_oup_message_id_

uint16_t fsw::control::PressureStateMachine::pt_oup_message_id_ = 0x2015
private

Definition at line 228 of file PressureStateMachine.hpp.

Referenced by readPressureData().

◆ running_

std::atomic<bool> fsw::control::PressureStateMachine::running_
private

Definition at line 196 of file PressureStateMachine.hpp.

Referenced by PressureStateMachine(), start(), stateMachineLoop(), and stop().

◆ state_entry_time_

std::chrono::steady_clock::time_point fsw::control::PressureStateMachine::state_entry_time_
private

◆ state_machine_period_

std::chrono::milliseconds fsw::control::PressureStateMachine::state_machine_period_ {100}
private

Definition at line 239 of file PressureStateMachine.hpp.

Referenced by stateMachineLoop().

◆ state_machine_thread_

std::thread fsw::control::PressureStateMachine::state_machine_thread_
private

Definition at line 235 of file PressureStateMachine.hpp.

Referenced by start(), and stop().

◆ state_mutex_

std::mutex fsw::control::PressureStateMachine::state_mutex_
private

Definition at line 236 of file PressureStateMachine.hpp.

Referenced by checkTransitions(), requestAbort(), and requestTransition().

◆ thresholds_

PressureThresholds fsw::control::PressureStateMachine::thresholds_
private

Definition at line 219 of file PressureStateMachine.hpp.

Referenced by checkTransitions(), and initialize().


The documentation for this class was generated from the following files: