40 #include "pathdesired.h"
43 static void path_endpoint(
const float * start_point,
const float * end_point,
45 static void path_vector(
const float * start_point,
const float * end_point,
47 static void path_circle(
const float * center_point,
float radius,
50 static void path_curve(
const float * start_point,
const float * end_point,
51 float radius,
const float * cur_point,
63 const float *cur_point,
66 uint8_t
mode = pathDesired->Mode;
67 float start_point[2] = {pathDesired->Start[0],pathDesired->Start[1]};
68 float end_point[2] = {pathDesired->End[0],pathDesired->End[1]};
71 case PATHDESIRED_MODE_VECTOR:
72 return path_vector(start_point, end_point, cur_point, status);
74 case PATHDESIRED_MODE_CIRCLERIGHT:
75 return path_curve(start_point, end_point, pathDesired->ModeParameters, cur_point, status, 1);
77 case PATHDESIRED_MODE_CIRCLELEFT:
78 return path_curve(start_point, end_point, pathDesired->ModeParameters, cur_point, status, 0);
80 case PATHDESIRED_MODE_CIRCLEPOSITIONLEFT:
81 return path_circle(end_point, pathDesired->ModeParameters, cur_point, status, 0);
83 case PATHDESIRED_MODE_CIRCLEPOSITIONRIGHT:
84 return path_circle(end_point, pathDesired->ModeParameters, cur_point, status, 1);
86 case PATHDESIRED_MODE_ENDPOINT:
87 case PATHDESIRED_MODE_HOLDPOSITION:
90 return path_endpoint(start_point, end_point, cur_point, status);
103 const float *end_point,
104 const float *cur_point,
107 float path_north, path_east, diff_north, diff_east;
108 float dist_path, dist_diff;
114 path_north = end_point[0] - start_point[0];
115 path_east = end_point[1] - start_point[1];
118 diff_north = end_point[0] - cur_point[0];
119 diff_east = end_point[1] - cur_point[1];
121 dist_diff = sqrtf( diff_north * diff_north + diff_east * diff_east );
122 dist_path = sqrtf( path_north * path_north + path_east * path_east );
124 if(dist_diff < 1e-6
f ) {
132 status->
error = dist_diff;
147 const float *end_point,
148 const float *cur_point,
151 float path_north, path_east, diff_north, diff_east;
157 path_north = end_point[0] - start_point[0];
158 path_east = end_point[1] - start_point[1];
161 diff_north = cur_point[0] - start_point[0];
162 diff_east = cur_point[1] - start_point[1];
164 dot = path_north * diff_north + path_east * diff_east;
165 dist_path = sqrtf( path_north * path_north + path_east * path_east );
167 if(dist_path < 1e-6
f) {
177 normal[0] = -path_east / dist_path;
178 normal[1] = path_north / dist_path;
181 status->
error = normal[0] * diff_north + normal[1] * diff_east;
205 const float * cur_point,
209 float diff_north, diff_east;
213 if (radius < 0.10
f) {
218 diff_north = cur_point[0] - center_point[0];
219 diff_east = cur_point[1] - center_point[1];
221 cradius = sqrtf( diff_north * diff_north + diff_east * diff_east );
223 if (cradius < 1e-6
f) {
226 status->
error = radius;
236 normal[0] = -diff_east / cradius;
237 normal[1] = diff_north / cradius;
240 normal[0] = diff_east / cradius;
241 normal[1] = -diff_north / cradius;
247 status->
error = radius - cradius;
269 const float * end_point,
271 const float * cur_point,
276 float min_radius = sqrtf(powf(start_point[0] - end_point[0], 2) +
277 powf(start_point[1] - end_point[1], 2)) / 2.0f + 0.01f;
279 if (fabsf(radius) < min_radius) {
290 if (fabsf(radius) < min_radius) {
293 radius = min_radius * 1000;
297 float diff_north, diff_east;
298 float path_north, path_east;
305 float m_n, m_e, p_n, p_e,
d, center[2];
308 m_n = (start_point[0] + end_point[0]) / 2;
309 m_e = (start_point[1] + end_point[1]) / 2;
313 p_n = -(end_point[1] - start_point[1]);
314 p_e = (end_point[0] - start_point[0]);
316 p_n = (end_point[1] - start_point[1]);
317 p_e = -(end_point[0] - start_point[0]);
321 d = sqrtf(radius * radius / (p_n * p_n + p_e * p_e) - 0.25
f);
323 float radius_sign = (radius > 0) ? 1 : -1;
324 float m_radius = fabsf(radius);
326 if (fabsf(p_n) < 1e-3
f && fabsf(p_e) < 1e-3
f) {
330 center[0] = m_n + p_n * d * radius_sign;
331 center[1] = m_e + p_e * d * radius_sign;
335 diff_north = cur_point[0] - center[0];
336 diff_east = cur_point[1] - center[1];
339 cradius = sqrtf( diff_north * diff_north + diff_east * diff_east );
343 status->
error = m_radius - cradius;
345 if (cradius < 1e-6
f) {
348 status->
error = m_radius;
358 normal[0] = -diff_east / cradius;
359 normal[1] = diff_north / cradius;
362 normal[0] = diff_east / cradius;
363 normal[1] = -diff_north / cradius;
374 path_north = end_point[0] - start_point[0];
375 path_east = end_point[1] - start_point[1];
376 diff_north = cur_point[0] - start_point[0];
377 diff_east = cur_point[1] - start_point[1];
378 float dist_path = sqrtf( path_north * path_north + path_east * path_east );
379 float dot = path_north * diff_north + path_east * diff_east;
static void path_endpoint(const float *start_point, const float *end_point, const float *cur_point, struct path_status *status)
Compute progress towards endpoint. Deviation equals distance.
static PathDesiredData pathDesired
Main PiOS header to include all the compiled in PiOS options.
static void path_circle(const float *center_point, float radius, const float *cur_point, struct path_status *status, bool clockwise)
Circle location continuously.
static void path_vector(const float *start_point, const float *end_point, const float *cur_point, struct path_status *status)
Compute progress along path and deviation from it.
float fractional_progress
static void path_curve(const float *start_point, const float *end_point, float radius, const float *cur_point, struct path_status *status, bool clockwise)
Compute progress along circular path and deviation from it.
Path calculation library with common API.
void path_progress(const PathDesiredData *pathDesired, const float *cur_point, struct path_status *status)
Compute progress along path and deviation from it.
float correction_direction[2]