pub struct Limits { /* private fields */ }Expand description
Bounds a robot’s speed and acceleration so commands stay within what the machine can do safely.
A raw command can be too fast or too sudden: a full-speed setpoint snaps the wheels, a hard
reverse strips traction. Limits caps the planar speed and yaw rate, then eases each toward
the capped target at a bounded acceleration, so motion is smooth and within envelope. The
easing reuses Ramp as its slew-rate limiter, with the step set to accel * dt each update.
§Examples
use pamoja_kit::{Limits, Twist};
// Up to 1 m/s and 2 rad/s, easing on at 0.5 m/s^2 and 4 rad/s^2.
let mut limits = Limits::new(1.0, 2.0, 0.5, 4.0);
// Asking for full speed from rest: the first 0.1 s step is acceleration-limited.
let cmd = limits.apply(Twist::planar(1.0, 0.0), 0.1);
assert!((cmd.vx - 0.05).abs() < 1e-6); // 0.5 m/s^2 * 0.1 sImplementations§
Source§impl Limits
impl Limits
Sourcepub fn new(
max_linear: f32,
max_angular: f32,
max_linear_accel: f32,
max_angular_accel: f32,
) -> Self
pub fn new( max_linear: f32, max_angular: f32, max_linear_accel: f32, max_angular_accel: f32, ) -> Self
Creates limits from the speed and acceleration ceilings.
§Arguments
max_linear- the largest planar speed; its magnitude is used.max_angular- the largest yaw rate; its magnitude is used.max_linear_accel- the largest change in linear speed per second; its magnitude is used.max_angular_accel- the largest change in yaw rate per second; its magnitude is used.
A ceiling that is not a number is taken as zero, so a mistake holds the robot still.
§Returns
Limits starting from rest.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the remembered motion to rest, so the next command eases up from zero.
Sourcepub fn apply(&mut self, desired: Twist, dt: f32) -> Twist
pub fn apply(&mut self, desired: Twist, dt: f32) -> Twist
Bounds a desired command in speed and acceleration and returns the safe command.
§Arguments
desired- the requested body motion. A component that is not a finite number is taken as zero, so a planner that fails eases the robot to a stop.dt- the time since the previous call, setting the acceleration step. One that is not a finite number allows no change this call.
§Returns
The command after capping speed and easing toward it within the acceleration limit.