Struct AngularPid

Source
pub struct AngularPid { /* private fields */ }
Expand description

PID controller for use in rotational systems.

This struct operates on the same principles and implementation as Pid, but takes exclusively Angles as input. Unlike Pid, AngularPid is able to recognize when angles wrap. This means a 0° measurement is equivalent to a 360° measurement, for instance.

This is useful for cases where you want the controller to drive the system to its setpoint using the “shortest turn possible”.

Implementations§

Source§

impl AngularPid

Source

pub const fn new( kp: f64, ki: f64, kd: f64, integration_range: Option<Angle>, ) -> Self

Construct a new PID controller from gain constants and an optional integration range.

Source

pub const fn gains(&self) -> (f64, f64, f64)

Get the current PID gains as a tuple (kp, ki, kd).

Source

pub const fn kp(&self) -> f64

Returns the controller’s proportional gain (kp).

Source

pub const fn ki(&self) -> f64

Returns the controller’s integral gain (kp).

Source

pub const fn kd(&self) -> f64

Returns the controller’s derivative gain (kp).

Source

pub const fn integration_range(&self) -> Option<Angle>

Returns the controller’s integration range.

Integration range is the minimum error range required to start integrating error. This is optionally applied to the controller as a mitigation for integral windup.

Source

pub const fn set_gains(&mut self, kp: f64, ki: f64, kd: f64)

Sets the PID gains to provided values.

Source

pub const fn set_kp(&mut self, kp: f64)

Sets the controller’s proportional gain (kp).

Source

pub const fn set_ki(&mut self, ki: f64)

Sets the controller’s integral gain (ki).

Source

pub const fn set_kd(&mut self, kd: f64)

Sets the controller’s derivative gain (kd).

Source

pub const fn set_integration_range(&mut self, range: Option<Angle>)

Sets the controller’s integration range.

Integration range is the minimum error range required to start integrating error. This is optionally applied to the controller as a mitigation for integral windup.

Source

pub const fn set_output_limit(&mut self, range: Option<f64>)

Sets the controller’s output limit.

This sets a maximum range for the controller’s output signal. It will effectively limit how fast the controller is able to drive the system, which may be desirable in some cases (e.g. limiting the maximum speed of a robot’s motion).

Trait Implementations§

Source§

impl Clone for AngularPid

Source§

fn clone(&self) -> AngularPid

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl ControlLoop for AngularPid

Source§

type Input = Angle

The type of input measurements and setpoints that this controller takes.
Source§

type Output = f64

The type of output (control signal) this controller produces.
Source§

fn update(&mut self, measurement: Angle, setpoint: Angle, dt: Duration) -> f64

Updates the control loop with the latest measurement and setpoint for the system, producing a corresponding control signal.
Source§

impl Debug for AngularPid

Source§

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

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

impl PartialEq for AngularPid

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for AngularPid

Source§

impl StructuralPartialEq for AngularPid

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.