Skip to main content

PidInstanceF32

Struct PidInstanceF32 

Source
pub struct PidInstanceF32 {
    pub a0: f32,
    pub a1: f32,
    pub a2: f32,
    pub state: [f32; 3],
    pub kp: f32,
    pub ki: f32,
    pub kd: f32,
}
Expand description

Instance structure for the floating-point PID Control.

Fields§

§a0: f32§a1: f32§a2: f32§state: [f32; 3]§kp: f32§ki: f32§kd: f32

Implementations§

Source§

impl PidInstanceF32

Source

pub fn new(kp: f32, ki: f32, kd: f32) -> Self

Examples found in repository?
examples/basic_usage.rs (line 36)
5fn main() {
6    println!("=== embedded-dsp Basic Usage Example ===");
7
8    // 1. Vector Operations
9    let a = [1.0f32, 2.0, 3.0, 4.0];
10    let b = [10.0f32, 20.0, 30.0, 40.0];
11    let mut vec_out = [0.0f32; 4];
12    add_f32(&a, &b, &mut vec_out);
13    println!("Vector Add: {:?}", vec_out);
14
15    let dot = dot_prod_f32(&a, &b);
16    println!("Vector Dot Product: {}", dot);
17
18    // 2. Q15 Fixed-Point Saturating Math
19    let q15_a = [20000i16, 25000];
20    let q15_b = [15000i16, 10000];
21    let mut q15_out = [0i16; 2];
22    add_q15(&q15_a, &q15_b, &mut q15_out);
23    println!("Q15 Saturating Add (clamped at 32767): {:?}", q15_out);
24
25    // 3. FIR Filtering
26    let coeffs = [0.25f32, 0.5, 0.25]; // 3-tap moving average filter
27    let mut state = [0.0f32; 3 + 4 - 1];
28    let mut fir = FirInstanceF32::init(3, &coeffs, &mut state);
29
30    let input_signal = [1.0f32, 2.0, 3.0, 4.0];
31    let mut filtered_signal = [0.0f32; 4];
32    fir_f32(&mut fir, &input_signal, &mut filtered_signal);
33    println!("FIR Filter Output: {:?}", filtered_signal);
34
35    // 4. PID Motor Controller
36    let mut pid = PidInstanceF32::new(2.0, 0.1, 0.05);
37    let control_output = pid.process(10.0);
38    println!("PID Control Signal: {}", control_output);
39
40    // 5. 64-Point Complex FFT
41    let mut fft_data = [0.0f32; 128]; // 64 complex pairs [re, im, ...]
42    for i in 0..64 {
43        fft_data[2 * i] = (i as f32 * 0.1).sin();
44    }
45    cfft_f32(&mut fft_data, 64, 0, 1);
46    println!("64-Point Complex FFT processed successfully!");
47}
Source

pub fn init(&mut self, reset_state_flag: i32)

Source

pub fn reset(&mut self)

Source

pub fn process(&mut self, in_val: f32) -> f32

Examples found in repository?
examples/basic_usage.rs (line 37)
5fn main() {
6    println!("=== embedded-dsp Basic Usage Example ===");
7
8    // 1. Vector Operations
9    let a = [1.0f32, 2.0, 3.0, 4.0];
10    let b = [10.0f32, 20.0, 30.0, 40.0];
11    let mut vec_out = [0.0f32; 4];
12    add_f32(&a, &b, &mut vec_out);
13    println!("Vector Add: {:?}", vec_out);
14
15    let dot = dot_prod_f32(&a, &b);
16    println!("Vector Dot Product: {}", dot);
17
18    // 2. Q15 Fixed-Point Saturating Math
19    let q15_a = [20000i16, 25000];
20    let q15_b = [15000i16, 10000];
21    let mut q15_out = [0i16; 2];
22    add_q15(&q15_a, &q15_b, &mut q15_out);
23    println!("Q15 Saturating Add (clamped at 32767): {:?}", q15_out);
24
25    // 3. FIR Filtering
26    let coeffs = [0.25f32, 0.5, 0.25]; // 3-tap moving average filter
27    let mut state = [0.0f32; 3 + 4 - 1];
28    let mut fir = FirInstanceF32::init(3, &coeffs, &mut state);
29
30    let input_signal = [1.0f32, 2.0, 3.0, 4.0];
31    let mut filtered_signal = [0.0f32; 4];
32    fir_f32(&mut fir, &input_signal, &mut filtered_signal);
33    println!("FIR Filter Output: {:?}", filtered_signal);
34
35    // 4. PID Motor Controller
36    let mut pid = PidInstanceF32::new(2.0, 0.1, 0.05);
37    let control_output = pid.process(10.0);
38    println!("PID Control Signal: {}", control_output);
39
40    // 5. 64-Point Complex FFT
41    let mut fft_data = [0.0f32; 128]; // 64 complex pairs [re, im, ...]
42    for i in 0..64 {
43        fft_data[2 * i] = (i as f32 * 0.1).sin();
44    }
45    cfft_f32(&mut fft_data, 64, 0, 1);
46    println!("64-Point Complex FFT processed successfully!");
47}

Trait Implementations§

Source§

impl Clone for PidInstanceF32

Source§

fn clone(&self) -> PidInstanceF32

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PidInstanceF32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PidInstanceF32

Source§

fn default() -> PidInstanceF32

Returns the “default value” for a type. Read more
Source§

impl PartialEq for PidInstanceF32

Source§

fn eq(&self, other: &PidInstanceF32) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PidInstanceF32

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.