1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*!
# Control Systems Torbox
Control Systems Torbox is a Rust library for designing, analyzing, simulating, and implementing linear control systems. This crate provides a comprehensive set of tools for working with transfer functions, state-space representations, frequency response analysis, and plotting.
## Features
- **Transfer Functions**: Create and manipulate transfer functions.
- **State-Space Representations**: Convert between transfer functions and state-space representations.
- **Frequency Response Analysis**: Compute Bode and Nyquist plots.
- **Properties of System**: H2-norm, H-inf-norm, poles, zeros
- **Plotting**: Display Bode and Nyquist plots natively using `egui`.
## Examples
The crate contains a representation for transfer functions:
```rust
use control_systems_torbox::*;
let tf_lp = Tf::<f64, Continuous>::new(&[10.0], &[10.0, 1.0]); // 10/(s + 10)
let sys = 1.0 / Tf::s();
let pi_c = 1.0 + 1.0 / Tf::s();
let openloop = sys * pi_c * tf_lp;
let tracking = openloop.clone() / (1.0 + openloop);
```
State-Space representations is also implemented and you can convert between transfer function and state-space
```rust
use control_systems_torbox::*;
use nalgebra::DMatrix;
let a = DMatrix::from_row_slice(2, 2, &[0., 0., 1., 0.]);
let b = DMatrix::from_row_slice(2, 1, &[1., 0.]);
let c = DMatrix::from_row_slice(1, 2, &[0., 1.]);
let d = DMatrix::from_row_slice(1, 1, &[0.]);
let sys_ss = Ss::<Continuous>::new(a, b, c, d).unwrap();
let sys_tf = sys_ss.to_tf().unwrap();
```
System norms such as H2-norm and H-inf-norm are also possible to calculte
```rust
use control_systems_torbox::*;
let low_pass = 1.0/(Tf::s().powi(2) + 2.0*0.2*Tf::s() + 0.1);
let low_pass = low_pass.to_ss().unwrap();
let h2_norm = low_pass.norm_h2().unwrap();
let hinf_norm = low_pass.norm_hinf().unwrap();
println!("H2 norm is: {}, H-inf norm is: {}", h2_norm, hinf_norm);
```
It is also possible to calculte the poles and zeros of a system
```rust
use control_systems_torbox::*;
let tf = (Tf::s() -1.0)*(Tf::s() + 3.0)/((Tf::s() - 4.0)*(Tf::s() + 5.0));
let ss = tf.to_ss().unwrap();
let poles = ss.poles();
let zeros = ss.zeros().unwrap();
println!("Tf:\n{}", tf);
println!("Poles:");
for pole in poles {
println!("{}", pole);
}
println!("\nZeros:");
for zero in zeros {
println!("{}", zero);
}
```
Both Bodeplot and Nyquistplot is implemented and can be displayed natively:
```rust,no_run
use control_systems_torbox::*;
let sys = (1.0/Tf::s()) * (1.0 + 1.0/Tf::s());
let sys_clp = sys.clone() / (1.0 + sys.clone());
let mut bode_plot = BodePlot::new(BodePlotOptions::default());
bode_plot.add_system(BodePlotData::new(sys_clp.bode(0.1, 10.)));
bode_plot.show(800, 600, "Bode plot demo").unwrap();
let mut nyq_plot = NyquistPlot::new(NyquistPlotOptions::default());
nyq_plot.add_system(NyquistPlotData::new(sys.nyquist(0.1, 100.)));
nyq_plot.show(600, 600, "Nyquist plot demo").unwrap();
```
!*/
pub use FrequencyResponse;
pub use ;
pub use ;
pub use SsRealization;
pub use ;