COPP C ABI
C interface for COPP trajectory optimization
Loading...
Searching...
No Matches
copp2_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 double normalize[EXAMPLE_DIM] = {1.0, 1.0, 1.0};
10 struct CoppPath *path = NULL;
11 struct CoppRobot *robot = NULL;
12 struct CoppVecF64 a_socp = {NULL, 0, 0};
13 struct CoppVecF64 t_s = {NULL, 0, 0};
14 struct CoppVecF64 s_t = {NULL, 0, 0};
15 int rc = 1;
16
17 example_fill_stations(s, EXAMPLE_NUM_POINTS);
18 if (example_create_analytic_path_2nd(&path))
19 {
20 goto cleanup;
21 }
22
23 /*
24 * 2) Build robot constraints (3-axis), then apply symmetric limits
25 * velocity/acceleration = [-1, 1].
26 */
27 if (example_create_robot_2nd(path, s, EXAMPLE_NUM_POINTS, &robot))
28 {
29 goto cleanup;
30 }
31
32 /*
33 * 3) Build COPP2 problem and solve COPP2-SOCP with Clarabel.
34 *
35 * The objective is 1.0 * time + 0.1 * thermal energy. With no
36 * inverse-dynamics callback installed, torque objectives use point
37 * dynamics (`tau = ddq`).
38 */
39 struct CoppClarabelOptions options;
40 enum CoppStatus status = copp_clarabel_default_options(&options);
41 if (example_expect_ok(status, "copp_clarabel_default_options"))
42 {
43 goto cleanup;
44 }
45 options.allow_almost_solved = true;
46
47 struct CoppSliceF64 empty = {NULL, 0};
48 struct CoppSliceF64 normalize_slice = {normalize, EXAMPLE_DIM};
49 struct CoppObjective objectives[2] = {
50 {COPP_OBJECTIVE_KIND_TIME, 1.0, empty, empty, empty},
51 {COPP_OBJECTIVE_KIND_THERMAL_ENERGY, 0.1, empty, empty, normalize_slice},
52 };
53 struct Copp2Problem problem = {
54 robot,
55 0,
57 0.0,
58 0.0,
60 2,
61 };
62
63 status = copp2_socp(problem, options, &a_socp);
64 if (example_expect_ok(status, "copp2_socp"))
65 {
66 goto cleanup;
67 }
68
69 /*
70 * 4) Post-process COPP2-SOCP results: a(s) -> t(s) -> s(t).
71 */
72 double t_final = 0.0;
73 if (example_time_from_second_order(s, EXAMPLE_NUM_POINTS, a_socp, &t_final, &t_s) ||
74 example_interpolate_second_order(s, EXAMPLE_NUM_POINTS, a_socp, t_s, &s_t))
75 {
76 goto cleanup;
77 }
78
79 /*
80 * 5) Print the tutorial summary.
81 */
82 printf("COPP2-SOCP done.\n");
83 printf("dim = %d, N = %d\n", EXAMPLE_DIM, EXAMPLE_NUM_POINTS);
84 printf("t_final = %.6f s\n", t_final);
85 printf("a_profile.len() = %zu\n", a_socp.len);
86 printf("s(t) samples = %zu\n", s_t.len);
87 rc = 0;
88
89cleanup:
92 copp_vec_f64_free(a_socp);
94 copp_path_free(path);
95 return rc;
96}
int main(void)
Definition copp2_socp.c:3
@ EXAMPLE_NUM_POINTS
@ EXAMPLE_DIM
enum CoppStatus copp2_socp(struct Copp2Problem problem, struct CoppClarabelOptions options, struct CoppVecF64 *out_a)
Solve a COPP2-SOCP problem.
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.
@ COPP_OBJECTIVE_KIND_TIME
Time objective: weight * integral dt.
Definition formulation.h:35
@ COPP_OBJECTIVE_KIND_THERMAL_ENERGY
Thermal-energy objective.
Definition formulation.h:48
struct CoppPath CoppPath
Opaque C handle for a library-owned Path.
Definition path.h:34
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.
Borrowed value descriptor for a COPP2 problem solved from C.
const struct CoppRobot * robot
Robot handle that owns the station-indexed constraint storage.
const struct CoppObjective * objectives
Objective descriptor array.
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
Borrowed objective descriptor for COPP solvers.
Definition formulation.h:86
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