TimeGetterFromGetter

Struct TimeGetterFromGetter 

Source
pub struct TimeGetterFromGetter<T: Clone, G: Getter<T, E> + ?Sized, E: Copy + Debug> { /* private fields */ }
Expand description

Because Getters always return a timestamp (as long as they don’t return Err(_) or Ok(None)), we can use this to treat them like TimeGetters.

Implementations§

Source§

impl<T: Clone, G: Getter<T, E> + ?Sized, E: Copy + Debug> TimeGetterFromGetter<T, G, E>

Source

pub const fn new(stream: Reference<G>) -> Self

Constructor for TimeGetterFromGetter.

Examples found in repository?
examples/pid.rs (line 37)
30    pub fn new(
31        input: Reference<dyn Getter<Quantity, ()>>,
32        setpoint: Quantity,
33        kp: Quantity,
34        ki: Quantity,
35        kd: Quantity,
36    ) -> Self {
37        let time_getter = rc_ref_cell_reference(TimeGetterFromGetter::new(input.clone()));
38        let setpoint = rc_ref_cell_reference(ConstantGetter::new(time_getter.clone(), setpoint));
39        let kp = rc_ref_cell_reference(ConstantGetter::new(time_getter.clone(), kp));
40        let ki = rc_ref_cell_reference(ConstantGetter::new(time_getter.clone(), ki));
41        let kd = rc_ref_cell_reference(ConstantGetter::new(time_getter.clone(), kd));
42        let error = rc_ref_cell_reference(DifferenceStream::new(setpoint.clone(), input.clone()));
43        let int = rc_ref_cell_reference(IntegralStream::new(error.clone()));
44        let drv = rc_ref_cell_reference(DerivativeStream::new(error.clone()));
45        //`ProductStream`'s behavior is to treat all `None` values as 1.0 so that it's as if they
46        //were not included. However, this is not what we want with the coefficient. `NoneToValue`
47        //is used to convert all `None` values to `Some(0.0)` to effectively exlude them from the
48        //final sum.
49        let int_zeroer = rc_ref_cell_reference(NoneToValue::new(
50            int.clone(),
51            time_getter.clone(),
52            Quantity::new(0.0, MILLIMETER),
53        ));
54        let drv_zeroer = rc_ref_cell_reference(NoneToValue::new(
55            drv.clone(),
56            time_getter.clone(),
57            Quantity::new(0.0, MILLIMETER),
58        ));
59        let kp_mul = rc_ref_cell_reference(ProductStream::new([
60            to_dyn!(Getter<Quantity, ()>, kp.clone()),
61            to_dyn!(Getter<Quantity, ()>, error.clone()),
62        ]));
63        //The way a PID controller works necessitates that it adds quantities of different units.
64        //Thus, QuantityToFloat streams are required to keep the dimensional analysis system from
65        //stopping this.
66        let pro_float_maker = rc_ref_cell_reference(QuantityToFloat::new(kp_mul));
67        let ki_mul = rc_ref_cell_reference(ProductStream::new([
68            to_dyn!(Getter<Quantity, ()>, ki.clone()),
69            to_dyn!(Getter<Quantity, ()>, int_zeroer.clone()),
70        ]));
71        let int_float_maker = rc_ref_cell_reference(QuantityToFloat::new(ki_mul));
72        let kd_mul = rc_ref_cell_reference(ProductStream::new([
73            to_dyn!(Getter<Quantity, ()>, kd.clone()),
74            to_dyn!(Getter<Quantity, ()>, drv_zeroer.clone()),
75        ]));
76        let drv_float_maker = rc_ref_cell_reference(QuantityToFloat::new(kd_mul));
77        let output = SumStream::new([
78            to_dyn!(Getter<f32, ()>, pro_float_maker.clone()),
79            to_dyn!(Getter<f32, ()>, int_float_maker.clone()),
80            to_dyn!(Getter<f32, ()>, drv_float_maker.clone()),
81        ]);
82        Self {
83            int: to_dyn!(Getter<Quantity, ()>, int),
84            drv: to_dyn!(Getter<Quantity, ()>, drv),
85            pro_float_maker: to_dyn!(Getter<f32, ()>, pro_float_maker),
86            int_float_maker: to_dyn!(Getter<f32, ()>, int_float_maker),
87            drv_float_maker: to_dyn!(Getter<f32, ()>, drv_float_maker),
88            output: output,
89        }
90    }

Trait Implementations§

Source§

impl<T: Clone, G: Getter<T, E> + ?Sized, E: Copy + Debug> TimeGetter<E> for TimeGetterFromGetter<T, G, E>

Source§

fn get(&self) -> TimeOutput<E>

Get the time.
Source§

impl<T: Clone, G: Getter<T, E> + ?Sized, E: Copy + Debug> Updatable<E> for TimeGetterFromGetter<T, G, E>

Source§

fn update(&mut self) -> NothingOrError<E>

As this trait is very generic, exactly what this does will be very dependent on the implementor.

Auto Trait Implementations§

§

impl<T, G, E> Freeze for TimeGetterFromGetter<T, G, E>
where G: ?Sized,

§

impl<T, G, E> !RefUnwindSafe for TimeGetterFromGetter<T, G, E>

§

impl<T, G, E> !Send for TimeGetterFromGetter<T, G, E>

§

impl<T, G, E> !Sync for TimeGetterFromGetter<T, G, E>

§

impl<T, G, E> Unpin for TimeGetterFromGetter<T, G, E>
where T: Unpin, E: Unpin, G: ?Sized,

§

impl<T, G, E> !UnwindSafe for TimeGetterFromGetter<T, G, E>

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, 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.