COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
copp3_socp.cpp
Go to the documentation of this file.
1// Tutorial example: solve a minimal COPP3-SOCP problem.
2//
3// COPP3 combines third-order constraints with COPP objectives. This example
4// uses a single time objective and expert output so objective diagnostics can be
5// inspected when Clarabel accepts the profile.
6
7#include <iostream>
8#include <vector>
9
10#include <copp/copp.hpp>
11
12int main()
13{
14 // Step 1: Minimal raw constraints: station grid plus first-order bound.
15 std::vector<double> s{0.0, 0.5, 1.0};
16 std::vector<double> amax{1.0, 1.0, 1.0};
17 std::vector<double> a_linearization{0.25, 0.25, 0.25};
18
19 copp::Robot robot(1, s.size());
20 robot.append_s(s);
21 robot.constraints().add_constraint_1st(amax, 0);
22
23 const copp::Boundary3 boundary{0.25, 0.25, 0.0, 0.0};
24
25 namespace copp3 = copp::solver::copp3_socp;
26
27 // Step 2: Build a COPP3 problem. The constructor borrows `robot`, copies
28 // objectives and `a_linearization`, then linearizes third-order constraints.
29 copp3::Problem problem{
30 robot,
32 a_linearization,
33 0,
34 boundary,
35 };
36
37 // Step 3: Allow AlmostSolved for this tiny example and request diagnostics.
39 options.allow_almost_solved = true;
40
41 auto expert = copp3::solve_expert(problem, options);
42 if (!expert.profile)
43 {
44 std::cerr << "Clarabel did not return an accepted profile\n";
45 return 1;
46 }
47
48 // Step 4: Integrate the accepted third-order profile.
49 auto time = copp::interpolation::s_to_t_topp3(s, *expert.profile, 0.0);
50
51 std::cout << "COPP3-SOCP done.\n";
52 std::cout << "profile length = " << expert.profile->len() << "\n";
53 std::cout << "t_final = " << time.t_final << "\n";
54 if (expert.objective_value)
55 {
56 std::cout << "objective = " << *expert.objective_value << "\n";
57 }
58
59 return 0;
60}
ConstraintsRef & add_constraint_1st(Span< const double > amax, std::size_t idx_s)
Add or tighten first-order constraints from a vector.
Robot facade backed by Rust Robot<CppRobotModel>.
Definition robot.hpp:318
ConstraintsRef constraints() noexcept
Return a borrowed raw constraint-buffer facade.
Robot & append_s(Span< const double > s)
Append strictly increasing path station samples.
int main()
COPP_API TimeProfile s_to_t_topp3(Span< const double > s, const Profile3rd &profile, double t0=0.0)
Convert a third-order profile to cumulative time t(s).
Objective Time(double weight=1.0)
Third-order convex-objective Clarabel SOCP backend with COPP objective support and expert objective/s...
Third-order endpoint boundary values.
Definition core.hpp:87
Shared Clarabel options for COPP/TOPP SOCP-style solvers.
Definition clarabel.hpp:117