Skip to main content

NyquistPlotter

Struct NyquistPlotter 

Source
pub struct NyquistPlotter<T, U = Hz> { /* private fields */ }
Expand description

Nyquist plot over [freq_from, freq_to) with step dfreq, all given in U (Hz by default).

Implementations§

Source§

impl<T, U> NyquistPlotter<T, U>
where T: Float + FloatConst + ToPrimitive + 'static, U: FrequencyUnit,

Source

pub fn new(freq_from: T, freq_to: T, dfreq: T) -> Self

data_len = ceil((freq_to - freq_from) / dfreq) points starting at freq_from, in U.

Examples found in repository?
examples/nyquist.rs (line 24)
9fn main() {
10
11    let omega = 300.0;
12
13    let kp = 3.0 * omega * omega;
14    let kd = 3.0 * omega;
15    let ki = omega* omega * omega;
16
17    let iter = 10;
18    for i in 0..=iter {
19        let alpha = 0.8 + 0.4 / iter as f64 * i as f64;
20
21        let mut storage_n = DataStorage::new(format!("./out/nyquist/nyquist_alpha_{:.02}.csv", alpha)).unwrap();
22        let mut storage_b = DataStorage::new(format!("./out/bode/bode_alpha_{:.02}.csv", alpha)).unwrap();
23
24        let plotter_n = NyquistPlotter::<f64>::new(10.0, 2000.0, 0.01);
25        let plotter_b = BodeDiagramPlotter::<f64>::new(0.1, 1000.0, 0.01, true);
26
27        let tf_main = TransferFunction::continuous(&[alpha * kd, alpha * kp, alpha * ki], &[1.0, 0.0]);
28        let tf_pl = TransferFunction::continuous(&[1.0], &[1.0, 0.0, 0.0]);
29        let tf = tf_main * tf_pl;
30        {
31            let responses = plotter_n.plot(&tf);
32            for res in responses {
33                storage_n.add(&res).unwrap();
34            }
35        }
36        {
37            let responses = plotter_b.frequency_response_s(&tf);
38            for res in responses {
39                storage_b.add(&res).unwrap();
40            }
41        }
42
43        storage_n.close().unwrap();
44        storage_b.close().unwrap();
45    }
46
47}
Source

pub fn plot<G: Into<FrequencyTransferFunction<T>>>( &self, g: G, ) -> Vec<FrequencyResponse<T>>

Calculate the vector locus of a frequency transfer function (or anything convertible into one, such as a continuous TransferFunction). omega of each point is in rad/s regardless of U.

Examples found in repository?
examples/nyquist.rs (line 31)
9fn main() {
10
11    let omega = 300.0;
12
13    let kp = 3.0 * omega * omega;
14    let kd = 3.0 * omega;
15    let ki = omega* omega * omega;
16
17    let iter = 10;
18    for i in 0..=iter {
19        let alpha = 0.8 + 0.4 / iter as f64 * i as f64;
20
21        let mut storage_n = DataStorage::new(format!("./out/nyquist/nyquist_alpha_{:.02}.csv", alpha)).unwrap();
22        let mut storage_b = DataStorage::new(format!("./out/bode/bode_alpha_{:.02}.csv", alpha)).unwrap();
23
24        let plotter_n = NyquistPlotter::<f64>::new(10.0, 2000.0, 0.01);
25        let plotter_b = BodeDiagramPlotter::<f64>::new(0.1, 1000.0, 0.01, true);
26
27        let tf_main = TransferFunction::continuous(&[alpha * kd, alpha * kp, alpha * ki], &[1.0, 0.0]);
28        let tf_pl = TransferFunction::continuous(&[1.0], &[1.0, 0.0, 0.0]);
29        let tf = tf_main * tf_pl;
30        {
31            let responses = plotter_n.plot(&tf);
32            for res in responses {
33                storage_n.add(&res).unwrap();
34            }
35        }
36        {
37            let responses = plotter_b.frequency_response_s(&tf);
38            for res in responses {
39                storage_b.add(&res).unwrap();
40            }
41        }
42
43        storage_n.close().unwrap();
44        storage_b.close().unwrap();
45    }
46
47}

Auto Trait Implementations§

§

impl<T, U> Freeze for NyquistPlotter<T, U>
where T: Freeze, PhantomData<U>: Freeze,

§

impl<T, U> RefUnwindSafe for NyquistPlotter<T, U>

§

impl<T, U> Send for NyquistPlotter<T, U>
where T: Send, PhantomData<U>: Send,

§

impl<T, U> Sync for NyquistPlotter<T, U>
where T: Sync, PhantomData<U>: Sync,

§

impl<T, U> Unpin for NyquistPlotter<T, U>
where T: Unpin, PhantomData<U>: Unpin,

§

impl<T, U> UnsafeUnpin for NyquistPlotter<T, U>

§

impl<T, U> UnwindSafe for NyquistPlotter<T, U>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.