COPP C ABI
C interface for COPP trajectory optimization
Loading...
Searching...
No Matches
Copp_copp2

Files

file  bindings/c/include/copp/copp2.h
 COPP2-SOCP solver APIs.

Data Structures

struct  Copp2SocpResult
 Compact COPP2-SOCP expert result returned to C. More...

Functions

enum CoppStatus copp2_socp (struct Copp2Problem problem, struct CoppClarabelOptions options, struct CoppVecF64 *out_a)
 Solve a COPP2-SOCP problem.
enum CoppStatus copp2_socp_expert (struct Copp2Problem problem, struct CoppClarabelOptions options, struct Copp2SocpResult *out_result)
 Solve a COPP2-SOCP problem and always return Clarabel diagnostics.
void copp2_socp_result_free (struct Copp2SocpResult result)
 Release memory owned by a Copp2SocpResult.

Detailed Description

Function Documentation

◆ copp2_socp()

enum CoppStatus copp2_socp ( struct Copp2Problem problem,
struct CoppClarabelOptions options,
struct CoppVecF64 * out_a )

Solve a COPP2-SOCP problem.

This C ABI builds an internal COPP2 problem from the borrowed Copp2Problem, forwards options to the Clarabel backend, and returns only the optimized a(s) = (ds/dt)^2 profile.

Supported objective kinds are Time, Linear, ThermalEnergy, and TotalVariationTorque. The torque objectives use the robot's stored inverse-dynamics callback when provided, otherwise point dynamics (tau = ddq) is used.

On success, out_a owns a COPP-allocated vector over the closed station interval and must be released with copp_vec_f64_free.

Example

The example below solves COPP2-SOCP with Clarabel options and releases the optimized a(s) profile.

struct CoppClarabelOptions options;
struct Copp2Problem problem = {
robot, 0, n - 1, 0.0, 0.0, objectives, num_objectives,
};
struct CoppVecF64 a = {0};
options.allow_almost_solved = true;
check(copp2_socp(problem, options, &a));
enum CoppStatus copp2_socp(struct Copp2Problem problem, struct CoppClarabelOptions options, struct CoppVecF64 *out_a)
Solve a COPP2-SOCP problem.
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.
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.
size_t num_objectives
Number of objective descriptors.
Shared Clarabel options for COPP SOCP solvers.
Definition core.h:627
Library-owned f64 vector returned to C.
Definition core.h:828
Safety
problem.robot must be a non-null handle returned by copp_robot_create and must remain valid for the duration of this call. problem.objectives must be valid for problem.num_objectives reads when problem.num_objectives is non-zero. If the robot has a stored inverse-dynamics callback, it must remain valid for this call. The robot must not be freed or mutated concurrently during the solve. out_a must be valid for one CoppVecF64 write.

◆ copp2_socp_expert()

enum CoppStatus copp2_socp_expert ( struct Copp2Problem problem,
struct CoppClarabelOptions options,
struct Copp2SocpResult * out_result )

Solve a COPP2-SOCP problem and always return Clarabel diagnostics.

This expert entry follows the advanced-diagnostics convention: true runtime failures still return a non-OK CoppStatus, but non-accepted Clarabel statuses are reported inside out_result with has_a == false and the function returns COPP_STATUS_OK.

Example

The example below distinguishes C ABI failures from non-accepted Clarabel solves and then frees all expert buffers.

struct Copp2SocpResult result = {0};
enum CoppStatus status = copp2_socp_expert(problem, options, &result);
if (status != COPP_STATUS_OK) {
fprintf(stderr, "COPP failed: %s\n", copp_last_error_message());
} else if (!result.has_a) {
fprintf(stderr,
"Clarabel status=%d iterations=%u r_prim=%.3e r_dual=%.3e\n",
(int)result.solver_status,
result.iterations,
result.r_prim,
result.r_dual);
} else {
printf("accepted profile length: %zu\n", result.a.len);
}
void copp2_socp_result_free(struct Copp2SocpResult result)
Release memory owned by a Copp2SocpResult.
enum CoppStatus copp2_socp_expert(struct Copp2Problem problem, struct CoppClarabelOptions options, struct Copp2SocpResult *out_result)
Solve a COPP2-SOCP problem and always return Clarabel diagnostics.
CoppStatus
C ABI status code returned by COPP FFI functions.
Definition core.h:34
const char * copp_last_error_message(void)
Return the current thread's last detailed error message as UTF-8.
@ COPP_STATUS_OK
Operation completed successfully.
Definition core.h:38
Compact COPP2-SOCP expert result returned to C.
Definition copp2.h:38
struct CoppVecF64 a
Accepted a profile, or an empty vector when has_a == false.
Definition copp2.h:46
enum CoppClarabelSolverStatus solver_status
Final Clarabel solver status.
Definition copp2.h:62
bool has_a
Whether a contains an accepted a(s) = (ds/dt)^2 profile.
Definition copp2.h:42
uint32_t iterations
Number of interior-point iterations.
Definition copp2.h:78
double r_dual
Dual residual reported by Clarabel.
Definition copp2.h:86
double r_prim
Primal residual reported by Clarabel.
Definition copp2.h:82
size_t len
Number of initialized elements.
Definition core.h:836
Safety
Same safety requirements as copp2_socp. out_result must be valid for one Copp2SocpResult write and must later be released with copp2_socp_result_free.

◆ copp2_socp_result_free()

void copp2_socp_result_free ( struct Copp2SocpResult result)

Release memory owned by a Copp2SocpResult.

Passing an already-freed result is invalid. Prefer freeing the full result with this function instead of freeing result.a manually.