COPP C ABI 0.2.3
C interface for COPP trajectory optimization
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1#ifndef COPP_PATH_H
2#define COPP_PATH_H
3
4/*
5 * Generated by bindings/c/scripts/generate_headers.ps1.
6 * Do not edit by hand; update src/ffi/c and regenerate.
7 */
8
14
15#include <stddef.h>
16#include <math.h>
17#include "copp/core.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
27
37typedef struct CoppPath CoppPath;
38
46typedef struct CoppJet3 {
50 double v;
54 double d1;
58 double d2;
62 double d3;
63} CoppJet3;
64
78
88
127
136typedef enum CoppStatus (*CoppPathParametricFn)(void *user_data,
137 size_t dim,
138 struct CoppJet3 s,
139 struct CoppJet3 *q);
140
147typedef enum CoppStatus (*CoppPathEvaluate2ndFn)(void *user_data,
148 size_t dim,
149 size_t n,
150 const double *s,
151 double *q,
152 double *dq,
153 double *ddq);
154
161typedef enum CoppStatus (*CoppPathEvaluate3rdFn)(void *user_data,
162 size_t dim,
163 size_t n,
164 const double *s,
165 double *q,
166 double *dq,
167 double *ddq,
168 double *dddq);
169
170#ifdef __cplusplus
171}
172#endif
173
177static inline struct CoppJet3 copp_constant(double x)
178{
179 struct CoppJet3 out = {x, 0.0, 0.0, 0.0};
180 return out;
181}
182
186static inline struct CoppJet3 copp_add(struct CoppJet3 a, struct CoppJet3 b)
187{
188 struct CoppJet3 out = {a.v + b.v, a.d1 + b.d1, a.d2 + b.d2, a.d3 + b.d3};
189 return out;
190}
191
195static inline struct CoppJet3 copp_add_f64(struct CoppJet3 a, double b)
196{
197 struct CoppJet3 out = {a.v + b, a.d1, a.d2, a.d3};
198 return out;
199}
200
204static inline struct CoppJet3 copp_sub(struct CoppJet3 a, struct CoppJet3 b)
205{
206 struct CoppJet3 out = {a.v - b.v, a.d1 - b.d1, a.d2 - b.d2, a.d3 - b.d3};
207 return out;
208}
209
213static inline struct CoppJet3 copp_sub_f64(struct CoppJet3 a, double b)
214{
215 struct CoppJet3 out = {a.v - b, a.d1, a.d2, a.d3};
216 return out;
217}
218
222static inline struct CoppJet3 copp_f64_sub(double a, struct CoppJet3 b)
223{
224 struct CoppJet3 out = {a - b.v, -b.d1, -b.d2, -b.d3};
225 return out;
226}
227
231static inline struct CoppJet3 copp_neg(struct CoppJet3 x)
232{
233 struct CoppJet3 out = {-x.v, -x.d1, -x.d2, -x.d3};
234 return out;
235}
236
240static inline struct CoppJet3 copp_mul(struct CoppJet3 a, struct CoppJet3 b)
241{
242 struct CoppJet3 out = {
243 a.v * b.v,
244 a.d1 * b.v + a.v * b.d1,
245 a.d2 * b.v + 2.0 * a.d1 * b.d1 + a.v * b.d2,
246 a.d3 * b.v + 3.0 * (a.d2 * b.d1 + a.d1 * b.d2) + a.v * b.d3};
247 return out;
248}
249
253static inline struct CoppJet3 copp_mul_f64(struct CoppJet3 a, double b)
254{
255 struct CoppJet3 out = {a.v * b, a.d1 * b, a.d2 * b, a.d3 * b};
256 return out;
257}
258
262static inline struct CoppJet3 copp_f64_div(double a, struct CoppJet3 b)
263{
264 const double inv = 1.0 / b.v;
265 const double inv2 = inv * inv;
266 const double inv3 = inv2 * inv;
267 const double inv4 = inv3 * inv;
268 const double d1sq = b.d1 * b.d1;
269 struct CoppJet3 out = {
270 a * inv,
271 -a * inv2 * b.d1,
272 a * (2.0 * inv3 * d1sq - inv2 * b.d2),
273 a * (-6.0 * inv4 * d1sq * b.d1 + 6.0 * inv3 * b.d1 * b.d2 - inv2 * b.d3)};
274 return out;
275}
276
280static inline struct CoppJet3 copp_div_f64(struct CoppJet3 a, double b)
281{
282 return copp_mul_f64(a, 1.0 / b);
283}
284
288static inline struct CoppJet3 copp_div(struct CoppJet3 a, struct CoppJet3 b)
289{
290 return copp_mul(a, copp_f64_div(1.0, b));
291}
292
296static inline struct CoppJet3 copp_sin(struct CoppJet3 x)
297{
298 const double sv = sin(x.v);
299 const double cv = cos(x.v);
300 const double d1sq = x.d1 * x.d1;
301 struct CoppJet3 out = {
302 sv,
303 cv * x.d1,
304 -sv * d1sq + cv * x.d2,
305 -cv * d1sq * x.d1 - 3.0 * sv * x.d1 * x.d2 + cv * x.d3};
306 return out;
307}
308
312static inline struct CoppJet3 copp_cos(struct CoppJet3 x)
313{
314 const double sv = sin(x.v);
315 const double cv = cos(x.v);
316 const double d1sq = x.d1 * x.d1;
317 struct CoppJet3 out = {
318 cv,
319 -sv * x.d1,
320 -cv * d1sq - sv * x.d2,
321 sv * d1sq * x.d1 - 3.0 * cv * x.d1 * x.d2 - sv * x.d3};
322 return out;
323}
324
328static inline struct CoppJet3 copp_exp(struct CoppJet3 x)
329{
330 const double ev = exp(x.v);
331 const double d1sq = x.d1 * x.d1;
332 struct CoppJet3 out = {
333 ev,
334 ev * x.d1,
335 ev * (d1sq + x.d2),
336 ev * (d1sq * x.d1 + 3.0 * x.d1 * x.d2 + x.d3)};
337 return out;
338}
339
343static inline struct CoppJet3 copp_log(struct CoppJet3 x)
344{
345 const double inv = 1.0 / x.v;
346 const double inv2 = inv * inv;
347 const double inv3 = inv2 * inv;
348 const double d1sq = x.d1 * x.d1;
349 struct CoppJet3 out = {
350 log(x.v),
351 inv * x.d1,
352 -inv2 * d1sq + inv * x.d2,
353 2.0 * inv3 * d1sq * x.d1 - 3.0 * inv2 * x.d1 * x.d2 + inv * x.d3};
354 return out;
355}
356
360static inline struct CoppJet3 copp_sqrt(struct CoppJet3 x)
361{
362 const double sqrtv = sqrt(x.v);
363 const double inv_sqrt = 1.0 / sqrtv;
364 const double inv_v_sqrt = inv_sqrt / x.v;
365 const double inv_v2_sqrt = inv_v_sqrt / x.v;
366 const double d1sq = x.d1 * x.d1;
367 struct CoppJet3 out = {
368 sqrtv,
369 0.5 * inv_sqrt * x.d1,
370 -0.25 * inv_v_sqrt * d1sq + 0.5 * inv_sqrt * x.d2,
371 0.375 * inv_v2_sqrt * d1sq * x.d1 - 0.75 * inv_v_sqrt * x.d1 * x.d2 + 0.5 * inv_sqrt * x.d3};
372 return out;
373}
374
378static inline struct CoppJet3 copp_powi(struct CoppJet3 x, int n)
379{
380 if (n == 0) {
381 return copp_constant(1.0);
382 }
383
384 const double nf = (double)n;
385 const double coeff2 = nf * (nf - 1.0);
386 const double coeff3 = coeff2 * (nf - 2.0);
387 const double dv = nf * pow(x.v, nf - 1.0);
388 const double ddv = coeff2 == 0.0 ? 0.0 : coeff2 * pow(x.v, nf - 2.0);
389 const double dddv = coeff3 == 0.0 ? 0.0 : coeff3 * pow(x.v, nf - 3.0);
390 const double d1sq = x.d1 * x.d1;
391 struct CoppJet3 out = {
392 pow(x.v, (double)n),
393 dv * x.d1,
394 ddv * d1sq + dv * x.d2,
395 dddv * d1sq * x.d1 + 3.0 * ddv * x.d1 * x.d2 + dv * x.d3};
396 return out;
397}
398
399#ifdef __cplusplus
400extern "C" {
401#endif
402
413 double s_max,
414 struct CoppPathOptions *out_options);
415
468 struct CoppPathOptions options,
469 struct CoppPath **out_path);
470
482 struct CoppPathOptions options,
483 struct CoppPath **out_path);
484
571
624
637
721 struct CoppSmoothingOptions options,
722 struct CoppPath **out_path);
723
739 bool *out_has_report,
740 struct CoppSmoothingReport *out_report);
741
754
803 double s_min,
804 double s_max,
805 CoppPathParametricFn evaluate,
806 void *user_data,
807 struct CoppPath **out_path);
808
857 double s_min,
858 double s_max,
859 CoppPathEvaluate2ndFn evaluate_2nd,
860 void *user_data,
861 struct CoppPath **out_path);
862
913 double s_min,
914 double s_max,
915 CoppPathEvaluate2ndFn evaluate_2nd,
916 CoppPathEvaluate3rdFn evaluate_3rd,
917 void *user_data,
918 struct CoppPath **out_path);
919
927enum CoppStatus copp_path_dim(const struct CoppPath *path, size_t *out_dim);
928
936enum CoppStatus copp_path_s_range(const struct CoppPath *path,
937 double *out_s_min,
938 double *out_s_max);
939
975 struct CoppSliceF64 s,
976 struct CoppMatrixF64 *out_q,
977 struct CoppMatrixF64 *out_dq,
978 struct CoppMatrixF64 *out_ddq);
979
1005 struct CoppSliceF64 s,
1006 struct CoppMatrixF64 *out_q,
1007 struct CoppMatrixF64 *out_dq,
1008 struct CoppMatrixF64 *out_ddq,
1009 struct CoppMatrixF64 *out_dddq);
1010
1020void copp_path_free(struct CoppPath *path);
1021
1023
1024#ifdef __cplusplus
1025}
1026#endif
1027
1028#endif /* COPP_PATH_H */
Core status, memory, matrix, and shared solver option types.
CoppStatus
C ABI status code returned by COPP FFI functions.
Definition core.h:34
struct CoppPath CoppPath
Opaque C handle for a library-owned Path.
Definition path.h:37
enum CoppStatus copp_path_evaluate_up_to_3rd(const struct CoppPath *path, struct CoppSliceF64 s, struct CoppMatrixF64 *out_q, struct CoppMatrixF64 *out_dq, struct CoppMatrixF64 *out_ddq, struct CoppMatrixF64 *out_dddq)
Evaluate q, dq, ddq, and dddq at the supplied path parameters.
enum CoppStatus copp_path_from_waypoints(struct CoppMatrixViewF64 waypoints, struct CoppPathOptions options, struct CoppPath **out_path)
Build an interpolating waypoint spline path.
enum CoppStatus copp_path_dim(const struct CoppPath *path, size_t *out_dim)
Return the path dimension.
enum CoppStatus(* CoppPathEvaluate2ndFn)(void *user_data, size_t dim, size_t n, const double *s, double *q, double *dq, double *ddq)
C callback for evaluating q, dq, and ddq.
Definition path.h:147
CoppPathOutOfRangeMode
C ABI path out-of-range behavior.
Definition path.h:68
enum CoppStatus copp_path_s_range(const struct CoppPath *path, double *out_s_min, double *out_s_max)
Return the valid path parameter range.
enum CoppStatus copp_smoothing_default_options(struct CoppSmoothingOptions *out_options)
Write default tolerance-bounded fitting options into out_options.
enum CoppStatus copp_path_from_evaluator_2nd(size_t dim, double s_min, double s_max, CoppPathEvaluate2ndFn evaluate_2nd, void *user_data, struct CoppPath **out_path)
Build a path from a C callback that provides derivatives up to 2nd order.
enum CoppStatus copp_path_smoothing_report(const struct CoppPath *path, bool *out_has_report, struct CoppSmoothingReport *out_report)
Return the construction report of a tolerance-fitted waypoint path.
enum CoppStatus(* CoppPathEvaluate3rdFn)(void *user_data, size_t dim, size_t n, const double *s, double *q, double *dq, double *ddq, double *dddq)
C callback for evaluating q, dq, ddq, and dddq.
Definition path.h:161
void copp_path_free(struct CoppPath *path)
Release a path handle created by this module.
enum CoppStatus copp_path_from_parametric(size_t dim, double s_min, double s_max, CoppPathParametricFn evaluate, void *user_data, struct CoppPath **out_path)
Build a path from a scalar-parametric C callback.
enum CoppStatus copp_path_evaluate_up_to_2nd(const struct CoppPath *path, struct CoppSliceF64 s, struct CoppMatrixF64 *out_q, struct CoppMatrixF64 *out_dq, struct CoppMatrixF64 *out_ddq)
Evaluate q, dq, and ddq at the supplied path parameters.
enum CoppStatus copp_path_from_waypoints_interpolating(struct CoppMatrixViewF64 waypoints, struct CoppPathOptions options, struct CoppPath **out_path)
Build an interpolating waypoint spline path.
enum CoppStatus copp_path_from_evaluator_3rd(size_t dim, double s_min, double s_max, CoppPathEvaluate2ndFn evaluate_2nd, CoppPathEvaluate3rdFn evaluate_3rd, void *user_data, struct CoppPath **out_path)
Build a path from C callbacks that provide derivatives up to 3rd order.
CoppPathParametrization
C ABI waypoint-spline parametrization.
Definition path.h:82
enum CoppStatus copp_path_from_waypoints_fitting(struct CoppMatrixViewF64 waypoints, struct CoppSmoothingOptions options, struct CoppPath **out_path)
Build a tolerance-bounded waypoint-fitting path.
enum CoppStatus copp_path_default_options(double s_min, double s_max, struct CoppPathOptions *out_options)
Write default waypoint spline options into out_options.
void copp_smoothing_report_free(struct CoppSmoothingReport report)
Release memory owned by a CoppSmoothingReport.
enum CoppStatus(* CoppPathParametricFn)(void *user_data, size_t dim, struct CoppJet3 s, struct CoppJet3 *q)
C callback for evaluating a scalar-parametric path with automatic derivatives.
Definition path.h:136
@ COPP_PATH_OUT_OF_RANGE_MODE_CLAMP
Clamp query parameters into [s_min, s_max].
Definition path.h:76
@ COPP_PATH_OUT_OF_RANGE_MODE_ERROR
Return an error when a query parameter is outside [s_min, s_max].
Definition path.h:72
@ COPP_PATH_PARAMETRIZATION_UNIFORM
Uniform parameter spacing between waypoints.
Definition path.h:86
C-compatible third-order automatic-differentiation scalar.
Definition path.h:46
double v
Function value.
Definition path.h:50
double d1
First derivative with respect to s.
Definition path.h:54
double d3
Third derivative with respect to s.
Definition path.h:62
double d2
Second derivative with respect to s.
Definition path.h:58
Library-owned column-major f64 matrix returned to C.
Definition core.h:934
Borrowed immutable f64 matrix passed from C to COPP.
Definition core.h:751
Options for waypoint spline path construction.
Definition path.h:97
size_t order
Spline order.
Definition path.h:101
enum CoppPathParametrization parametrization
Waypoint parametrization mode.
Definition path.h:117
struct CoppMatrixViewF64 end_state
Boundary derivatives at s_max, or empty for zero boundary derivatives.
Definition path.h:125
enum CoppPathOutOfRangeMode out_of_range_mode
Behavior for out-of-range path evaluation.
Definition path.h:113
struct CoppMatrixViewF64 start_state
Boundary derivatives at s_min, or empty for zero boundary derivatives.
Definition path.h:121
double s_min
Lower bound of the path parameter range.
Definition path.h:105
double s_max
Upper bound of the path parameter range.
Definition path.h:109
Borrowed immutable f64 slice passed from C to COPP.
Definition core.h:812
Borrowed immutable size_t slice passed from C to COPP.
Definition core.h:847
Options for tolerance-bounded waypoint fitting.
Definition path.h:510
size_t max_segments
Maximum number of polynomial spans used by the selected axes.
Definition path.h:562
struct CoppSliceF64 parameters
Optional common path parameter assigned to each waypoint column.
Definition path.h:548
size_t max_refinements
Maximum number of adaptive knot-refinement passes.
Definition path.h:555
struct CoppSliceUsize axes
Optional 0-based input rows allowed to deviate from their reference polylines.
Definition path.h:539
struct CoppSliceF64 tolerance_per_axis
Optional per-axis absolute tolerances.
Definition path.h:528
enum CoppPathOutOfRangeMode out_of_range_mode
Behavior for out-of-range evaluation of the returned path.
Definition path.h:569
double tolerance
Absolute tolerance broadcast to every selected axis when tolerance_per_axis is empty.
Definition path.h:518
Diagnostics recorded while constructing a tolerance-fitted waypoint path.
Definition path.h:585
size_t segments
Number of final polynomial spans shared by the selected axes.
Definition path.h:593
size_t refinements
Number of completed local knot-refinement passes.
Definition path.h:604
struct CoppVecUsize axes
Selected 0-based input-row indices, in tolerance/report order.
Definition path.h:589
size_t checked_intervals
Number of reference-polyline intervals visited by numerical audits, including revisits and the final ...
Definition path.h:614
size_t fitting_rows
Number of discrete or quadrature fitting rows assembled, counting rows assembled again during local r...
Definition path.h:609
size_t interpolated_segments
Number of spans in the separate unselected-axis interpolant.
Definition path.h:600
struct CoppVecF64 max_errors
Final whole-domain absolute-error bound for each selected axis.
Definition path.h:622
Library-owned f64 vector returned to C.
Definition core.h:876
Library-owned usize vector returned to C.
Definition core.h:897