Struct comfy_wgpu::Pid
pub struct Pid<T>where
T: FloatCore,{
pub setpoint: T,
pub output_limit: T,
pub kp: T,
pub ki: T,
pub kd: T,
pub p_limit: T,
pub i_limit: T,
pub d_limit: T,
/* private fields */
}Expand description
Adjustable proportional-integral-derivative (PID) controller.
Examples
This controller provides a builder pattern interface which allows you to pick-and-choose which PID inputs you’d like to use during operation. Here’s what a basic proportional-only controller could look like:
use pid::Pid;
// Create limited controller
let mut p_controller = Pid::new(15.0, 100.0);
p_controller.p(10.0, 100.0);
// Get first output
let p_output = p_controller.next_control_output(400.0);This controller would give you set a proportional controller to 10.0 with a target of 15.0 and an output limit of 100.0 per output iteration. The same controller with a full PID system built in looks like:
use pid::Pid;
// Create full PID controller
let mut full_controller = Pid::new(15.0, 100.0);
full_controller.p(10.0, 100.0).i(4.5, 100.0).d(0.25, 100.0);
// Get first output
let full_output = full_controller.next_control_output(400.0);This next_control_output method is what’s used to input new values into the controller to tell it what the current state of the system is. In the examples above it’s only being used once, but realistically this will be a hot method. Please see [ControlOutput] for examples of how to handle these outputs; it’s quite straight forward and mirrors the values of this structure in some ways.
The last item of note is that these p, i, and d methods can be used during operation which lets you add and/or modify these controller values if need be.
Fields§
§setpoint: TIdeal setpoint to strive for.
output_limit: TDefines the overall output filter limit.
kp: TProportional gain.
ki: TIntegral gain.
kd: TDerivative gain.
p_limit: TLimiter for the proportional term: -p_limit <= P <= p_limit.
i_limit: TLimiter for the integral term: -i_limit <= I <= i_limit.
d_limit: TLimiter for the derivative term: -d_limit <= D <= d_limit.
Implementations§
§impl<T> Pid<T>where
T: FloatCore,
impl<T> Pid<T>where T: FloatCore,
pub fn p(&mut self, gain: impl Into<T>, limit: impl Into<T>) -> &mut Pid<T>
pub fn p(&mut self, gain: impl Into<T>, limit: impl Into<T>) -> &mut Pid<T>
Sets the Self::p term for this controller.
pub fn i(&mut self, gain: impl Into<T>, limit: impl Into<T>) -> &mut Pid<T>
pub fn i(&mut self, gain: impl Into<T>, limit: impl Into<T>) -> &mut Pid<T>
Sets the Self::i term for this controller.
pub fn d(&mut self, gain: impl Into<T>, limit: impl Into<T>) -> &mut Pid<T>
pub fn d(&mut self, gain: impl Into<T>, limit: impl Into<T>) -> &mut Pid<T>
Sets the Self::d term for this controller.
pub fn setpoint(&mut self, setpoint: impl Into<T>) -> &mut Pid<T>
pub fn setpoint(&mut self, setpoint: impl Into<T>) -> &mut Pid<T>
Sets the Pid::setpoint to target for this controller.
pub fn next_control_output(&mut self, measurement: T) -> ControlOutput<T>
pub fn next_control_output(&mut self, measurement: T) -> ControlOutput<T>
Given a new measurement, calculates the next control output.
Panics
- If a setpoint has not been set via
update_setpoint().
pub fn reset_integral_term(&mut self)
pub fn reset_integral_term(&mut self)
Resets the integral term back to zero, this may drastically change the control output.
Trait Implementations§
§impl<T> Ord for Pid<T>where
T: Ord + FloatCore,
impl<T> Ord for Pid<T>where T: Ord + FloatCore,
§impl<T> PartialOrd<Pid<T>> for Pid<T>where
T: PartialOrd<T> + FloatCore,
impl<T> PartialOrd<Pid<T>> for Pid<T>where T: PartialOrd<T> + FloatCore,
§fn partial_cmp(&self, other: &Pid<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Pid<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl<T> Copy for Pid<T>where T: Copy + FloatCore,
impl<T> Eq for Pid<T>where T: Eq + FloatCore,
impl<T> StructuralEq for Pid<T>where T: FloatCore,
impl<T> StructuralPartialEq for Pid<T>where T: FloatCore,
Auto Trait Implementations§
impl<T> RefUnwindSafe for Pid<T>where T: RefUnwindSafe,
impl<T> Send for Pid<T>where T: Send,
impl<T> Sync for Pid<T>where T: Sync,
impl<T> Unpin for Pid<T>where T: Unpin,
impl<T> UnwindSafe for Pid<T>where T: UnwindSafe,
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.