Skip to main content

Odometry

Struct Odometry 

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

Tracks a robot’s Pose by accumulating its motion over time (odometry).

With no GPS indoors, a robot estimates where it is by adding up where it has been: each small move is integrated onto the running pose. This uses the exact arc model rather than a straight- line step, so a robot that drives and turns at once follows the curve it actually traces instead of cutting the corner; over many steps that is markedly more accurate. Feed it either a body motion (forward speed and yaw rate over a time step) or wheel-distance deltas through a DiffDrive model. Dead reckoning drifts, so correct the heading from an absolute source with fuse_heading when one is available.

§Examples

use pamoja_kit::{Odometry, Pose};

// Drive a quarter circle of radius 1 m: forward 1 m/s, turning left at 1 rad/s, for pi/2 s.
let mut odom = Odometry::at_origin();
let pose = odom.integrate(1.0, 1.0, core::f32::consts::FRAC_PI_2);

// It ends about (1, 1) facing 90 degrees, the far corner of the arc.
assert!((pose.x - 1.0).abs() < 1e-5);
assert!((pose.y - 1.0).abs() < 1e-5);
assert!((pose.theta - core::f32::consts::FRAC_PI_2).abs() < 1e-5);

Implementations§

Source§

impl Odometry

Source

pub fn new(start: Pose) -> Self

Creates an estimator starting from a known pose.

§Arguments
  • start - the initial pose.
§Returns

The estimator.

Source

pub fn at_origin() -> Self

Creates an estimator starting at the origin facing along the x axis.

§Returns

The estimator.

Source

pub fn pose(&self) -> Pose

Returns the current pose estimate.

§Returns

The pose accumulated so far.

Source

pub fn reset(&mut self, pose: Pose)

Resets the estimate to a known pose.

§Arguments
  • pose - the pose to set.
Source

pub fn integrate(&mut self, linear: f32, angular: f32, dt: f32) -> Pose

Integrates a body motion over a time step and returns the new pose.

§Arguments
  • linear - the forward speed.
  • angular - the yaw rate, positive turning left.
  • dt - the length of the time step.
§Returns

The updated pose.

Source

pub fn integrate_wheels( &mut self, left: f32, right: f32, drive: &DiffDrive, ) -> Pose

Integrates wheel-distance deltas through a differential-drive model.

§Arguments
  • left - the distance the left wheel rolled since the last update.
  • right - the distance the right wheel rolled since the last update.
  • drive - the DiffDrive model giving the track between the wheels.
§Returns

The updated pose. The wheel deltas are turned into a forward distance and a heading change by DiffDrive::body_motion, then integrated as one arc.

Source

pub fn fuse_heading(&mut self, measured: f32, weight: f32)

Corrects the heading toward an absolute measurement, the way a compass tames gyro drift.

This is the angular cousin of Complementary: it nudges the estimated heading along the shortest arc toward an absolute reading (an IMU yaw, a magnetometer, a GPS course) by a blend weight, leaving the position untouched.

§Arguments
  • measured - the absolute heading in radians.
  • weight - how strongly to trust the measurement, clamped to [0, 1]; zero keeps the dead-reckoned heading, one snaps to measured.

Trait Implementations§

Source§

impl Clone for Odometry

Source§

fn clone(&self) -> Odometry

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 Odometry

Source§

impl Debug for Odometry

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.