Skip to main content

WaypointFollower

Struct WaypointFollower 

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

Guides a robot from waypoint to waypoint by GPS-style coordinates (carrot following).

This is the “go to that point” primitive behind a patrol route, a return-to-base, or a field pass: given where the robot is, which way it faces, and the next waypoint, it produces the twist to get there. It turns toward the target in proportion to the heading error and slows the forward speed as that error grows (by the cosine of the error), so the robot pivots toward a target behind it before driving off, rather than swinging wide. The caller holds the list of waypoints and advances to the next once Guidance::arrived is set, which keeps this allocation-free.

§Examples

use pamoja_kit::{Coordinate, WaypointFollower};

// Cruise 1.5 m/s, arrive within 3 m, turn at 1.5 rad per rad of error, cap 1 rad/s.
let follower = WaypointFollower::new(1.5, 3.0, 1.5, 1.0);

// At the equator/prime meridian facing east (90 deg), with the target due east.
let here = Coordinate::new(0.0, 0.0);
let target = Coordinate::new(0.0, 0.01);
let g = follower.guide(here, 90.0, target);
assert!(g.heading_error_deg.abs() < 1e-3); // already pointed at it
assert!((g.twist.vx - 1.5).abs() < 1e-3); // so drive at cruise
assert!(!g.arrived);

Implementations§

Source§

impl WaypointFollower

Source

pub fn new( cruise: f32, arrival_m: f64, heading_gain: f32, max_angular: f32, ) -> Self

Creates a follower with the given speeds and tolerances.

§Arguments
  • cruise - the forward speed when pointed at the target; its magnitude is used.
  • arrival_m - how close, in metres, counts as arrived; its magnitude is used.
  • heading_gain - yaw rate commanded per radian of heading error; its magnitude is used.
  • max_angular - the largest yaw rate to command; its magnitude is used.
§Returns

The follower.

Source

pub fn guide( &self, here: Coordinate, heading_deg: f32, target: Coordinate, ) -> Guidance

Produces the steering command from the robot’s position and heading to a target.

§Arguments
  • here - the robot’s current coordinate.
  • heading_deg - the robot’s heading in degrees clockwise from north (a compass course).
  • target - the waypoint to head toward.
§Returns

The Guidance; once within the arrival radius the twist is zero and arrived is set.

Trait Implementations§

Source§

impl Clone for WaypointFollower

Source§

fn clone(&self) -> WaypointFollower

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 WaypointFollower

Source§

impl Debug for WaypointFollower

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.