opengnc.fdir package
Submodules
opengnc.fdir.failure_accommodation module
Actuator accommodation and control allocation weight adjustment.
- class opengnc.fdir.failure_accommodation.ActuatorAccommodation(B: ndarray, initial_weights: ndarray | None = None)[source]
Bases:
objectActuator Fault Accommodation and Weighted Control Allocation.
Redistributes control efforts across healthy actuators in response to partial or total failures. Allocation Logic: $mathbf{u} = mathbf{W}^{-1} mathbf{B}^T (mathbf{B} mathbf{W}^{-1} mathbf{B}^T)^{-1} tau$.
- Parameters:
B (np.ndarray) – Control allocation (geometry) matrix of shape $(k, m)$.
initial_weights (np.ndarray, optional) – Weight matrix $mathbf{W}$ (relative cost of using each actuator). Can be $(m, m)$ or diagonal $(m,)$. Defaults to identity.
- allocate(tau: ndarray) ndarray[source]
Map desired torque/effort to actuator commands.
- Parameters:
tau (np.ndarray) – Desired control effort $(k,)$.
- Returns:
Actuator command vector $(m,)$.
- Return type:
np.ndarray
opengnc.fdir.parity_space module
Parity Space methods for Fault Detection and Isolation (FDI).
- class opengnc.fdir.parity_space.ParitySpaceDetector(M: ndarray)[source]
Bases:
objectFault Detection and Isolation (FDI) via Parity Space.
Measurement Model: $mathbf{y} = mathbf{M}mathbf{x} + mathbf{v} + mathbf{f}$
The Parity Matrix $mathbf{P}$ satisfies $mathbf{P}mathbf{M} = mathbf{0}$. The Parity Vector is $mathbf{p} = mathbf{P}mathbf{y}$.
- Parameters:
M (np.ndarray) – Geometry matrix $(p times n)$, $p > n$.
- detect_fault(y: ndarray, threshold: float) bool[source]
Detect fault by checking if $|mathbf{p}| > epsilon$.
- Parameters:
y (np.ndarray) – Measurement vector.
threshold (float) – Fault detection threshold.
- Returns:
True if a fault is detected.
- Return type:
bool
opengnc.fdir.residual_generation module
Residual generation for fault detection using observers.
- class opengnc.fdir.residual_generation.AnalyticalRedundancy[source]
Bases:
objectUtilities for Analytical Redundancy-based Fault Detection.
- static check_threshold(r: ndarray, threshold: float) bool[source]
Threshold check for a residual vector.
- Parameters:
r (np.ndarray) – Residual vector.
threshold (float) – Fault limit.
- Returns:
True if $|mathbf{r}| > text{threshold}$.
- Return type:
bool
- static gyro_vs_quaternion_residual(q_dot_measured: ndarray, q_dot_calculated: ndarray) ndarray[source]
Residual between attitude rate kinematics and sensor differentiator.
Calculates $mathbf{r} = dot{mathbf{q}}_m - dot{mathbf{q}}_c$, where $dot{mathbf{q}}_c = frac{1}{2} mathbf{q} otimes mathbf{omega}$.
- Parameters:
q_dot_measured (np.ndarray) – Measured quaternion derivative.
q_dot_calculated (np.ndarray) – Calculated derivative from gyros.
- Returns:
Attitude residual vector.
- Return type:
np.ndarray
- class opengnc.fdir.residual_generation.ObserverResidualGenerator(A: ndarray, B: ndarray, C: ndarray, D: ndarray | None = None, L: ndarray | None = None, x0: ndarray | None = None)[source]
Bases:
objectFault Residual Generation via Luenberger Observer.
Implements a linear observer to estimate system outputs and generate innovation-based residuals. Observer Dynamics: $hat{mathbf{x}}_{k+1} = mathbf{A} hat{mathbf{x}}_k + mathbf{B} mathbf{u}_k + mathbf{L} (mathbf{y}_k - hat{mathbf{y}}_k)$ Residual: $mathbf{r}_k = mathbf{y}_k - mathbf{C} hat{mathbf{x}}_k$.
- Parameters:
A (np.ndarray) – State transition matrix $(n, n)$.
B (np.ndarray) – Input matrix $(n, m)$.
C (np.ndarray) – Output matrix $(p, n)$.
D (np.ndarray, optional) – Feedthrough matrix $(p, m)$. Defaults to zero.
L (np.ndarray) – Observer gain matrix $(n, p)$.
x0 (np.ndarray, optional) – Initial state estimate.
opengnc.fdir.safe_mode module
Safe mode and fault detection logic for system mode transitions.
- class opengnc.fdir.safe_mode.SafeModeCondition(check_fn: Callable[[], bool], trigger_time_sec: float = 0.0)[source]
Bases:
objectTrigger logic for Safe Mode state transitions.
Monitors a specific fault condition and confirms it based on a time-to-trigger threshold to avoid false positives.
- Parameters:
check_fn (Callable[[], bool]) – Function returning True if the condition is currently violated.
trigger_time_sec (float, optional) – Confirmation threshold (s). Default is 0.0 (immediate).
- class opengnc.fdir.safe_mode.SafeModeLogic(initial_mode: SystemMode = SystemMode.NOMINAL)[source]
Bases:
objectFinite State Machine for Spacecraft Mode Management (FDIR).
- Parameters:
initial_mode (SystemMode, optional) – Starting mode. Default is NOMINAL.
- add_condition(name: str, condition: SafeModeCondition) None[source]
Register a new safety trigger.
- Parameters:
name (str) – Unique identifier for the condition.
condition (SafeModeCondition) – Trigger implementation.
- force_mode(mode: SystemMode, reason: str = 'Commanded') None[source]
Force a mode transition (e.g., via ground command).
- Parameters:
mode (SystemMode) – Target mode.
reason (str, optional) – Rationale for the forced change.
- update() SystemMode[source]
Process all conditions and update system mode.
- Returns:
Current operating mode.
- Return type:
Module contents
Fault Detection, Isolation & Recovery (FDIR) module.
- class opengnc.fdir.ActuatorAccommodation(B: ndarray, initial_weights: ndarray | None = None)[source]
Bases:
objectActuator Fault Accommodation and Weighted Control Allocation.
Redistributes control efforts across healthy actuators in response to partial or total failures. Allocation Logic: $mathbf{u} = mathbf{W}^{-1} mathbf{B}^T (mathbf{B} mathbf{W}^{-1} mathbf{B}^T)^{-1} tau$.
- Parameters:
B (np.ndarray) – Control allocation (geometry) matrix of shape $(k, m)$.
initial_weights (np.ndarray, optional) – Weight matrix $mathbf{W}$ (relative cost of using each actuator). Can be $(m, m)$ or diagonal $(m,)$. Defaults to identity.
- allocate(tau: ndarray) ndarray[source]
Map desired torque/effort to actuator commands.
- Parameters:
tau (np.ndarray) – Desired control effort $(k,)$.
- Returns:
Actuator command vector $(m,)$.
- Return type:
np.ndarray
- class opengnc.fdir.AnalyticalRedundancy[source]
Bases:
objectUtilities for Analytical Redundancy-based Fault Detection.
- static check_threshold(r: ndarray, threshold: float) bool[source]
Threshold check for a residual vector.
- Parameters:
r (np.ndarray) – Residual vector.
threshold (float) – Fault limit.
- Returns:
True if $|mathbf{r}| > text{threshold}$.
- Return type:
bool
- static gyro_vs_quaternion_residual(q_dot_measured: ndarray, q_dot_calculated: ndarray) ndarray[source]
Residual between attitude rate kinematics and sensor differentiator.
Calculates $mathbf{r} = dot{mathbf{q}}_m - dot{mathbf{q}}_c$, where $dot{mathbf{q}}_c = frac{1}{2} mathbf{q} otimes mathbf{omega}$.
- Parameters:
q_dot_measured (np.ndarray) – Measured quaternion derivative.
q_dot_calculated (np.ndarray) – Calculated derivative from gyros.
- Returns:
Attitude residual vector.
- Return type:
np.ndarray
- class opengnc.fdir.ObserverResidualGenerator(A: ndarray, B: ndarray, C: ndarray, D: ndarray | None = None, L: ndarray | None = None, x0: ndarray | None = None)[source]
Bases:
objectFault Residual Generation via Luenberger Observer.
Implements a linear observer to estimate system outputs and generate innovation-based residuals. Observer Dynamics: $hat{mathbf{x}}_{k+1} = mathbf{A} hat{mathbf{x}}_k + mathbf{B} mathbf{u}_k + mathbf{L} (mathbf{y}_k - hat{mathbf{y}}_k)$ Residual: $mathbf{r}_k = mathbf{y}_k - mathbf{C} hat{mathbf{x}}_k$.
- Parameters:
A (np.ndarray) – State transition matrix $(n, n)$.
B (np.ndarray) – Input matrix $(n, m)$.
C (np.ndarray) – Output matrix $(p, n)$.
D (np.ndarray, optional) – Feedthrough matrix $(p, m)$. Defaults to zero.
L (np.ndarray) – Observer gain matrix $(n, p)$.
x0 (np.ndarray, optional) – Initial state estimate.
- class opengnc.fdir.ParitySpaceDetector(M: ndarray)[source]
Bases:
objectFault Detection and Isolation (FDI) via Parity Space.
Measurement Model: $mathbf{y} = mathbf{M}mathbf{x} + mathbf{v} + mathbf{f}$
The Parity Matrix $mathbf{P}$ satisfies $mathbf{P}mathbf{M} = mathbf{0}$. The Parity Vector is $mathbf{p} = mathbf{P}mathbf{y}$.
- Parameters:
M (np.ndarray) – Geometry matrix $(p times n)$, $p > n$.
- detect_fault(y: ndarray, threshold: float) bool[source]
Detect fault by checking if $|mathbf{p}| > epsilon$.
- Parameters:
y (np.ndarray) – Measurement vector.
threshold (float) – Fault detection threshold.
- Returns:
True if a fault is detected.
- Return type:
bool
- class opengnc.fdir.SafeModeCondition(check_fn: Callable[[], bool], trigger_time_sec: float = 0.0)[source]
Bases:
objectTrigger logic for Safe Mode state transitions.
Monitors a specific fault condition and confirms it based on a time-to-trigger threshold to avoid false positives.
- Parameters:
check_fn (Callable[[], bool]) – Function returning True if the condition is currently violated.
trigger_time_sec (float, optional) – Confirmation threshold (s). Default is 0.0 (immediate).
- update() bool[source]
Evaluate condition and return True if confirmation time is exceeded.
- Returns:
True if safety trigger is active.
- Return type:
bool
- violated_start_time: float | None
- class opengnc.fdir.SafeModeLogic(initial_mode: SystemMode = SystemMode.NOMINAL)[source]
Bases:
objectFinite State Machine for Spacecraft Mode Management (FDIR).
- Parameters:
initial_mode (SystemMode, optional) – Starting mode. Default is NOMINAL.
- add_condition(name: str, condition: SafeModeCondition) None[source]
Register a new safety trigger.
- Parameters:
name (str) – Unique identifier for the condition.
condition (SafeModeCondition) – Trigger implementation.
- conditions: dict[str, SafeModeCondition]
- force_mode(mode: SystemMode, reason: str = 'Commanded') None[source]
Force a mode transition (e.g., via ground command).
- Parameters:
mode (SystemMode) – Target mode.
reason (str, optional) – Rationale for the forced change.
- history: list[dict[str, Any]]
- update() SystemMode[source]
Process all conditions and update system mode.
- Returns:
Current operating mode.
- Return type: