COPP C ABI
C interface for COPP trajectory optimization
Loading...
Searching...
No Matches
topp2_ra.c
Go to the documentation of this file.
1#include "example_common.h"
2
3int main(void)
4{
5 /*
6 * 1) Deterministic 3-axis Lissajous path q(s), s in [0, 1].
7 *
8 * This example uses a callback path equivalent to the native parametric
9 * path example, so the analytic q, dq, and ddq values are the same.
10 */
11 double s[EXAMPLE_NUM_POINTS];
12 struct CoppPath *path = NULL;
13 struct CoppRobot *robot = NULL;
14 struct CoppVecF64 a_ra = {NULL, 0, 0};
15 struct CoppVecF64 t_s = {NULL, 0, 0};
16 struct CoppVecF64 s_t = {NULL, 0, 0};
17 int rc = 1;
18
19 example_fill_stations(s, EXAMPLE_NUM_POINTS);
20 if (example_create_analytic_path_2nd(&path))
21 {
22 goto cleanup;
23 }
24
25 /*
26 * 2) Build robot constraints (3-axis), then apply symmetric limits
27 * velocity/acceleration = [-1, 1].
28 */
29 if (example_create_robot_2nd(path, s, EXAMPLE_NUM_POINTS, &robot))
30 {
31 goto cleanup;
32 }
33
34 /*
35 * 3) Solve TOPP2-RA with boundary values a(0) = 0 and a(1) = 0.
36 * The output profile stores a[k] = (ds/dt)^2 at each station.
37 */
38 if (example_solve_topp2_seed(robot, EXAMPLE_NUM_POINTS, &a_ra))
39 {
40 goto cleanup;
41 }
42
43 /*
44 * 4) Post-process TOPP2-RA results: a(s) -> t(s) -> s(t).
45 * `t_s[k]` is the time when station s[k] is reached. `s_t` uses a
46 * uniform time grid with dt = 1e-3 s, which is useful for plotting and
47 * downstream control.
48 */
49 double t_final = 0.0;
50 if (example_time_from_second_order(s, EXAMPLE_NUM_POINTS, a_ra, &t_final, &t_s) ||
51 example_interpolate_second_order(s, EXAMPLE_NUM_POINTS, a_ra, t_s, &s_t))
52 {
53 goto cleanup;
54 }
55
56 /*
57 * 5) Print the tutorial summary.
58 */
59 printf("TOPP2-RA done.\n");
60 printf("dim = %d, N = %d\n", EXAMPLE_DIM, EXAMPLE_NUM_POINTS);
61 printf("t_final = %.6f s\n", t_final);
62 printf("a_profile.len() = %zu\n", a_ra.len);
63 printf("s(t) samples = %zu\n", s_t.len);
64 rc = 0;
65
66cleanup:
70 copp_robot_free(robot);
71 copp_path_free(path);
72 return rc;
73}
@ EXAMPLE_NUM_POINTS
@ EXAMPLE_DIM
void copp_vec_f64_free(struct CoppVecF64 vec)
Release a library-owned f64 vector returned by COPP.
struct CoppPath CoppPath
Opaque C handle for a library-owned Path.
Definition path.h:36
void copp_path_free(struct CoppPath *path)
Release a path handle created by this module.
struct CoppRobot CoppRobot
Opaque C handle for a library-owned robot and constraint buffer.
Definition robot.h:35
void copp_robot_free(struct CoppRobot *robot)
Release a robot handle created by copp_robot_create.
Library-owned f64 vector returned to C.
Definition core.h:828
size_t len
Number of initialized elements.
Definition core.h:836
int main(void)
Definition topp2_ra.c:3