LTISimulator#

class do_dpc.control_utils.lti_systems.LTISimulator(sys, x_0, process_noise=None, measurement_noise=None)[source]#

Bases: object

Simulates a Linear Time-Invariant (LTI) system of the form:

\[x[k+1] = A * x[k] + B * u[k] + w[k] y[k] = C * x[k] + D * u[k] + v[k]\]
where:
  • \(x[k]\) is the system state at time step k,

  • \(u[k]\) is the input at time step k,

  • \(w[k]\) is the process noise,

  • \(y[k]\) is the system output,

  • \(v[k]\) is the measurement noise.

The system is simulated with state-space matrices \(A\), \(B\), \(C\), and \(D\), and optionally, process and measurement noise can be added using white noise generators.

sys#

Matrix representation of the system.

Type:

StateSpaceModel

x_0#

Initial state vector (shape (n,)), representing the state at time step 0.

Type:

np.ndarray

process_noise#

Noise affecting the system state.

Type:

Optional[WhiteNoiseGenerator]

measurement_noise#

Noise affecting the system output.

Type:

Optional[WhiteNoiseGenerator]

Parameters:
  • sys (StateSpaceModel) – Matrix representation of the system.

  • x_0 (np.ndarray) – Initial state vector (shape (n,)).

  • process_noise (Optional[WhiteNoiseGenerator]) – Noise affecting system state.

  • measurement_noise (Optional[WhiteNoiseGenerator]) – Noise affecting system output.

Raises:

ValueError – If x_0 dimensions are inconsistent.

Methods#

calculate_inf_hor_Kalman_gain_K#

do_dpc.control_utils.lti_systems.LTISimulator.calculate_inf_hor_Kalman_gain_K(self)#

Computes the infinite-horizon Kalman Gain (K) for state estimation.

System model:

x[n+1] = A x[n] + B u[n] + G w[n] y[n] = C x[n] + D u[n] + v[n]

Noise covariance properties:

E{w w^T} = QN (Process noise covariance) E{v v^T} = RN (Measurement noise covariance) E{w v^T} = NN (Cross-covariance, assumed zero)

Assumption:

G = RN.

Kalman Gain (K) minimizes the state estimation error:

x_e[n+1] = A x_e[n] + B u[n] + K(y[n] - C x_e[n] - D u[n])

Returns:

Kalman Gain matrix.

Return type:

K (np.ndarray)

get_dims#

do_dpc.control_utils.lti_systems.LTISimulator.get_dims(self)#

Returns the dimensions of the LTI system.

Returns:

  • n (int): Number of state variables.

  • m (int): Number of control inputs.

  • p (int): Number of system outputs.

Return type:

tuple

get_output#

do_dpc.control_utils.lti_systems.LTISimulator.get_output(self, u=None)#

Computes the current system output with measurement noise.

Parameters:

u (Optional[np.ndarray]) – Control input vector.

Returns:

Current system output vector.

Return type:

np.ndarray

get_output_without_noise#

do_dpc.control_utils.lti_systems.LTISimulator.get_output_without_noise(self, u=None)#

Returns the current output of the system without measurement noise.

Parameters:

u (np.ndarray, optional) – The control input vector (shape (m,)).

Returns:

The current output vector (shape (p,)).

Return type:

np.ndarray

get_state#

do_dpc.control_utils.lti_systems.LTISimulator.get_state(self)#

Returns the current state of the system.

Returns:

Current state vector.

Return type:

np.ndarray

reset_x_to_x_0#

do_dpc.control_utils.lti_systems.LTISimulator.reset_x_to_x_0(self)#

Resets to the initial state for the system.

set_initial_x_0#

do_dpc.control_utils.lti_systems.LTISimulator.set_initial_x_0(self, x_0)#

Sets a new initial state for the system.

Parameters:

x_0 (np.ndarray) – The new initial state vector.

Raises:

ValueError – If the shape of x_0 does not match the system state dimension.

step#

do_dpc.control_utils.lti_systems.LTISimulator.step(self, u)#

Advances the LTI system by one-step given a control input.

Parameters:

u (np.ndarray) – Control input vector (shape (m,)).

Returns:

The system output y (shape (p,)).

Return type:

np.ndarray

Raises:

ValueError – If u does not match the expected input shape (m,).