COPP C ABI
C interface for COPP trajectory optimization
Loading...
Searching...
No Matches
topp3_socp.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 double s[EXAMPLE_NUM_POINTS];
9 struct CoppPath *path = NULL;
10 struct CoppRobot *robot = NULL;
11 struct CoppVecF64 a_ra0 = {NULL, 0, 0};
12 struct CoppProfile3rd profile_qp1 = {{NULL, 0, 0}, {NULL, 0, 0}, 0, 0};
13 struct CoppProfile3rd profile_qp2 = {{NULL, 0, 0}, {NULL, 0, 0}, 0, 0};
14 struct CoppVecF64 t_s1 = {NULL, 0, 0};
15 struct CoppVecF64 t_s2 = {NULL, 0, 0};
16 struct CoppVecF64 s_t1 = {NULL, 0, 0};
17 struct CoppVecF64 s_t2 = {NULL, 0, 0};
18 int rc = 1;
19
20 example_fill_stations(s, EXAMPLE_NUM_POINTS);
21 if (example_create_analytic_path_3rd(&path))
22 {
23 goto cleanup;
24 }
25
26 /*
27 * 2) Build robot constraints (3-axis), then apply symmetric limits
28 * velocity/acceleration/jerk = [-1, 1].
29 */
30 if (example_create_robot_3rd(path, s, EXAMPLE_NUM_POINTS, &robot))
31 {
32 goto cleanup;
33 }
34
35 /*
36 * 3) Solve TOPP2-RA to get a feasible linearization profile for TOPP3.
37 */
38 if (example_seed_third_order_problem(robot, EXAMPLE_NUM_POINTS, &a_ra0))
39 {
40 goto cleanup;
41 }
42
43 /*
44 * 4) Solve TOPP3-SOCP with the linearization profile from TOPP2-RA.
45 */
46 struct CoppClarabelOptions options_socp;
47 enum CoppStatus status = copp_clarabel_default_options(&options_socp);
48 if (example_expect_ok(status, "copp_clarabel_default_options"))
49 {
50 goto cleanup;
51 }
52 options_socp.allow_almost_solved = true;
53
54 struct Topp3Problem problem1 = {
55 robot,
56 0,
57 (struct CoppSliceF64){a_ra0.data, a_ra0.len},
58 0.0,
59 0.0,
60 0.0,
61 0.0,
62 1,
63 1,
64 1e-10,
65 };
66 status = topp3_socp(problem1, options_socp, &profile_qp1);
67 if (example_expect_ok(status, "topp3_socp first iteration"))
68 {
69 goto cleanup;
70 }
71
72 double t_final1 = 0.0;
73 if (example_time_from_third_order(s, EXAMPLE_NUM_POINTS, profile_qp1, &t_final1, &t_s1) ||
74 example_interpolate_third_order(s, EXAMPLE_NUM_POINTS, profile_qp1, t_s1, &s_t1))
75 {
76 goto cleanup;
77 }
78
79 printf("TOPP3-SOCP done. (The first-iteration)\n");
80 printf("dim = %d, N = %d\n", EXAMPLE_DIM, EXAMPLE_NUM_POINTS);
81 printf("t_final = %.6f s\n", t_final1);
82 printf("a_profile.len() = %zu\n", profile_qp1.a.len);
83 printf("b_profile.len() = %zu\n", profile_qp1.b.len);
84 printf("s(t) samples = %zu\n", s_t1.len);
85
86 /*
87 * 5) Solve TOPP3-SOCP with the first SOCP profile as the new linearization
88 * point, matching the tutorial's second SCP iteration.
89 */
90 struct Topp3Problem problem2 = {
91 robot,
92 0,
93 (struct CoppSliceF64){profile_qp1.a.data, profile_qp1.a.len},
94 0.0,
95 0.0,
96 0.0,
97 0.0,
98 1,
99 1,
100 1e-10,
101 };
102 status = topp3_socp(problem2, options_socp, &profile_qp2);
103 if (example_expect_ok(status, "topp3_socp second iteration"))
104 {
105 goto cleanup;
106 }
107
108 double t_final2 = 0.0;
109 if (example_time_from_third_order(s, EXAMPLE_NUM_POINTS, profile_qp2, &t_final2, &t_s2) ||
110 example_interpolate_third_order(s, EXAMPLE_NUM_POINTS, profile_qp2, t_s2, &s_t2))
111 {
112 goto cleanup;
113 }
114
115 printf("---------\nTOPP3-SOCP done. (The second-iteration)\n");
116 printf("dim = %d, N = %d\n", EXAMPLE_DIM, EXAMPLE_NUM_POINTS);
117 printf("t_final = %.6f s <= %.6f s\n", t_final2, t_final1);
118 printf("a_profile.len() = %zu\n", profile_qp2.a.len);
119 printf("b_profile.len() = %zu\n", profile_qp2.b.len);
120 printf("s(t) samples = %zu\n", s_t2.len);
121 rc = 0;
122
123cleanup:
124 copp_vec_f64_free(s_t2);
125 copp_vec_f64_free(s_t1);
126 copp_vec_f64_free(t_s2);
127 copp_vec_f64_free(t_s1);
128 copp_profile_3rd_free(profile_qp2);
129 copp_profile_3rd_free(profile_qp1);
130 copp_vec_f64_free(a_ra0);
131 copp_robot_free(robot);
132 copp_path_free(path);
133 return rc;
134}
@ EXAMPLE_NUM_POINTS
@ EXAMPLE_DIM
CoppStatus
C ABI status code returned by COPP FFI functions.
Definition core.h:34
void copp_vec_f64_free(struct CoppVecF64 vec)
Release a library-owned f64 vector returned by COPP.
enum CoppStatus copp_clarabel_default_options(struct CoppClarabelOptions *out_options)
Write default shared Clarabel options into out_options.
void copp_profile_3rd_free(struct CoppProfile3rd profile)
Release a third-order profile 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.
enum CoppStatus topp3_socp(struct Topp3Problem problem, struct CoppClarabelOptions options, struct CoppProfile3rd *out_profile)
Solve a TOPP3-SOCP problem.
Shared Clarabel options for COPP SOCP solvers.
Definition core.h:627
bool allow_almost_solved
Accept Clarabel status AlmostSolved as usable.
Definition core.h:635
Owned third-order profile returned by TOPP3/COPP3 C ABI solvers.
struct CoppVecF64 b
Node-based profile b[k] = ddot{s}_k.
struct CoppVecF64 a
Node-based profile a[k] = dot{s}_k^2.
Borrowed immutable f64 slice passed from C to COPP.
Definition core.h:781
Library-owned f64 vector returned to C.
Definition core.h:828
size_t len
Number of initialized elements.
Definition core.h:836
double * data
Pointer to the first element, or null for an empty vector.
Definition core.h:832
Borrowed value descriptor for a TOPP3 problem solved from C.
struct CoppRobot * robot
Mutable robot handle that owns station-indexed constraint storage.
int main(void)
Definition topp3_socp.c:3