COPP C ABI
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
36typedef struct CoppPath CoppPath;
37
45typedef struct CoppJet3 {
49 double v;
53 double d1;
57 double d2;
61 double d3;
62} CoppJet3;
63
77
87
126
135typedef enum CoppStatus (*CoppPathParametricFn)(void *user_data,
136 size_t dim,
137 struct CoppJet3 s,
138 struct CoppJet3 *q);
139
146typedef enum CoppStatus (*CoppPathEvaluate2ndFn)(void *user_data,
147 size_t dim,
148 size_t n,
149 const double *s,
150 double *q,
151 double *dq,
152 double *ddq);
153
160typedef enum CoppStatus (*CoppPathEvaluate3rdFn)(void *user_data,
161 size_t dim,
162 size_t n,
163 const double *s,
164 double *q,
165 double *dq,
166 double *ddq,
167 double *dddq);
168
169#ifdef __cplusplus
170}
171#endif
172
176static inline struct CoppJet3 copp_constant(double x)
177{
178 struct CoppJet3 out = {x, 0.0, 0.0, 0.0};
179 return out;
180}
181
185static inline struct CoppJet3 copp_add(struct CoppJet3 a, struct CoppJet3 b)
186{
187 struct CoppJet3 out = {a.v + b.v, a.d1 + b.d1, a.d2 + b.d2, a.d3 + b.d3};
188 return out;
189}
190
194static inline struct CoppJet3 copp_add_f64(struct CoppJet3 a, double b)
195{
196 struct CoppJet3 out = {a.v + b, a.d1, a.d2, a.d3};
197 return out;
198}
199
203static inline struct CoppJet3 copp_sub(struct CoppJet3 a, struct CoppJet3 b)
204{
205 struct CoppJet3 out = {a.v - b.v, a.d1 - b.d1, a.d2 - b.d2, a.d3 - b.d3};
206 return out;
207}
208
212static inline struct CoppJet3 copp_sub_f64(struct CoppJet3 a, double b)
213{
214 struct CoppJet3 out = {a.v - b, a.d1, a.d2, a.d3};
215 return out;
216}
217
221static inline struct CoppJet3 copp_f64_sub(double a, struct CoppJet3 b)
222{
223 struct CoppJet3 out = {a - b.v, -b.d1, -b.d2, -b.d3};
224 return out;
225}
226
230static inline struct CoppJet3 copp_neg(struct CoppJet3 x)
231{
232 struct CoppJet3 out = {-x.v, -x.d1, -x.d2, -x.d3};
233 return out;
234}
235
239static inline struct CoppJet3 copp_mul(struct CoppJet3 a, struct CoppJet3 b)
240{
241 struct CoppJet3 out = {
242 a.v * b.v,
243 a.d1 * b.v + a.v * b.d1,
244 a.d2 * b.v + 2.0 * a.d1 * b.d1 + a.v * b.d2,
245 a.d3 * b.v + 3.0 * (a.d2 * b.d1 + a.d1 * b.d2) + a.v * b.d3};
246 return out;
247}
248
252static inline struct CoppJet3 copp_mul_f64(struct CoppJet3 a, double b)
253{
254 struct CoppJet3 out = {a.v * b, a.d1 * b, a.d2 * b, a.d3 * b};
255 return out;
256}
257
261static inline struct CoppJet3 copp_f64_div(double a, struct CoppJet3 b)
262{
263 const double inv = 1.0 / b.v;
264 const double inv2 = inv * inv;
265 const double inv3 = inv2 * inv;
266 const double inv4 = inv3 * inv;
267 const double d1sq = b.d1 * b.d1;
268 struct CoppJet3 out = {
269 a * inv,
270 -a * inv2 * b.d1,
271 a * (2.0 * inv3 * d1sq - inv2 * b.d2),
272 a * (-6.0 * inv4 * d1sq * b.d1 + 6.0 * inv3 * b.d1 * b.d2 - inv2 * b.d3)};
273 return out;
274}
275
279static inline struct CoppJet3 copp_div_f64(struct CoppJet3 a, double b)
280{
281 return copp_mul_f64(a, 1.0 / b);
282}
283
287static inline struct CoppJet3 copp_div(struct CoppJet3 a, struct CoppJet3 b)
288{
289 return copp_mul(a, copp_f64_div(1.0, b));
290}
291
295static inline struct CoppJet3 copp_sin(struct CoppJet3 x)
296{
297 const double sv = sin(x.v);
298 const double cv = cos(x.v);
299 const double d1sq = x.d1 * x.d1;
300 struct CoppJet3 out = {
301 sv,
302 cv * x.d1,
303 -sv * d1sq + cv * x.d2,
304 -cv * d1sq * x.d1 - 3.0 * sv * x.d1 * x.d2 + cv * x.d3};
305 return out;
306}
307
311static inline struct CoppJet3 copp_cos(struct CoppJet3 x)
312{
313 const double sv = sin(x.v);
314 const double cv = cos(x.v);
315 const double d1sq = x.d1 * x.d1;
316 struct CoppJet3 out = {
317 cv,
318 -sv * x.d1,
319 -cv * d1sq - sv * x.d2,
320 sv * d1sq * x.d1 - 3.0 * cv * x.d1 * x.d2 - sv * x.d3};
321 return out;
322}
323
327static inline struct CoppJet3 copp_exp(struct CoppJet3 x)
328{
329 const double ev = exp(x.v);
330 const double d1sq = x.d1 * x.d1;
331 struct CoppJet3 out = {
332 ev,
333 ev * x.d1,
334 ev * (d1sq + x.d2),
335 ev * (d1sq * x.d1 + 3.0 * x.d1 * x.d2 + x.d3)};
336 return out;
337}
338
342static inline struct CoppJet3 copp_log(struct CoppJet3 x)
343{
344 const double inv = 1.0 / x.v;
345 const double inv2 = inv * inv;
346 const double inv3 = inv2 * inv;
347 const double d1sq = x.d1 * x.d1;
348 struct CoppJet3 out = {
349 log(x.v),
350 inv * x.d1,
351 -inv2 * d1sq + inv * x.d2,
352 2.0 * inv3 * d1sq * x.d1 - 3.0 * inv2 * x.d1 * x.d2 + inv * x.d3};
353 return out;
354}
355
359static inline struct CoppJet3 copp_sqrt(struct CoppJet3 x)
360{
361 const double sqrtv = sqrt(x.v);
362 const double inv_sqrt = 1.0 / sqrtv;
363 const double inv_v_sqrt = inv_sqrt / x.v;
364 const double inv_v2_sqrt = inv_v_sqrt / x.v;
365 const double d1sq = x.d1 * x.d1;
366 struct CoppJet3 out = {
367 sqrtv,
368 0.5 * inv_sqrt * x.d1,
369 -0.25 * inv_v_sqrt * d1sq + 0.5 * inv_sqrt * x.d2,
370 0.375 * inv_v2_sqrt * d1sq * x.d1 - 0.75 * inv_v_sqrt * x.d1 * x.d2 + 0.5 * inv_sqrt * x.d3};
371 return out;
372}
373
377static inline struct CoppJet3 copp_powi(struct CoppJet3 x, int n)
378{
379 if (n == 0) {
380 return copp_constant(1.0);
381 }
382
383 const double nf = (double)n;
384 const double coeff2 = nf * (nf - 1.0);
385 const double coeff3 = coeff2 * (nf - 2.0);
386 const double dv = nf * pow(x.v, nf - 1.0);
387 const double ddv = coeff2 == 0.0 ? 0.0 : coeff2 * pow(x.v, nf - 2.0);
388 const double dddv = coeff3 == 0.0 ? 0.0 : coeff3 * pow(x.v, nf - 3.0);
389 const double d1sq = x.d1 * x.d1;
390 struct CoppJet3 out = {
391 pow(x.v, (double)n),
392 dv * x.d1,
393 ddv * d1sq + dv * x.d2,
394 dddv * d1sq * x.d1 + 3.0 * ddv * x.d1 * x.d2 + dv * x.d3};
395 return out;
396}
397
398#ifdef __cplusplus
399extern "C" {
400#endif
401
412 double s_max,
413 struct CoppPathOptions *out_options);
414
460 struct CoppPathOptions options,
461 struct CoppPath **out_path);
462
511 double s_min,
512 double s_max,
513 CoppPathParametricFn evaluate,
514 void *user_data,
515 struct CoppPath **out_path);
516
565 double s_min,
566 double s_max,
567 CoppPathEvaluate2ndFn evaluate_2nd,
568 void *user_data,
569 struct CoppPath **out_path);
570
621 double s_min,
622 double s_max,
623 CoppPathEvaluate2ndFn evaluate_2nd,
624 CoppPathEvaluate3rdFn evaluate_3rd,
625 void *user_data,
626 struct CoppPath **out_path);
627
635enum CoppStatus copp_path_dim(const struct CoppPath *path, size_t *out_dim);
636
644enum CoppStatus copp_path_s_range(const struct CoppPath *path,
645 double *out_s_min,
646 double *out_s_max);
647
683 struct CoppSliceF64 s,
684 struct CoppMatrixF64 *out_q,
685 struct CoppMatrixF64 *out_dq,
686 struct CoppMatrixF64 *out_ddq);
687
713 struct CoppSliceF64 s,
714 struct CoppMatrixF64 *out_q,
715 struct CoppMatrixF64 *out_dq,
716 struct CoppMatrixF64 *out_ddq,
717 struct CoppMatrixF64 *out_dddq);
718
728void copp_path_free(struct CoppPath *path);
729
731
732#ifdef __cplusplus
733}
734#endif
735
736#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:36
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 a 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:146
CoppPathOutOfRangeMode
C ABI path out-of-range behavior.
Definition path.h:67
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_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(* 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:160
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_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:81
enum CoppStatus copp_path_default_options(double s_min, double s_max, struct CoppPathOptions *out_options)
Write default waypoint spline options into out_options.
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:135
@ COPP_PATH_OUT_OF_RANGE_MODE_CLAMP
Clamp query parameters into [s_min, s_max].
Definition path.h:75
@ COPP_PATH_OUT_OF_RANGE_MODE_ERROR
Return an error when a query parameter is outside [s_min, s_max].
Definition path.h:71
@ COPP_PATH_PARAMETRIZATION_UNIFORM
Uniform parameter spacing between waypoints.
Definition path.h:85
C-compatible third-order automatic-differentiation scalar.
Definition path.h:45
double v
Function value.
Definition path.h:49
double d1
First derivative with respect to s.
Definition path.h:53
double d3
Third derivative with respect to s.
Definition path.h:61
double d2
Second derivative with respect to s.
Definition path.h:57
Library-owned column-major f64 matrix returned to C.
Definition core.h:886
Borrowed immutable f64 matrix passed from C to COPP.
Definition core.h:720
Options for waypoint spline path construction.
Definition path.h:96
size_t order
Spline order.
Definition path.h:100
enum CoppPathParametrization parametrization
Waypoint parametrization mode.
Definition path.h:116
struct CoppMatrixViewF64 end_state
Boundary derivatives at s_max, or empty for zero boundary derivatives.
Definition path.h:124
enum CoppPathOutOfRangeMode out_of_range_mode
Behavior for out-of-range path evaluation.
Definition path.h:112
struct CoppMatrixViewF64 start_state
Boundary derivatives at s_min, or empty for zero boundary derivatives.
Definition path.h:120
double s_min
Lower bound of the path parameter range.
Definition path.h:104
double s_max
Upper bound of the path parameter range.
Definition path.h:108
Borrowed immutable f64 slice passed from C to COPP.
Definition core.h:781