STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
combined_gui Namespace Reference

Classes

class  PacketType
class  ConfigManager
class  UDPReceiver
class  SensorDebugDialog
class  SensorPlotWidget
class  SensorPlotWindow
class  ActuatorControlWidget
class  PWMControlWindow
class  PressureBarWidget
class  TopBarWidget
class  SettingsWidget
class  ActuatorControlWindow
class  CalibrationWindow
class  CombinedMainWindow

Functions

float actuator_counts_to_volts (int data_u32)
 get_num_actuators ()
tuple[Dict[str, Dict[str, str]], int] load_state_machine_csv (Path csv_path)
Dict[str, Dict[str, bool]] load_state_transitions_csv (Path csv_path)
int get_actuator_id_from_role (str role_name)
 apply_state_from_csv (actuator_widget, str state_name, Dict[str, Dict[str, str]] state_machine)
float calculate_pressure (float adc_code, float PT_A, float PT_B, float PT_C, float PT_D)
Tuple[Dict[int, Tuple[float, float, float, float]], Optional[str]] load_pt_calibration (csv_paths)
Optional[Tuple[int, int, int]] parse_packet_header (bytes data)
Optional[Tuple[dict, List[dict]]] parse_sensor_data_packet (bytes data)
bytes create_actuator_command_packet (List[Tuple[int, int]] commands)
bytes create_pwm_actuator_command_packet (List[Tuple[int, int, float, float]] commands)
 main ()

Variables

 _SCRIPT_DIR = Path(__file__).resolve().parent
 PT_CALIBRATION_CSV
 _qt_plugins = os.environ.get("QT_QPA_PLATFORM_PLUGIN_PATH")
list _candidates
 reverse
 _p
 useOpenGL
 True
 antialias
 _file_dir
 _level1 = os.path.dirname(_file_dir)
 _level2 = os.path.dirname(_level1)
 _project_root = os.path.dirname(_level2)
 _calib_path = os.path.join(_project_root, "scripts", "calibration")
bool ROBUST_CALIBRATION_AVAILABLE = True
int DIABLO_COMMS_VERSION = 0
int MAX_PACKET_SIZE = 512
str DEFAULT_SENSOR_IP = "192.168.2.101"
str DEFAULT_ACTUATOR_IP = "192.168.2.201"
int DEFAULT_DEVICE_PORT = 5005
int DEFAULT_RECEIVE_PORT = 5006
str PACKET_HEADER_FORMAT = "<BBI"
int PACKET_HEADER_SIZE = 6
str ACTUATOR_COMMAND_PACKET_FORMAT = "<B"
int ACTUATOR_COMMAND_PACKET_SIZE = 1
str ACTUATOR_COMMAND_FORMAT = "<BB"
int ACTUATOR_COMMAND_SIZE = 2
str PWM_ACTUATOR_COMMAND_PACKET_FORMAT = "<B"
int PWM_ACTUATOR_COMMAND_PACKET_SIZE = 1
str PWM_ACTUATOR_COMMAND_FORMAT = "<BIff"
int PWM_ACTUATOR_COMMAND_SIZE = 13
str SENSOR_DATA_PACKET_FORMAT = "<BB"
int SENSOR_DATA_PACKET_SIZE = 2
str SENSOR_DATA_CHUNK_FORMAT = "<I"
int SENSOR_DATA_CHUNK_SIZE = 4
str SENSOR_DATAPOINT_FORMAT = "<BI"
int SENSOR_DATAPOINT_SIZE = 5
int ACT_ADC_MAX = 4095
float ACT_ADC_VREF = 3.3
float DEFAULT_WINDOW_SECONDS = 10.0
int MAX_POINTS = 200000
int UPDATE_INTERVAL_MS = 100
int NUM_CONNECTORS = 10
list DEFAULT_ACTUATOR_ROLE_NAMES
list DEFAULT_SENSOR_ROLE_NAMES
dict DEFAULT_ACTUATOR_ABBREV_TO_ROLE
list ACTUATOR_DISPLAY_ORDER_WHEN_ROLES
str ACTUATOR_LABELS_FILE = _SCRIPT_DIR / "actuator_labels.json"
str SENSOR_LABELS_FILE = _SCRIPT_DIR / "sensor_labels.json"
list SENSOR_COLORS
str CONFIG_FILE = _SCRIPT_DIR / "config.json"
str _DEFAULT_STATE_MACHINE_CSV = _SCRIPT_DIR / "state_machine_actuators.csv"
str _DEFAULT_STATE_TRANSITIONS_CSV = _SCRIPT_DIR / "state_transitions.csv"
 CONFIG = ConfigManager()

Detailed Description

Combined Sensor & Actuator Control GUI
Opens one full-screen window with:
- Left (66%): Sensor/PT data receiver and real-time plotting
- Right (33%): Actuator control and voltage monitoring

Requirements: pip install pyqt6 pyqtgraph numpy

Function Documentation

◆ actuator_counts_to_volts()

float combined_gui.actuator_counts_to_volts ( int data_u32)
Actuator current-sense datapoint -> volts.

Boards send raw 12-bit counts (<= 4095). Firmware from before that sent
float volts as bits; any nonzero voltage float encodes far above 4095, so
those are still read as floats until every board is reflashed.

Definition at line 160 of file combined_gui.py.

Referenced by combined_gui.ActuatorControlWidget.on_sensor_data().

◆ apply_state_from_csv()

combined_gui.apply_state_from_csv ( actuator_widget,
str state_name,
Dict[str, Dict[str, str]] state_machine )
Apply actuator states from CSV for the given state name.

Mapping:
- FV = Fuel Vent
- OV = LOX Vent
- FP = Fuel Press
- OP = LOX Press
- FM = Fuel Main
- OM = LOX Main

Definition at line 648 of file combined_gui.py.

References get_actuator_id_from_role(), and get_num_actuators().

◆ calculate_pressure()

float combined_gui.calculate_pressure ( float adc_code,
float PT_A,
float PT_B,
float PT_C,
float PT_D )
Compute pressure (psi) from ADC code using cubic polynomial.

Definition at line 713 of file combined_gui.py.

Referenced by combined_gui.SensorPlotWidget.on_sensor_data(), and combined_gui.SensorPlotWidget.zero_pts().

◆ create_actuator_command_packet()

bytes combined_gui.create_actuator_command_packet ( List[Tuple[int, int]] commands)
Create an actuator command packet.
commands: List of (actuator_id, actuator_state) tuples
actuator_id: 1-10 (1-indexed)
actuator_state: 0 = OFF, non-zero = ON

Definition at line 927 of file combined_gui.py.

References time.time().

Referenced by combined_gui.ActuatorControlWidget.send_actuator_command().

◆ create_pwm_actuator_command_packet()

bytes combined_gui.create_pwm_actuator_command_packet ( List[Tuple[int, int, float, float]] commands)
Creates a PWM Actuator Command packet.
Packet layout: PacketHeader + PWMActuatorCommandPacket + N PWMActuatorCommand.

commands: List of tuples (actuator_id, duration_ms, duty_cycle, frequency)
          Note: duration is in ms (uint32), duty_cycle is float (0.0-1.0), frequency is float (Hz)

Definition at line 975 of file combined_gui.py.

References time.time().

Referenced by combined_gui.PWMControlWindow.execute_now().

◆ get_actuator_id_from_role()

int combined_gui.get_actuator_id_from_role ( str role_name)
Get actuator ID from role name. Returns 0 if not found.

Definition at line 643 of file combined_gui.py.

Referenced by apply_state_from_csv().

◆ get_num_actuators()

◆ load_pt_calibration()

Tuple[Dict[int, Tuple[float, float, float, float]], Optional[str]] combined_gui.load_pt_calibration ( csv_paths)
Load PT calibration coefficients from one or more CSV files.
Args:
    csv_paths: Single CSV path (str) or list of CSV paths. Empty string/list uses default.
Returns:
    Tuple of (result_dict, error_message):
    - result_dict: connector_id -> (PT_A, PT_B, PT_C, PT_D) for each PT present in CSVs
    - error_message: None if successful, error string if duplicates or other errors found
The number in the CSV (PT1, PT2, ...) is the board connector number; this same ID is used
everywhere: config.json sensor_roles, mappings, and packet sensor_id.
CSV columns per PT: ADC Code, Pressure, Coefficient 0 (A), 1 (B), 2 (C), 3 (D).
Uses the last data row as the calibration coefficients.
Works with any number of PTs; PT numbers are discovered from column names "PT{N} Coefficient 0".
If multiple CSVs contain the same PT number, returns error message listing duplicates.

Definition at line 720 of file combined_gui.py.

Referenced by combined_gui.SensorPlotWidget.reload_pt_calibration().

◆ load_state_machine_csv()

tuple[Dict[str, Dict[str, str]], int] combined_gui.load_state_machine_csv ( Path csv_path)
Load state machine CSV file.
Returns tuple: (state_machine_dict, num_actuators)
state_machine_dict: state_name -> {actuator_abbrev -> OPEN/CLOSE}
num_actuators: number of actuators found in CSV
CSV format: first row is header with state names (first column empty), first column of data rows is actuator abbreviations

Definition at line 530 of file combined_gui.py.

Referenced by combined_gui.ConfigManager.get_num_actuators().

◆ load_state_transitions_csv()

Dict[str, Dict[str, bool]] combined_gui.load_state_transitions_csv ( Path csv_path)
Load state transitions CSV file.
Returns dict: current_state -> {next_state -> allowed (True/False)}
CSV format: first row is header with next states, first column is current states

Definition at line 593 of file combined_gui.py.

◆ main()

combined_gui.main ( void )
Main entry point

Definition at line 5995 of file combined_gui.py.

◆ parse_packet_header()

Optional[Tuple[int, int, int]] combined_gui.parse_packet_header ( bytes data)
Parse the packet header. Returns: (packet_type, version, timestamp) or None

Definition at line 851 of file combined_gui.py.

Referenced by parse_sensor_data_packet(), and combined_gui.UDPReceiver.run().

◆ parse_sensor_data_packet()

Optional[Tuple[dict, List[dict]]] combined_gui.parse_sensor_data_packet ( bytes data)
Parse a sensor data packet. Returns: (header_dict, chunks_list) or None

Definition at line 864 of file combined_gui.py.

References parse_packet_header().

Referenced by combined_gui.UDPReceiver.run().

Variable Documentation

◆ _calib_path

combined_gui._calib_path = os.path.join(_project_root, "scripts", "calibration")
protected

Definition at line 83 of file combined_gui.py.

◆ _candidates

list combined_gui._candidates
protected
Initial value:
1= [
2 "/opt/homebrew/share/qt/plugins/platforms",
3 "/opt/homebrew/Cellar/qtbase/6.10.1/share/qt/plugins/platforms",
4 ]

Definition at line 38 of file combined_gui.py.

◆ _DEFAULT_STATE_MACHINE_CSV

str combined_gui._DEFAULT_STATE_MACHINE_CSV = _SCRIPT_DIR / "state_machine_actuators.csv"
protected

Definition at line 230 of file combined_gui.py.

◆ _DEFAULT_STATE_TRANSITIONS_CSV

str combined_gui._DEFAULT_STATE_TRANSITIONS_CSV = _SCRIPT_DIR / "state_transitions.csv"
protected

Definition at line 231 of file combined_gui.py.

◆ _file_dir

combined_gui._file_dir
protected
Initial value:
1= os.path.dirname(
2 os.path.abspath(__file__)
3)

Definition at line 77 of file combined_gui.py.

◆ _level1

combined_gui._level1 = os.path.dirname(_file_dir)
protected

Definition at line 80 of file combined_gui.py.

◆ _level2

combined_gui._level2 = os.path.dirname(_level1)
protected

Definition at line 81 of file combined_gui.py.

◆ _p

combined_gui._p
protected
Initial value:
1= os.path.join(
2 "/opt/homebrew/Cellar/qtbase",
3 _name,
4 "share",
5 "qt",
6 "plugins",
7 "platforms",
8 )

Definition at line 46 of file combined_gui.py.

◆ _project_root

combined_gui._project_root = os.path.dirname(_level2)
protected

Definition at line 82 of file combined_gui.py.

◆ _qt_plugins

combined_gui._qt_plugins = os.environ.get("QT_QPA_PLATFORM_PLUGIN_PATH")
protected

Definition at line 36 of file combined_gui.py.

◆ _SCRIPT_DIR

combined_gui._SCRIPT_DIR = Path(__file__).resolve().parent
protected

Definition at line 24 of file combined_gui.py.

◆ ACT_ADC_MAX

int combined_gui.ACT_ADC_MAX = 4095

Definition at line 156 of file combined_gui.py.

◆ ACT_ADC_VREF

float combined_gui.ACT_ADC_VREF = 3.3

Definition at line 157 of file combined_gui.py.

◆ ACTUATOR_COMMAND_FORMAT

str combined_gui.ACTUATOR_COMMAND_FORMAT = "<BB"

Definition at line 137 of file combined_gui.py.

◆ ACTUATOR_COMMAND_PACKET_FORMAT

str combined_gui.ACTUATOR_COMMAND_PACKET_FORMAT = "<B"

Definition at line 134 of file combined_gui.py.

◆ ACTUATOR_COMMAND_PACKET_SIZE

int combined_gui.ACTUATOR_COMMAND_PACKET_SIZE = 1

Definition at line 135 of file combined_gui.py.

◆ ACTUATOR_COMMAND_SIZE

int combined_gui.ACTUATOR_COMMAND_SIZE = 2

Definition at line 138 of file combined_gui.py.

◆ ACTUATOR_DISPLAY_ORDER_WHEN_ROLES

list combined_gui.ACTUATOR_DISPLAY_ORDER_WHEN_ROLES
Initial value:
1= [
2 "Fuel Vent",
3 "LOX Vent",
4 "Fuel Press",
5 "LOX Press",
6 "Fuel Main",
7 "LOX Main",
8 "Fuel Fill",
9]

Definition at line 202 of file combined_gui.py.

◆ ACTUATOR_LABELS_FILE

str combined_gui.ACTUATOR_LABELS_FILE = _SCRIPT_DIR / "actuator_labels.json"

Definition at line 211 of file combined_gui.py.

◆ antialias

combined_gui.antialias

Definition at line 68 of file combined_gui.py.

◆ CONFIG

combined_gui.CONFIG = ConfigManager()

Definition at line 515 of file combined_gui.py.

◆ CONFIG_FILE

str combined_gui.CONFIG_FILE = _SCRIPT_DIR / "config.json"

Definition at line 229 of file combined_gui.py.

◆ DEFAULT_ACTUATOR_ABBREV_TO_ROLE

dict combined_gui.DEFAULT_ACTUATOR_ABBREV_TO_ROLE
Initial value:
1= {
2 "FV": "Fuel Vent",
3 "OV": "LOX Vent",
4 "FP": "Fuel Press",
5 "OP": "LOX Press",
6 "FM": "Fuel Main",
7 "OM": "LOX Main",
8}

Definition at line 193 of file combined_gui.py.

◆ DEFAULT_ACTUATOR_IP

str combined_gui.DEFAULT_ACTUATOR_IP = "192.168.2.201"

Definition at line 126 of file combined_gui.py.

◆ DEFAULT_ACTUATOR_ROLE_NAMES

list combined_gui.DEFAULT_ACTUATOR_ROLE_NAMES
Initial value:
1= [
2 "LOX Main",
3 "Fuel Main",
4 "Fuel Vent",
5 "Fuel Press",
6 "LOX Vent",
7 "LOX Press",
8]

Definition at line 179 of file combined_gui.py.

◆ DEFAULT_DEVICE_PORT

int combined_gui.DEFAULT_DEVICE_PORT = 5005

Definition at line 127 of file combined_gui.py.

◆ DEFAULT_RECEIVE_PORT

int combined_gui.DEFAULT_RECEIVE_PORT = 5006

Definition at line 128 of file combined_gui.py.

◆ DEFAULT_SENSOR_IP

str combined_gui.DEFAULT_SENSOR_IP = "192.168.2.101"

Definition at line 125 of file combined_gui.py.

◆ DEFAULT_SENSOR_ROLE_NAMES

list combined_gui.DEFAULT_SENSOR_ROLE_NAMES
Initial value:
1= [
2 "LOX Upstream",
3 "LOX Downstream",
4 "Low Press PT",
5 "Fuel Downstream",
6]

Definition at line 187 of file combined_gui.py.

◆ DEFAULT_WINDOW_SECONDS

float combined_gui.DEFAULT_WINDOW_SECONDS = 10.0

Definition at line 173 of file combined_gui.py.

◆ DIABLO_COMMS_VERSION

int combined_gui.DIABLO_COMMS_VERSION = 0

Definition at line 105 of file combined_gui.py.

◆ MAX_PACKET_SIZE

int combined_gui.MAX_PACKET_SIZE = 512

Definition at line 106 of file combined_gui.py.

◆ MAX_POINTS

int combined_gui.MAX_POINTS = 200000

Definition at line 174 of file combined_gui.py.

◆ NUM_CONNECTORS

combined_gui.NUM_CONNECTORS = 10

Definition at line 176 of file combined_gui.py.

◆ PACKET_HEADER_FORMAT

str combined_gui.PACKET_HEADER_FORMAT = "<BBI"

Definition at line 131 of file combined_gui.py.

◆ PACKET_HEADER_SIZE

int combined_gui.PACKET_HEADER_SIZE = 6

Definition at line 132 of file combined_gui.py.

◆ PT_CALIBRATION_CSV

combined_gui.PT_CALIBRATION_CSV
Initial value:
1= str(
2 _SCRIPT_DIR.parent.parent
3 / "PT_Board"
4 / "Calibration"
5 / "PT Calibration Attempt 2026-02-04_test2.csv"
6)

Definition at line 27 of file combined_gui.py.

◆ PWM_ACTUATOR_COMMAND_FORMAT

str combined_gui.PWM_ACTUATOR_COMMAND_FORMAT = "<BIff"

Definition at line 143 of file combined_gui.py.

◆ PWM_ACTUATOR_COMMAND_PACKET_FORMAT

str combined_gui.PWM_ACTUATOR_COMMAND_PACKET_FORMAT = "<B"

Definition at line 140 of file combined_gui.py.

◆ PWM_ACTUATOR_COMMAND_PACKET_SIZE

int combined_gui.PWM_ACTUATOR_COMMAND_PACKET_SIZE = 1

Definition at line 141 of file combined_gui.py.

◆ PWM_ACTUATOR_COMMAND_SIZE

int combined_gui.PWM_ACTUATOR_COMMAND_SIZE = 13

Definition at line 144 of file combined_gui.py.

◆ reverse

combined_gui.reverse

Definition at line 44 of file combined_gui.py.

◆ ROBUST_CALIBRATION_AVAILABLE

bool combined_gui.ROBUST_CALIBRATION_AVAILABLE = True

Definition at line 93 of file combined_gui.py.

◆ SENSOR_COLORS

list combined_gui.SENSOR_COLORS
Initial value:
1= [
2 (255, 80, 80), # Red
3 (80, 255, 80), # Green
4 (80, 150, 255), # Blue
5 (255, 200, 80), # Orange
6 (200, 80, 255), # Purple
7 (80, 255, 255), # Cyan
8 (255, 150, 150), # Light Red
9 (150, 255, 150), # Light Green
10 (150, 200, 255), # Light Blue
11 (255, 255, 80), # Yellow
12]

Definition at line 215 of file combined_gui.py.

◆ SENSOR_DATA_CHUNK_FORMAT

str combined_gui.SENSOR_DATA_CHUNK_FORMAT = "<I"

Definition at line 149 of file combined_gui.py.

◆ SENSOR_DATA_CHUNK_SIZE

int combined_gui.SENSOR_DATA_CHUNK_SIZE = 4

Definition at line 150 of file combined_gui.py.

◆ SENSOR_DATA_PACKET_FORMAT

str combined_gui.SENSOR_DATA_PACKET_FORMAT = "<BB"

Definition at line 146 of file combined_gui.py.

◆ SENSOR_DATA_PACKET_SIZE

int combined_gui.SENSOR_DATA_PACKET_SIZE = 2

Definition at line 147 of file combined_gui.py.

◆ SENSOR_DATAPOINT_FORMAT

str combined_gui.SENSOR_DATAPOINT_FORMAT = "<BI"

Definition at line 152 of file combined_gui.py.

◆ SENSOR_DATAPOINT_SIZE

int combined_gui.SENSOR_DATAPOINT_SIZE = 5

Definition at line 153 of file combined_gui.py.

◆ SENSOR_LABELS_FILE

str combined_gui.SENSOR_LABELS_FILE = _SCRIPT_DIR / "sensor_labels.json"

Definition at line 212 of file combined_gui.py.

◆ True

combined_gui.True

Definition at line 68 of file combined_gui.py.

◆ UPDATE_INTERVAL_MS

int combined_gui.UPDATE_INTERVAL_MS = 100

Definition at line 175 of file combined_gui.py.

◆ useOpenGL

combined_gui.useOpenGL

Definition at line 68 of file combined_gui.py.