pub struct ConstantGetter<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> { /* private fields */ }Expand description
Getter for returning a constant value.
Implementations§
Source§impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> ConstantGetter<T, TG, E>
impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> ConstantGetter<T, TG, E>
Sourcepub const fn new(time_getter: Reference<TG>, value: T) -> Self
pub const fn new(time_getter: Reference<TG>, value: T) -> Self
Constructor for ConstantGetter.
Examples found in repository?
examples/pid.rs (line 38)
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, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> Getter<T, E> for ConstantGetter<T, TG, E>
impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> Getter<T, E> for ConstantGetter<T, TG, E>
Source§impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> Settable<T, E> for ConstantGetter<T, TG, E>
impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> Settable<T, E> for ConstantGetter<T, TG, E>
Source§fn get_settable_data_ref(&self) -> &SettableData<T, E>
fn get_settable_data_ref(&self) -> &SettableData<T, E>
As traits cannot have fields, get functions and separate types are required. All you have to
do is make a field for a corresponding
SettableData, make this return an immutable
reference to it, and make get_settable_data_mut
return a mutable reference to it.Source§fn get_settable_data_mut(&mut self) -> &mut SettableData<T, E>
fn get_settable_data_mut(&mut self) -> &mut SettableData<T, E>
As traits cannot have fields, get functions and separate types are required. All you have to
do is make a field for a corresponding
SettableData, make this return a mutable
reference to it, and make get_settable_data_ref
return an immutable reference to it.Source§fn impl_set(&mut self, value: T) -> NothingOrError<E>
fn impl_set(&mut self, value: T) -> NothingOrError<E>
Set something, not updating the internal
SettableData. Due to current limitations of the
language, you must implement this but call set. Do not call this directly as it will make
get_last_request work incorrectly.Source§fn set(&mut self, value: S) -> NothingOrError<E>
fn set(&mut self, value: S) -> NothingOrError<E>
Set something to a value. For example, this could set a motor to a voltage. You should call
this and not
impl_set.Source§fn follow(&mut self, getter: Reference<dyn Getter<S, E>>)
fn follow(&mut self, getter: Reference<dyn Getter<S, E>>)
Begin following a
Getter of the same type. For this to work, you must have
update_following_data in your Updatable implementation.Source§fn stop_following(&mut self)
fn stop_following(&mut self)
Stop following the
Getter.Source§fn update_following_data(&mut self) -> NothingOrError<E>
fn update_following_data(&mut self) -> NothingOrError<E>
Get a new value from the
Getter we’re following, if there is one, and call
set
accordingly. You must add this to your Updatable implementation if you are following
Getters. This is a current limitation of the Rust language. If specialization is ever
stabilized, this will hopefully be done in a better way.Source§fn get_last_request(&self) -> Option<S>
fn get_last_request(&self) -> Option<S>
Get the argument from the last time
set was called.Source§impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> Updatable<E> for ConstantGetter<T, TG, E>
impl<T: Clone, TG: TimeGetter<E> + ?Sized, E: Copy + Debug> Updatable<E> for ConstantGetter<T, TG, E>
Source§fn update(&mut self) -> NothingOrError<E>
fn update(&mut self) -> NothingOrError<E>
This does not need to be called.
Auto Trait Implementations§
impl<T, TG, E> Freeze for ConstantGetter<T, TG, E>
impl<T, TG, E> !RefUnwindSafe for ConstantGetter<T, TG, E>
impl<T, TG, E> !Send for ConstantGetter<T, TG, E>
impl<T, TG, E> !Sync for ConstantGetter<T, TG, E>
impl<T, TG, E> Unpin for ConstantGetter<T, TG, E>
impl<T, TG, E> !UnwindSafe for ConstantGetter<T, TG, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more