aboutsummaryrefslogtreecommitdiff
path: root/src/motion_planner.h
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 22:28:13 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 22:47:34 +0000
commitcb070b2d3f2b6e241e3be1b7e0eeb90fc755255f (patch)
treec7d90c0abe9533c87d51b5196871846855efa1ba /src/motion_planner.h
downloadthesis-cb070b2d3f2b6e241e3be1b7e0eeb90fc755255f.tar.gz
publishHEADmaster
Diffstat (limited to 'src/motion_planner.h')
-rw-r--r--src/motion_planner.h159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/motion_planner.h b/src/motion_planner.h
new file mode 100644
index 0000000..0073f79
--- /dev/null
+++ b/src/motion_planner.h
@@ -0,0 +1,159 @@
1#ifndef INCLUDED_MOTION_PLANNER_H
2#define INCLUDED_MOTION_PLANNER_H
3
4#include <stdint.h>
5#include <stdio.h>
6#include "path.h"
7
8#define MP_EPS 1e-9
9
10enum mp_status {
11 MP_OK = 0,
12 MP_ERR_INVALID_ARG = -1,
13 MP_ERR_LIMITS = -2,
14 MP_ERR_ALLOC = -3,
15 MP_ERR_GEOMETRY = -4,
16 MP_ERR_PROFILE = -5
17};
18
19enum mp_geom_type {
20 MP_GEOM_LINE = 1,
21 MP_GEOM_ARC = 2
22};
23
24enum mp_node_flags {
25 MP_NODE_START = 1u << 0,
26 MP_NODE_END = 1u << 1,
27 MP_NODE_GEOM_GAP = 1u << 2,
28 MP_NODE_STRAIGHT = 1u << 3,
29 MP_NODE_CORNER_LIMIT = 1u << 4,
30 MP_NODE_HARD_STOP = 1u << 5,
31 MP_NODE_SPEED_CHANGE = 1u << 6,
32 MP_NODE_KNOT = 1u << 7
33};
34
35struct mp_vec2 {
36 double x;
37 double y;
38};
39
40struct mp_limits {
41 double vmax; // mm/s: предел для рабочих G1-перемещений
42 double rapid_vmax; // mm/s: предел для G0; если <= 0, используется vmax
43 double amax; // mm/s^2: скалярное тангенциальное ускорение
44 double jmax; // mm/s^3: скалярный jerk; должен быть > 0
45 double corner_tol; // mm: виртуальный допуск скругления углов
46 double min_segment_len; // mm: сегменты короче порога игнорируются
47 double default_feed; // mm/s: feed для G1, если path_element.f <= 0
48
49 double straight_angle_tol; // rad
50 double stop_angle; // rad
51 double corner_speed_deadband; // относительный deadband, например 0.02
52
53 double curvature_blend_len; // mm
54};
55
56struct mp_segment {
57 enum mp_geom_type type;
58 uint32_t source_index;
59 int flags;
60
61 struct mp_vec2 p0;
62 struct mp_vec2 p1;
63
64 struct mp_vec2 c; // центр дуги
65 double r; // радиус дуги
66 double a0; // начальный угол дуги
67 double sweep; // signed sweep, rad
68
69 double length; // mm
70 double s_begin; // global mm
71 double s_end; // global mm
72
73 double feed; // mm/s: командная скорость до ограничений
74 double v_nominal; // mm/s: скорость участка после ограничений
75};
76
77struct mp_node {
78 double s; // global mm
79 double v_cap; // mm/s: геометрический/командный предел узла
80 double v; // mm/s: скорость после lookahead
81 double theta; // rad: угол между касательными
82 uint32_t flags; // enum mp_node_flags
83};
84
85struct mp_phase {
86 double t_begin; // s
87 double dt; // s
88
89 double s_begin; // mm
90 double s_end; // mm
91
92 double v0; // mm/s
93 double a0; // mm/s^2
94 double j; // mm/s^3
95};
96
97struct motion_plan {
98 struct mp_segment *segments;
99 uint32_t segment_count;
100 uint32_t segment_capacity;
101
102 struct mp_node *nodes;
103 uint32_t node_count;
104 uint32_t node_capacity;
105
106 struct mp_phase *phases;
107 uint32_t phase_count;
108 uint32_t phase_capacity;
109
110 double total_length;
111 double total_time;
112
113 double curvature_blend_len; // mm
114
115 double v_min;
116 double v_max;
117 double a_min;
118 double a_max;
119 double j_min;
120 double j_max;
121};
122
123struct mp_sample {
124 double t;
125 double s;
126
127 struct mp_vec2 p;
128 struct mp_vec2 tangent;
129 struct mp_vec2 normal;
130
131 double kappa;
132 double kappa_geom;
133
134 double v;
135 double a_t;
136 double j_t;
137
138 double a_n;
139 double a_abs;
140 double j_abs;
141
142 struct mp_vec2 vel;
143 struct mp_vec2 acc;
144 struct mp_vec2 jerk;
145
146 uint32_t segment_index;
147 uint32_t source_index;
148 int source_flags;
149};
150
151void mp_plan_init (struct motion_plan *plan);
152void mp_plan_free (struct motion_plan *plan);
153
154int mp_plan_build (const struct path *path, double initial_x, double initial_y, const struct mp_limits *limits, struct motion_plan *out);
155void mp_plan_eval_scalar (const struct motion_plan *plan, double t, double *s_out, double *v_out, double *a_out, double *j_out);
156void mp_plan_sample (const struct motion_plan *plan, double t, struct mp_sample *out);
157void mp_plan_write_csv (const struct motion_plan *plan, double dt, FILE *out, int write_header);
158
159#endif // INCLUDED_MOTION_PLANNER_H