opengnc.classical_control package

Submodules

opengnc.classical_control.bdot module

B-Dot controller for spacecraft magnetic detumbling.

class opengnc.classical_control.bdot.BDot(gain: float)[source]

Bases: object

B-Dot controller for magnetic detumbling.

Control Law: $mathbf{m} = -K_{gain} dot{mathbf{B}}$

Parameters:

gain (float) – Feedback gain $K$ ($Am^2 s / T$).

calculate_control(b_dot: ndarray | list[float]) ndarray[source]

Calculate the required magnetic dipole moment from the B-field rate.

Parameters:

b_dot (np.ndarray or list) – The time derivative of the magnetic field vector ($dot{B}$) in the Body frame (3,). Units: [T/s].

Returns:

Magnetic dipole moment vector $m$ in Body frame (3,). Units: $[A cdot m^2]$.

Return type:

np.ndarray

calculate_control_discrete(b_field_curr: ndarray | list[float], b_field_prev: ndarray | list[float], dt: float) ndarray[source]

Calculate B-Dot control using discrete finite differences.

Useful when only B-field measurements are available instead of explicit rates.

Parameters:
  • b_field_curr (np.ndarray or list) – Current magnetic field vector measurement (Body frame). Units: [T].

  • b_field_prev (np.ndarray or list) – Previous magnetic field vector measurement (Body frame). Units: [T].

  • dt (float) – Time step between measurements (s).

Returns:

Magnetic dipole moment vector $m$ in Body frame (3,).

Return type:

np.ndarray

opengnc.classical_control.momentum_dumping module

Reaction wheel momentum desaturation using magnetic torque (Cross-Product Law).

class opengnc.classical_control.momentum_dumping.CrossProductLaw(gain: float, max_dipole: float | None = None)[source]

Bases: object

Reaction wheel momentum desaturation using the Cross-Product Law.

This controller calculates a magnetic dipole moment ‘m’ such that the resulting magnetic torque $T = m times B$ opposes the component of the angular momentum error perpendicular to the magnetic field.

Control law: $m = k frac{H_{err} times B}{|B|^2}$

Parameters:
  • gain (float) – Feedback gain $k$ ($k > 0$). Units: $[s^{-1}]$.

  • max_dipole (float, optional) – Maximum magnetic dipole moment allowed (saturation) [Am^2].

calculate_control(h_error: ndarray | list[float], b_field: ndarray | list[float]) ndarray[source]

Calculate the required magnetic dipole moment.

Parameters:
  • h_error (np.ndarray or list) – The angular momentum vector to be dumped (3,). Units: [Nms].

  • b_field (np.ndarray or list) – The local magnetic field vector in Body frame (3,). Units: [T].

Returns:

Magnetic dipole moment vector $m$ [Am^2] (3,).

Return type:

np.ndarray

opengnc.classical_control.pid module

Generic PID controller implementation with anti-windup logic.

class opengnc.classical_control.pid.PID(kp: float, ki: float, kd: float, output_limits: tuple[float, float] | None = None, anti_windup_method: str = 'clamping')[source]

Bases: object

Generic PID controller with anti-windup.

Control Law: $u(t) = K_p e(t) + K_i int_0^t e(tau) dtau + K_d frac{de(t)}{dt}$

Parameters:
  • kp (float) – Proportional gain.

  • ki (float) – Integral gain.

  • kd (float) – Derivative gain.

  • output_limits (tuple[float, float] | None, optional) – (min, max) saturation limits.

  • anti_windup_method (str, optional) – Method (e.g., “clamping”). Default “clamping”.

reset() None[source]

Reset the internal integrator and error states to zero.

update(error: float, dt: float) float[source]

Update the PID control calculation for a single time step.

Parameters:
  • error (float) – The current error signal (setpoint - measured).

  • dt (float) – Time step since the last update (s).

Returns:

The computed control output signal.

Return type:

float

opengnc.classical_control.rate_damping module

Proportional rate damping controller for torque-based detumbling.

class opengnc.classical_control.rate_damping.RateDampingControl(gain: float, max_torque: float | None = None)[source]

Bases: object

Proportional angular rate damping controller for spacecraft detumbling.

Generates torque commands to reduce the spacecraft’s angular rates, typically using thrusters or other active actuators.

Control law: $T = -K omega$

Parameters:
  • gain (float) – Proportional damping gain $K$ ($K > 0$).

  • max_torque (float, optional) – Maximum torque command magnitude allowed (N-m). Default is None.

compute_torque(omega: ndarray) ndarray[source]

Compute the commanded damping torque.

Parameters:

omega (np.ndarray) – Measured angular velocity vector in the body frame (3,). Units: [rad/s].

Returns:

Commanded torque vector in the body frame (3,). Units: [N-m].

Return type:

np.ndarray

Module contents