Skip to main content

parameterize

Function parameterize 

Source
pub fn parameterize<const N: usize, const MAX_POINTS: usize>(
    waypoints: &[[CuJointPosition; N]],
    params: &CuTimingParams<N>,
    overrides: CuTimingOverrides<'_, N>,
    out: &mut CuTrajectoryPayload<N, MAX_POINTS>,
) -> CuResult<CuTimingStatus>
Expand description

Times a joint-space waypoint path, writing timestamped points into out in place without allocating.

Only fixed-size stack buffers are used; nothing is heap-allocated. out gets CuTrajectoryInterpolation::Cubic: the stored points carry exact positions and velocities (accelerations are stored as zero), and the velocity limits of the polynomial profiles are certified on the cubic Hermite segments.

§Profiles

  • Trapezoidal: each segment duration is the maximum over joints of the trapezoidal (triangular when the displacement is too short to reach full speed) time under the velocity/acceleration limits, so every joint has zero velocity at each waypoint. Requires zero waypoint velocities (any non-zero entry is CuTimingStatus::InvalidInput). A fixed segment duration must be at least the synchronized minimum for that segment (else InvalidInput); the profile is stretched onto it exactly, lowering peak velocity accordingly.
  • SCurve: jerk-limited symmetric 7-segment rest-to-rest S-curve per segment, synchronized across joints. Requires zero waypoint velocities. The segment duration derives from the velocity, acceleration, and jerk limits (infinite jerk reproduces trapezoidal timing); a fixed duration at least the minimum is honored exactly (else InvalidInput).
  • MinimumJerk: quintic minimum-jerk polynomial per segment per joint with zero endpoint accelerations, honoring the specified waypoint velocities. Duration: fixed when given, otherwise derived so zero-via peak velocity (|v| <= 1.875 * distance / duration) and acceleration (|a| <= (10 / sqrt(3)) * distance / duration^2) satisfy the limits; with any non-zero waypoint velocity the derived duration falls back to the trapezoidal minimum. The exact velocity extrema of every segment, waypoint velocities included, are validated against the limits (exceeding is InvalidInput).
  • Cubic: cubic Hermite polynomial per segment per joint honoring the specified waypoint velocities exactly. Duration: fixed when given, otherwise the trapezoidal minimum; the exact velocity extrema of every segment, waypoint velocities included, are validated against the limits (exceeding is InvalidInput).

§Guarantees (all profiles)

The first point is at t = 0 at waypoints[0] with its specified velocity, the last point is exactly at the final waypoint with its specified velocity, times are strictly increasing, and the total duration equals the sum of the segment durations. Points are resampled at params.sample_period. An empty path yields EmptyPath, a single waypoint yields one point (Success), and a full buffer yields CapacityExceeded.

§Example

use repose_kinematics::CuJointAcceleration;
use repose_kinematics::CuJointPosition;
use repose_kinematics::CuJointVelocity;
use repose_trajectory::CuJointTrajectoryLimits;
use repose_trajectory::CuTimingOverrides;
use repose_trajectory::CuTimingParams;
use repose_trajectory::CuTimingStatus;
use repose_trajectory::CuTrajectoryPayload;
use repose_trajectory::parameterize;
use cu29::units::si::angle::radian;
use cu29::units::si::angular_acceleration::radian_per_second_squared;
use cu29::units::si::angular_velocity::radian_per_second;
use cu29::units::si::f64::Angle;
use cu29::units::si::f64::AngularAcceleration;
use cu29::units::si::f64::AngularVelocity;
use cu29::units::si::f64::Time;
use cu29::units::si::time::second;

let waypoints = [
    [CuJointPosition::Revolute(Angle::new::<radian>(0.0))],
    [CuJointPosition::Revolute(Angle::new::<radian>(1.0))],
];
let params = CuTimingParams {
    limits: CuJointTrajectoryLimits::new(
        [CuJointVelocity::Revolute(AngularVelocity::new::<radian_per_second>(0.5))],
        [CuJointAcceleration::Revolute(
            AngularAcceleration::new::<radian_per_second_squared>(1.0),
        )],
    ),
    sample_period: Time::new::<second>(0.02),
    ..Default::default()
};
let mut out = CuTrajectoryPayload::<1, 512>::new();
let status = parameterize(&waypoints, &params, CuTimingOverrides::default(), &mut out).unwrap();
assert_eq!(status, CuTimingStatus::Success);