2 unstable releases

Uses new Rust 2024

0.1.0 Mar 16, 2025
0.0.1 Mar 16, 2025

#407 in Algorithms

Download history 136/week @ 2025-03-10 90/week @ 2025-03-17

226 downloads per month

MIT license

12MB
145K SLoC

FORTRAN Legacy 137K SLoC // 0.6% comments ReScript 4.5K SLoC Rust 2.5K SLoC // 0.0% comments BASH 22 SLoC // 0.1% comments Bitbake 15 SLoC // 0.6% comments

Control Systems Torbox

Build Status Latest Version codecov

Control Systems Torbox is a rust library for designing, analysing, simulating and implementating linear control systems.

Usage

To use this crate add control-systems-torbox to your Cargo.toml:

[dependencies]
control-systems-torbox = "0.0.1"

Examples

The crate contains a representation for transfer functions:

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

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 = ss2tf(&sys_ss).unwrap();

Both Bodeplot and Nyquistplot is implemented and can be displayed natively:

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(bode(sys_clp, 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(nyquist(sys, 0.1, 100.)));
nyq_plot.show(600, 600, "Nyquist plot demo").unwrap();

Dependencies

~51–89MB
~1.5M SLoC