util
Public functions and their Rust signatures.
slew
pub fn slew(target: f32, current: f32, max_change: f32) -> f32Slew rate limiter.
target— target valuecurrent— current valuemax_change— maximum change. No maximum if set to 0
Returns the limited value.
assert_eq!(slew(100.0, 0.0, 10.0), 10.0);
assert_eq!(slew(100.0, 0.0, 0.0), 100.0);Parameters
Prop
Type
Returns
f32rad_to_deg
pub fn rad_to_deg(rad: f32) -> f32Convert radians to degrees (rad * 180 / M_PI).
Parameters
Prop
Type
Returns
f32deg_to_rad
pub fn deg_to_rad(deg: f32) -> f32Convert degrees to radians (deg * M_PI / 180).
Parameters
Prop
Type
Returns
f32sanitize_angle
pub fn sanitize_angle(angle: f32, radians: bool) -> f32Bound an angle to [0, 2π) (radians) or [0, 360) (degrees).
Parameters
Prop
Type
Returns
f32angle_error
pub fn angle_error(target: f32, position: f32, radians: bool, direction: AngularDirection) -> f32Calculate the error between two angles. Useful when calculating the error between target and actual heading.
target— target angleposition— position angleradians—trueif angles are in radians (LemLib's default),falsefor degreesdirection— which direction to turn;AngularDirection::Autopicks the shortest path
assert_eq!(angle_error(10.0, 350.0, false, AngularDirection::Auto), 20.0);
assert_eq!(angle_error(350.0, 10.0, false, AngularDirection::CwClockwise), 340.0);Parameters
Prop
Type
Returns
f32sgn
pub fn sgn<T: Signum>(value: T) -> TReturn the sign of a number: -1 if negative, 1 otherwise (including 0 and NaN).
This is LemLib's sgn, which is not f32::signum: sgn(0.0) == 1.0 and sgn(-0.0) == 1.0.
Parameters
Prop
Type
Returns
Tavg
pub fn avg(values: &[f32]) -> f32Return the average of a slice of numbers. An empty slice gives NaN, as in LemLib.
Parameters
Prop
Type
Returns
f32ema
pub fn ema(current: f32, previous: f32, smooth: f32) -> f32Exponential moving average.
current— current measurementprevious— previous outputsmooth— smoothing factor (0–1). 1 means no smoothing, 0 means no change.
Parameters
Prop
Type
Returns
f32get_curvature
pub fn get_curvature(pose: Pose, other: Pose) -> f32Get the signed curvature of a circle that intersects the first pose and the second pose.
The circle is also tangent to the theta of the first pose (in radians, standard position). The sign follows LemLib's formula: a point to the left of the heading gives a negative curvature, a point to the right a positive one.
Parameters
Prop
Type
Returns
f32