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
impl WaypointFollower
Sourcepub fn new(
cruise: f32,
arrival_m: f64,
heading_gain: f32,
max_angular: f32,
) -> Self
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.
Sourcepub fn guide(
&self,
here: Coordinate,
heading_deg: f32,
target: Coordinate,
) -> Guidance
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
impl Clone for WaypointFollower
Source§fn clone(&self) -> WaypointFollower
fn clone(&self) -> WaypointFollower
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more