diff options
| author | 2026-11-11 22:28:13 +0000 | |
|---|---|---|
| committer | 2026-11-11 22:47:34 +0000 | |
| commit | cb070b2d3f2b6e241e3be1b7e0eeb90fc755255f (patch) | |
| tree | c7d90c0abe9533c87d51b5196871846855efa1ba /src/transition.h | |
| download | thesis-master.tar.gz | |
Diffstat (limited to 'src/transition.h')
| -rw-r--r-- | src/transition.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/transition.h b/src/transition.h new file mode 100644 index 0000000..70b3ae9 --- /dev/null +++ b/src/transition.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | #ifndef INCLUDED_TRANSITION_V3_SPARAM_H | ||
| 2 | #define INCLUDED_TRANSITION_V3_SPARAM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include "vec2.h" | ||
| 6 | |||
| 7 | /* | ||
| 8 | * Time-optimal jerk-limited transition for independent X/Y axes. | ||
| 9 | * | ||
| 10 | * The planner treats X and Y as independent 1D axes with identical symmetric | ||
| 11 | * limits for both directions: | ||
| 12 | * |v_axis| <= vmax, |a_axis| <= amax, |j_axis| <= jmax. | ||
| 13 | * | ||
| 14 | * Boundary acceleration is fixed to zero on both axes. Jerk is a bounded | ||
| 15 | * control, not a state; tr_sample() reports j=0 outside the motion interval, | ||
| 16 | * but the time-optimal profile may jump from 0 to +/-jmax at t=0 and jump back | ||
| 17 | * to 0 at t=T. If continuous jerk is required, the problem is snap-limited, | ||
| 18 | * not jerk-limited. | ||
| 19 | * | ||
| 20 | * The transition can be sampled either by time t or by travelled arclength s. | ||
| 21 | * Arclength is computed as | ||
| 22 | * s(t) = integral_0^t hypot(vx(tau), vy(tau)) d tau. | ||
| 23 | * | ||
| 24 | * For fast repeated sampling by s, tr_transition stores an internal monotone | ||
| 25 | * lookup table parameterized by arclength. The dynamic profile is still stored | ||
| 26 | * as time-polynomial axis phases; the s-table only maps s -> t. | ||
| 27 | */ | ||
| 28 | |||
| 29 | #define TR_S_TABLE_CAP 2049u | ||
| 30 | |||
| 31 | #define TR_S_PARAM_TABLE_UNIFORM_BY_LENGTH 1 | ||
| 32 | |||
| 33 | enum tr_status { | ||
| 34 | TR_OK = 0, | ||
| 35 | TR_ERR_INVALID_ARG = -1, | ||
| 36 | TR_ERR_LIMITS = -2, | ||
| 37 | TR_ERR_INFEASIBLE = -3, | ||
| 38 | TR_ERR_NUMERIC = -4, | ||
| 39 | TR_ERR_NO_PROFILE = -5 | ||
| 40 | }; | ||
| 41 | |||
| 42 | struct tr_axis_phase { | ||
| 43 | double t_begin; | ||
| 44 | double dt; | ||
| 45 | double q0; | ||
| 46 | double v0; | ||
| 47 | double a0; | ||
| 48 | double j; | ||
| 49 | }; | ||
| 50 | |||
| 51 | struct tr_axis_plan { | ||
| 52 | struct tr_axis_phase phases[16]; | ||
| 53 | uint32_t count; | ||
| 54 | double duration; | ||
| 55 | double q0, q1; | ||
| 56 | double v0, v1; | ||
| 57 | }; | ||
| 58 | |||
| 59 | struct tr_s_node { | ||
| 60 | double s; | ||
| 61 | double t; | ||
| 62 | }; | ||
| 63 | |||
| 64 | struct tr_transition { | ||
| 65 | struct tr_axis_plan x; | ||
| 66 | struct tr_axis_plan y; | ||
| 67 | double duration; | ||
| 68 | double length; | ||
| 69 | |||
| 70 | /* Uniform arclength parameterization: s_nodes[i].s is approximately | ||
| 71 | * i*length/(s_node_count-1), and s_nodes[i].t is the corresponding time. | ||
| 72 | */ | ||
| 73 | uint32_t s_node_count; | ||
| 74 | double s_step; | ||
| 75 | struct tr_s_node s_nodes[TR_S_TABLE_CAP]; | ||
| 76 | |||
| 77 | double vmax, amax, jmax; | ||
| 78 | }; | ||
| 79 | |||
| 80 | struct tr_sample { | ||
| 81 | double t; | ||
| 82 | double s; | ||
| 83 | struct vec2 r; | ||
| 84 | struct vec2 v; | ||
| 85 | struct vec2 a; | ||
| 86 | struct vec2 j; | ||
| 87 | }; | ||
| 88 | |||
| 89 | int tr_build (struct tr_transition *out, | ||
| 90 | struct vec2 r0, | ||
| 91 | struct vec2 r1, | ||
| 92 | struct vec2 v0, | ||
| 93 | struct vec2 v1, | ||
| 94 | double vmax, | ||
| 95 | double amax, | ||
| 96 | double jmax); | ||
| 97 | |||
| 98 | void tr_sample (const struct tr_transition *tr, double t, struct tr_sample *out); | ||
| 99 | void tr_sample_at_s (const struct tr_transition *tr, double s, struct tr_sample *out); | ||
| 100 | |||
| 101 | double tr_length_at_time (const struct tr_transition *tr, double t); | ||
| 102 | double tr_time_at_length (const struct tr_transition *tr, double s); | ||
| 103 | |||
| 104 | const char *tr_status_string (int status); | ||
| 105 | |||
| 106 | #endif /* INCLUDED_TRANSITION_V3_SPARAM_H */ | ||
