Skip to main content

ArmFeedForward

Struct ArmFeedForward 

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

Feedforward controller for arm mechanisms with gravity compensation.

Extends FeedForward with a gravity compensation term that accounts for the arm’s position. This is essential for arms that must hold position against gravity.

§Formula

voltage = ks * sign(v) + kv * v + ka * a + kg * g(angle)

Where g(angle) is a function that returns the gravity effect at the given angle (typically cos(angle) for a simple arm).

§Example

use kernelvex::{ArmFeedForward, QAngle};

let ff = ArmFeedForward::new(0.1, 0.5, 0.01, 0.3);

// Calculate with gravity compensation using cosine
let voltage = ff.calculate(
    QAngle::from_degrees(45.0),
    target_velocity,
    target_acceleration,
    |angle| angle.cos(),
);

Implementations§

Source§

impl ArmFeedForward

Source

pub const fn new(ks: f64, kv: f64, ka: f64, kg: f64) -> Self

Creates a new arm feedforward controller with the given gains.

§Arguments
  • ks - Static friction compensation
  • kv - Velocity feedforward gain
  • ka - Acceleration feedforward gain
  • kg - Gravity compensation gain
Source

pub const fn ks(&self) -> f64

Returns the static friction gain.

Source

pub const fn kv(&self) -> f64

Returns the velocity feedforward gain.

Source

pub const fn ka(&self) -> f64

Returns the acceleration feedforward gain.

Source

pub const fn kg(&self) -> f64

Returns the gravity compensation gain.

Source

pub const fn set_gains(self, ks: f64, kv: f64, ka: f64, kg: f64) -> Self

Sets all gains at once, returning a new instance.

Source

pub const fn set_ks(self, ks: f64) -> Self

Sets the static friction gain, returning a new instance.

Source

pub const fn set_kv(self, kv: f64) -> Self

Sets the velocity gain, returning a new instance.

Source

pub const fn set_ka(self, ka: f64) -> Self

Sets the acceleration gain, returning a new instance.

Source

pub const fn set_kg(self, kg: f64) -> Self

Sets the gravity gain, returning a new instance.

Source

pub fn calculate( &self, angle: QAngle, velocity: f64, acceleration: f64, g: impl Fn(QAngle) -> f64, ) -> f64

Calculates the feedforward voltage with gravity compensation.

§Arguments
  • angle - Current arm angle
  • velocity - Desired velocity
  • acceleration - Desired acceleration
  • g - Gravity function that takes angle and returns gravity effect
§Returns

The feedforward voltage output including gravity compensation.

§Example
// Using cosine for simple arm
let voltage = ff.calculate(angle, vel, acc, |a| a.cos());

// Using custom gravity function
let voltage = ff.calculate(angle, vel, acc, |a| {
    // Custom gravity calculation for 4-bar linkage
    (a + offset).cos() * linkage_factor
});

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.