Skip to main content

Mecanum

Struct Mecanum 

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

Mecanum (four-wheel omnidirectional) drive: forward, sideways, and turning at once.

A mecanum base carries four wheels whose angled rollers let it strafe sideways as well as drive and turn, so it tracks a full planar Twist (vx, vy, omega). This uses the standard kinematics for the common “O” roller layout, with k = (half-wheelbase + half-track):

front_left  = vx - vy - k*omega      rear_left  = vx + vy - k*omega
front_right = vx + vy + k*omega      rear_right = vx - vy + k*omega

The forward kinematics invert these by averaging the wheels. Speeds are wheel contact speeds in the body’s units; convert to motor rates by dividing by the wheel radius.

§Examples

use pamoja_kit::{Mecanum, Twist, WheelSpeeds};

// 0.4 m wheelbase, 0.3 m track.
let base = Mecanum::new(0.4, 0.3);

// Pure left strafe: the O-layout spins the diagonals against each other.
let w = base.wheel_speeds(Twist::new(0.0, 1.0, 0.0));
assert_eq!(w, WheelSpeeds { front_left: -1.0, front_right: 1.0, rear_left: 1.0, rear_right: -1.0 });

// Reading the wheels back recovers the body twist.
let t = base.body_motion(w);
assert!(t.vx.abs() < 1e-6 && (t.vy - 1.0).abs() < 1e-6 && t.omega.abs() < 1e-6);

Implementations§

Source§

impl Mecanum

Source

pub fn new(wheelbase: f32, track: f32) -> Self

Creates a model from the wheelbase and track.

§Arguments
  • wheelbase - the front-to-rear distance between axles; its magnitude is used.
  • track - the left-to-right distance between wheels; its magnitude is used.
§Returns

The kinematics model.

Source

pub fn wheel_speeds(&self, twist: Twist) -> WheelSpeeds

Returns the four wheel speeds for a desired body twist.

§Arguments
  • twist - the desired body velocity, using all of vx, vy, and omega.
§Returns

The WheelSpeeds that produce that twist.

Source

pub fn body_motion(&self, wheels: WheelSpeeds) -> Twist

Returns the body twist for measured wheel speeds.

§Arguments
  • wheels - the four measured wheel speeds.
§Returns

The body Twist; omega is zero when the base has no size (lever arm zero).

Trait Implementations§

Source§

impl Clone for Mecanum

Source§

fn clone(&self) -> Mecanum

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 Mecanum

Source§

impl Debug for Mecanum

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 = 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.