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
impl DiscreteStateSpaceModel
Sourcepub fn from_matrices(
mat_a: &DMatrix<f64>,
mat_b: &DMatrix<f64>,
mat_c: &DMatrix<f64>,
mat_d: &DMatrix<f64>,
sampling_dt: f64,
) -> DiscreteStateSpaceModel
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}Sourcepub 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
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 }Sourcepub fn from_continuous_ss_forward_euler(
model: &ContinuousStateSpaceModel,
sampling_dt: f64,
) -> DiscreteStateSpaceModel
pub fn from_continuous_ss_forward_euler( model: &ContinuousStateSpaceModel, sampling_dt: f64, ) -> DiscreteStateSpaceModel
Trait Implementations§
Source§impl Clone for DiscreteStateSpaceModel
impl Clone for DiscreteStateSpaceModel
Source§fn clone(&self) -> DiscreteStateSpaceModel
fn clone(&self) -> DiscreteStateSpaceModel
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DiscreteStateSpaceModel
impl Debug for DiscreteStateSpaceModel
Source§impl Discrete for DiscreteStateSpaceModel
impl Discrete for DiscreteStateSpaceModel
Source§fn sampling_dt(&self) -> f64
fn sampling_dt(&self) -> f64
Returns the sampling time interval (
dt) of the discrete system.Source§impl Pole for DiscreteStateSpaceModel
impl Pole for DiscreteStateSpaceModel
Auto Trait Implementations§
impl Freeze for DiscreteStateSpaceModel
impl RefUnwindSafe for DiscreteStateSpaceModel
impl Send for DiscreteStateSpaceModel
impl Sync for DiscreteStateSpaceModel
impl Unpin for DiscreteStateSpaceModel
impl UnwindSafe for DiscreteStateSpaceModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.