pub struct PidController {
pub pd: PdController,
pub lin_integral: Vector<f32>,
pub ang_integral: AngVector<f32>,
pub lin_ki: Vector<f32>,
pub ang_ki: AngVector<f32>,
}
Expand description
A Proportional-Integral-Derivative (PID) controller.
For video games, the Proportional-Derivative PdController
is generally sufficient and
offers an immutable API.
Fields§
§pd: PdController
The Proportional-Derivative (PD) part of this PID controller.
lin_integral: Vector<f32>
The translational error accumulated through time for the Integral part of the PID controller.
ang_integral: AngVector<f32>
The angular error accumulated through time for the Integral part of the PID controller.
lin_ki: Vector<f32>
The linear gain applied to the Integral part of the PID controller.
ang_ki: AngVector<f32>
The angular gain applied to the Integral part of the PID controller.
Implementations§
Source§impl PidController
impl PidController
Sourcepub fn new(kp: f32, ki: f32, kd: f32, axes: AxesMask) -> PidController
pub fn new(kp: f32, ki: f32, kd: f32, axes: AxesMask) -> PidController
Initialized the PDI controller with uniform gain.
The same gain are applied on all axes. To configure per-axes gains, construct
the PidController
by setting its fields explicitly instead.
Only the axes specified in axes
will be enabled (but the gain values are set
on all axes regardless).
Sourcepub fn set_axes(&mut self, axes: AxesMask)
pub fn set_axes(&mut self, axes: AxesMask)
Set the axes errors and corrections are computed for.
This doesn’t modify any of the gains.
Sourcepub fn reset_integrals(&mut self)
pub fn reset_integrals(&mut self)
Resets to zero the accumulated linear and angular errors used by the Integral part of the controller.
Sourcepub fn linear_rigid_body_correction(
&mut self,
dt: f32,
rb: &RigidBody,
target_pos: Point<f32>,
target_linvel: Vector<f32>,
) -> Vector<f32>
pub fn linear_rigid_body_correction( &mut self, dt: f32, rb: &RigidBody, target_pos: Point<f32>, target_linvel: Vector<f32>, ) -> Vector<f32>
Calculates the linear correction from positional and velocity errors calculated automatically from a rigid-body and the desired positions/velocities.
The unit of the returned value depends on the gain values. In general, kd
is proportional to
the inverse of the simulation step so the returned value is a linear rigid-body velocity
change.
This method is mutable because of the need to update the accumulated positional
errors for the Integral part of this controller. Prefer the PdController
instead if
an immutable API is needed.
Sourcepub fn angular_rigid_body_correction(
&mut self,
dt: f32,
rb: &RigidBody,
target_rot: Rotation<f32>,
target_angvel: AngVector<f32>,
) -> AngVector<f32>
pub fn angular_rigid_body_correction( &mut self, dt: f32, rb: &RigidBody, target_rot: Rotation<f32>, target_angvel: AngVector<f32>, ) -> AngVector<f32>
Calculates the angular correction from positional and velocity errors calculated automatically from a rigid-body and the desired positions/velocities.
The unit of the returned value depends on the gain values. In general, kd
is proportional to
the inverse of the simulation step so the returned value is an angular rigid-body velocity
change.
This method is mutable because of the need to update the accumulated positional
errors for the Integral part of this controller. Prefer the PdController
instead if
an immutable API is needed.
Sourcepub fn rigid_body_correction(
&mut self,
dt: f32,
rb: &RigidBody,
target_pose: Isometry<f32>,
target_vels: RigidBodyVelocity,
) -> RigidBodyVelocity
pub fn rigid_body_correction( &mut self, dt: f32, rb: &RigidBody, target_pose: Isometry<f32>, target_vels: RigidBodyVelocity, ) -> RigidBodyVelocity
Calculates the linear and angular correction from positional and velocity errors calculated automatically from a rigid-body and the desired poses/velocities.
The unit of the returned value depends on the gain values. In general, kd
is proportional to
the inverse of the simulation step so the returned value is a rigid-body velocity
change.
This method is mutable because of the need to update the accumulated positional
errors for the Integral part of this controller. Prefer the PdController
instead if
an immutable API is needed.
Sourcepub fn correction(
&mut self,
dt: f32,
pose_errors: &PdErrors,
vel_errors: &PdErrors,
) -> RigidBodyVelocity
pub fn correction( &mut self, dt: f32, pose_errors: &PdErrors, vel_errors: &PdErrors, ) -> RigidBodyVelocity
Calculates the linear and angular correction from the given positional and velocity errors.
The unit of the returned value depends on the gain values. In general, kd
is proportional to
the inverse of the simulation step so the returned value is a rigid-body velocity
change.
This method is mutable because of the need to update the accumulated positional
errors for the Integral part of this controller. Prefer the PdController
instead if
an immutable API is needed.
Trait Implementations§
Source§impl Clone for PidController
impl Clone for PidController
Source§fn clone(&self) -> PidController
fn clone(&self) -> PidController
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PidController
impl Debug for PidController
Source§impl Default for PidController
impl Default for PidController
Source§impl PartialEq for PidController
impl PartialEq for PidController
impl Copy for PidController
impl StructuralPartialEq for PidController
Auto Trait Implementations§
impl Freeze for PidController
impl RefUnwindSafe for PidController
impl Send for PidController
impl Sync for PidController
impl Unpin for PidController
impl UnwindSafe for PidController
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.