Skip to main content

DiffDrive

Struct DiffDrive 

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

Converts between a robot’s motion and its two wheel speeds (differential drive).

A differential-drive robot steers by spinning its left and right wheels at different speeds. This converts both ways: wheel_speeds turns a desired forward speed and turn rate into the wheel speeds to command (inverse kinematics), and body_motion turns measured wheel speeds back into the robot’s forward speed and turn rate (forward kinematics). The one parameter is the track: the distance between the wheels.

§Examples

use pamoja_kit::DiffDrive;

let drive = DiffDrive::new(0.5); // wheels 0.5 apart
// Drive straight: both wheels turn at the forward speed.
assert_eq!(drive.wheel_speeds(1.0, 0.0), (1.0, 1.0));
// Spin in place: the wheels turn opposite, each at turn rate times half the track.
assert_eq!(drive.wheel_speeds(0.0, 2.0), (-0.5, 0.5));

Implementations§

Source§

impl DiffDrive

Source

pub fn new(track: f32) -> Self

Creates a model for wheels track apart.

§Arguments
  • track - the distance between the left and right wheels; its magnitude is used.
§Returns

The kinematics model.

Source

pub fn wheel_speeds(&self, linear: f32, angular: f32) -> (f32, f32)

Returns the (left, right) wheel speeds for a desired body motion.

§Arguments
  • linear - the forward speed.
  • angular - the turn rate, positive turning toward the left (counter-clockwise).
§Returns

(left, right), where left = linear - angular * track / 2 and right = linear + angular * track / 2.

Source

pub fn body_motion(&self, left: f32, right: f32) -> (f32, f32)

Returns the body (linear, angular) motion for measured wheel speeds.

§Arguments
  • left - the left wheel speed.
  • right - the right wheel speed.
§Returns

(linear, angular), where linear = (right + left) / 2 and angular = (right - left) / track. Angular is zero when the track is zero.

Trait Implementations§

Source§

impl Clone for DiffDrive

Source§

fn clone(&self) -> DiffDrive

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 DiffDrive

Source§

impl Debug for DiffDrive

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.