control-sys, a control system library written in Rust
control-sys is a control system library written in Rust. It implements tools to represent and analyze LTI systems using state-space model.
Examples
Continuous state space model
A continuous state space model can be defined with ContinuousStateSpaceModel. As an example, a state-space model representing a DC motor can be defined this way. We are using nalgebra to represent the matrices:
use nalgebra as na;
use model;
// DC motor parameters
let b = 0.1f64;
let j = 0.01f64;
let k = 0.01f64;
let l = 0.5f64;
let r = 1.0f64;
let mat_ac = dmatrix!;
let mat_bc = dmatrix!;
let mat_cc = dmatrix!;
let cont_model = from_matrices;
Continuous to discrete model conversion
A DiscreteStateSpaceModel can be built from a continuous one. You then need to specify the sampling step ts:
use nalgebra as na;
use model;
// DC motor parameters
let b = 0.1f64;
let j = 0.01f64;
let k = 0.01f64;
let l = 0.5f64;
let r = 1.0f64;
let mat_ac = dmatrix!;
let mat_bc = dmatrix!;
let mat_cc = dmatrix!;
let cont_model = from_matrices;
let discrete_model =
from_continuous_ss_forward_euler;
Step response
You can compute the step response of a system. For a discrete system, the simulation steps are given by the sampling step of the discretization:
use nalgebra as na;
use ;
// DC motor parameters
let b = 0.1f64;
let j = 0.01f64;
let k = 0.01f64;
let l = 0.5f64;
let r = 1.0f64;
let mat_ac = dmatrix!;
let mat_bc = dmatrix!;
let mat_cc = dmatrix!;
let cont_model = from_matrices;
let discrete_model =
from_continuous_ss_forward_euler;
// where model implements the traits `StateSpaceModel` and `Discrete`
let duration = 10.0; // [s]
let = step_for_discrete_ss;
You can also compute the step response for a continuous model. You will need to provide the sampling step and the model will be discretized before computing the step response:
use nalgebra as na;
use ;
// DC motor parameters
let b = 0.1f64;
let j = 0.01f64;
let k = 0.01f64;
let l = 0.5f64;
let r = 1.0f64;
let mat_ac = dmatrix!;
let mat_bc = dmatrix!;
let mat_cc = dmatrix!;
let cont_model = from_matrices;
// where model is a continuous state space model
let sampling_dt = 0.05; // [s]
let duration = 10.0; // [s]
let = step_for_continuous_ss;
Controllability
The controllability of a system can be evaluated using the is_ss_controllable method:
use nalgebra as na;
use ;
let ss_model = from_matrices;
let = is_ss_controllable;
if is_controllable