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.

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 x B opposes the component of the angular momentum error perpendicular to the magnetic field.

Control law: m = k * (H_err x B) / ||B||^2.

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

Calculate the required magnetic dipole moment.

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.

compute_torque(omega: ndarray) ndarray[source]

Compute the commanded damping torque.

Module contents

class opengnc.classical_control.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

class opengnc.classical_control.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 x B opposes the component of the angular momentum error perpendicular to the magnetic field.

Control law: m = k * (H_err x B) / ||B||^2.

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

Calculate the required magnetic dipole moment.

class opengnc.classical_control.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

class opengnc.classical_control.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.

compute_torque(omega: ndarray) ndarray[source]

Compute the commanded damping torque.