#ifndef INCLUDED_TRANSITION_V3_SPARAM_H #define INCLUDED_TRANSITION_V3_SPARAM_H #include #include "vec2.h" /* * Time-optimal jerk-limited transition for independent X/Y axes. * * The planner treats X and Y as independent 1D axes with identical symmetric * limits for both directions: * |v_axis| <= vmax, |a_axis| <= amax, |j_axis| <= jmax. * * Boundary acceleration is fixed to zero on both axes. Jerk is a bounded * control, not a state; tr_sample() reports j=0 outside the motion interval, * but the time-optimal profile may jump from 0 to +/-jmax at t=0 and jump back * to 0 at t=T. If continuous jerk is required, the problem is snap-limited, * not jerk-limited. * * The transition can be sampled either by time t or by travelled arclength s. * Arclength is computed as * s(t) = integral_0^t hypot(vx(tau), vy(tau)) d tau. * * For fast repeated sampling by s, tr_transition stores an internal monotone * lookup table parameterized by arclength. The dynamic profile is still stored * as time-polynomial axis phases; the s-table only maps s -> t. */ #define TR_S_TABLE_CAP 2049u #define TR_S_PARAM_TABLE_UNIFORM_BY_LENGTH 1 enum tr_status { TR_OK = 0, TR_ERR_INVALID_ARG = -1, TR_ERR_LIMITS = -2, TR_ERR_INFEASIBLE = -3, TR_ERR_NUMERIC = -4, TR_ERR_NO_PROFILE = -5 }; struct tr_axis_phase { double t_begin; double dt; double q0; double v0; double a0; double j; }; struct tr_axis_plan { struct tr_axis_phase phases[16]; uint32_t count; double duration; double q0, q1; double v0, v1; }; struct tr_s_node { double s; double t; }; struct tr_transition { struct tr_axis_plan x; struct tr_axis_plan y; double duration; double length; /* Uniform arclength parameterization: s_nodes[i].s is approximately * i*length/(s_node_count-1), and s_nodes[i].t is the corresponding time. */ uint32_t s_node_count; double s_step; struct tr_s_node s_nodes[TR_S_TABLE_CAP]; double vmax, amax, jmax; }; struct tr_sample { double t; double s; struct vec2 r; struct vec2 v; struct vec2 a; struct vec2 j; }; int tr_build (struct tr_transition *out, struct vec2 r0, struct vec2 r1, struct vec2 v0, struct vec2 v1, double vmax, double amax, double jmax); void tr_sample (const struct tr_transition *tr, double t, struct tr_sample *out); void tr_sample_at_s (const struct tr_transition *tr, double s, struct tr_sample *out); double tr_length_at_time (const struct tr_transition *tr, double t); double tr_time_at_length (const struct tr_transition *tr, double s); const char *tr_status_string (int status); #endif /* INCLUDED_TRANSITION_V3_SPARAM_H */