DiscreteStateSpaceModel

Struct DiscreteStateSpaceModel 

Source
pub struct DiscreteStateSpaceModel { /* private fields */ }
Expand description

A struct representing a discrete state-space model.

This model is defined by the following matrices:

  • mat_a: The state transition matrix.
  • mat_b: The control input matrix.
  • mat_c: The output matrix.
  • mat_d: The feedthrough (or direct transmission) matrix.

Additionally, the model includes a sampling time sampling_dt which represents the time interval between each discrete step.

§Fields

  • mat_a (na::DMatrix<f64>): The state transition matrix.
  • mat_b (na::DMatrix<f64>): The control input matrix.
  • mat_c (na::DMatrix<f64>): The output matrix.
  • mat_d (na::DMatrix<f64>): The feedthrough matrix.
  • sampling_dt (f64): The sampling time interval.

Implementations§

Source§

impl DiscreteStateSpaceModel

Source

pub fn from_matrices( mat_a: &DMatrix<f64>, mat_b: &DMatrix<f64>, mat_c: &DMatrix<f64>, mat_d: &DMatrix<f64>, sampling_dt: f64, ) -> DiscreteStateSpaceModel

Creates a new DiscreteStateSpaceModel with the given state-space matrices and sampling time.

§Arguments
  • mat_a - State transition matrix.
  • mat_b - Control input matrix.
  • mat_c - Observation matrix.
  • mat_d - Feedforward matrix.
  • sampling_dt - Sampling time interval.
§Returns

A new DiscreteStateSpaceModel instance.

Examples found in repository?
examples/controllability.rs (lines 7-15)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let ss_model = model::DiscreteStateSpaceModel::from_matrices(
8        &nalgebra::dmatrix![1.0, -2.0; 
9                            2.0, 1.0],
10        &nalgebra::dmatrix![1.0;
11                            2.0],
12        &nalgebra::dmatrix![],
13        &nalgebra::dmatrix![],
14        0.05,
15    );
16
17    let (is_controllable, controllability_matrix) = analysis::is_ss_controllable(&ss_model);
18
19    if is_controllable {
20        println!("The system is controllable");
21        println!("Its controllability matrix is: {}", controllability_matrix);
22    }
23
24    Ok(())
25}
Source

pub fn from_continuous_matrix_forward_euler( mat_ac: &DMatrix<f64>, mat_bc: &DMatrix<f64>, mat_cc: &DMatrix<f64>, mat_dc: &DMatrix<f64>, sampling_dt: f64, ) -> DiscreteStateSpaceModel

Converts a continuous state-space model to a discrete state-space model using the forward Euler method.

§Arguments
  • mat_ac - Continuous state transition matrix.
  • mat_bc - Continuous control input matrix.
  • mat_cc - Continuous observation matrix.
  • mat_dc - Continuous feedforward matrix.
  • sampling_dt - Sampling time interval.
§Returns

A new DiscreteStateSpaceModel instance.

Examples found in repository?
examples/step_response.rs (lines 55-61)
42    pub fn build_model(params: Parameters, sampling_dt: f64) -> DiscreteStateSpaceModel {
43        // Define the continuous-time system matrices
44        let mat_ac = na::dmatrix![
45            0.0, 1.0, 0.0, 0.0;
46            -(params.k1 + params.k2) / params.m1, -(params.d1 + params.d2) / params.m1, params.k2 / params.m1, params.d2 / params.m1;
47            0.0, 0.0, 0.0, 1.0;
48            params.k2 / params.m2, params.d2 / params.m2, -params.k2 / params.m2, -params.d2 / params.m2
49        ];
50        let mat_bc = na::dmatrix![0.0; 0.0; 0.0; 1.0 / params.m2];
51        let mat_cc = na::dmatrix![1.0, 0.0, 0.0, 0.0];
52        let mat_dc = na::dmatrix![0.0];
53
54        // Model discretization
55        DiscreteStateSpaceModel::from_continuous_matrix_forward_euler(
56            &mat_ac,
57            &mat_bc,
58            &mat_cc,
59            &mat_dc,
60            sampling_dt,
61        )
62    }
63}
64
65pub mod dc_motor {
66    use control_sys::model::DiscreteStateSpaceModel;
67    use std::default::Default;
68
69    pub struct Parameters {
70        b: f64,
71        j: f64,
72        k: f64,
73        l: f64,
74        r: f64,
75    }
76
77    impl Default for Parameters {
78        fn default() -> Parameters {
79            Parameters {
80                b: 0.1,
81                j: 0.01,
82                k: 0.01,
83                l: 0.5,
84                r: 1.0,
85            }
86        }
87    }
88
89    pub fn build_model(params: Parameters, sampling_dt: f64) -> DiscreteStateSpaceModel {
90        // Define the continuous-time system matrices
91        let mat_ac = na::dmatrix![
92            -params.b / params.j, params.k / params.j;
93            -params.k / params.l, -params.r / params.l;
94        ];
95        let mat_bc = na::dmatrix![0.0; 1.0 / params.l];
96        let mat_cc = na::dmatrix![1.0, 0.0];
97
98        // Model discretization
99        DiscreteStateSpaceModel::from_continuous_matrix_forward_euler(
100            &mat_ac,
101            &mat_bc,
102            &mat_cc,
103            &na::dmatrix![0.0],
104            sampling_dt,
105        )
106    }
Source

pub fn from_continuous_ss_forward_euler( model: &ContinuousStateSpaceModel, sampling_dt: f64, ) -> DiscreteStateSpaceModel

Converts a continuous state-space model to a discrete state-space model using the forward Euler method.

§Arguments
  • model - A reference to a ContinuousStateSpaceModel instance.
  • sampling_dt - Sampling time interval.
§Returns

A new DiscreteStateSpaceModel instance.

Trait Implementations§

Source§

impl Clone for DiscreteStateSpaceModel

Source§

fn clone(&self) -> DiscreteStateSpaceModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DiscreteStateSpaceModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Discrete for DiscreteStateSpaceModel

Source§

fn sampling_dt(&self) -> f64

Returns the sampling time interval (dt) of the discrete system.
Source§

impl Pole for DiscreteStateSpaceModel

Source§

fn poles(&self) -> Vec<Complex<f64>>

Returnes a vector of complex numbers representing the poles of the system.
Source§

impl StateSpaceModel for DiscreteStateSpaceModel

Source§

fn mat_a(&self) -> &DMatrix<f64>

Returns a reference to the state matrix A.
Source§

fn mat_b(&self) -> &DMatrix<f64>

Returns a reference to the input matrix B.
Source§

fn mat_c(&self) -> &DMatrix<f64>

Returns a reference to the output matrix C.
Source§

fn mat_d(&self) -> &DMatrix<f64>

Returns a reference to the feedthrough matrix D.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.