Skip to main content

TwoLinkArm

Struct TwoLinkArm 

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

A planar two-link arm: the textbook arm with a closed-form inverse.

Two links of fixed length in a plane, with a shoulder and an elbow joint. tip is forward kinematics; joints_for is the analytic inverse, returning the shoulder and elbow angles that place the hand at a target, for the chosen Elbow branch.

§Examples

use pamoja_kit::{Elbow, TwoLinkArm};

let arm = TwoLinkArm::new(1.0, 1.0);
// Place the hand, then recover the joint angles for it.
let (x, y) = arm.tip(0.5, 0.7);
let (q1, q2) = arm.joints_for(x, y, Elbow::Up).unwrap();
assert!((q1 - 0.5).abs() < 1e-4 && (q2 - 0.7).abs() < 1e-4);

// A target beyond the arm's reach has no solution.
assert!(arm.joints_for(5.0, 0.0, Elbow::Up).is_none());

Implementations§

Source§

impl TwoLinkArm

Source

pub fn new(l1: f32, l2: f32) -> Self

Creates an arm from its two link lengths.

§Arguments
  • l1 - the first (shoulder) link length; its magnitude is used.
  • l2 - the second (elbow) link length; its magnitude is used.
§Returns

The arm.

Source

pub fn reach(&self) -> (f32, f32)

Returns the closest and farthest distances the hand can reach from the shoulder.

§Returns

(min, max), where min is |l1 - l2| and max is l1 + l2.

Source

pub fn tip(&self, shoulder: f32, elbow: f32) -> (f32, f32)

Returns the hand position for given joint angles (forward kinematics).

§Arguments
  • shoulder - the first joint angle, in radians from the x axis.
  • elbow - the second joint angle, in radians relative to the first link.
§Returns

The hand (x, y).

Source

pub fn joints_for(&self, x: f32, y: f32, elbow: Elbow) -> Option<(f32, f32)>

Returns the joint angles that place the hand at a target (inverse kinematics).

§Arguments
  • x - the target x coordinate.
  • y - the target y coordinate.
  • elbow - which Elbow branch to solve for.
§Returns

Some((shoulder, elbow)) for a reachable target, or None if the target lies outside the arm’s reach.

Trait Implementations§

Source§

impl Clone for TwoLinkArm

Source§

fn clone(&self) -> TwoLinkArm

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for TwoLinkArm

Source§

impl Debug for TwoLinkArm

Source§

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

Formats the value using the given formatter. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.