COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
topp3_socp.cpp
Go to the documentation of this file.
1// Tutorial example: solve TOPP3-SOCP with two SCP refinement rounds.
2//
3// The SOCP formulation depends on a linearization profile. A common workflow is
4// to solve once with a simple initial `a0`, then rebuild the problem with the
5// recovered `profile.a` and solve again.
6
7#include <iostream>
8#include <vector>
9
10#include <copp/copp.hpp>
11
12int main()
13{
14 // Step 1: Minimal one-dimensional constraint setup.
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> a0{0.25, 0.25, 0.25};
18
19 copp::Constraints constraints(1, s.size());
20 constraints.append_s(s)
21 .add_constraint_1st(amax, 0);
22
23 // Step 2: Configure Clarabel and endpoint boundary values.
24 const copp::Boundary3 boundary{0.25, 0.25, 0.0, 0.0};
25
27 options.allow_almost_solved = true;
28
29 // Step 3: First SCP round using the hand-chosen linearization profile.
30 copp::solver::topp3::Problem first_problem{
31 constraints.ref(),
32 a0,
33 0,
34 boundary,
35 };
36 auto profile1 = copp::solver::topp3_socp::solve(first_problem, options);
37
38 // Step 4: Second SCP round using the previous `a` profile as the new
39 // linearization. More rounds can be added by repeating this pattern.
40 copp::solver::topp3::Problem second_problem{
41 constraints.ref(),
42 profile1.a,
43 0,
44 boundary,
45 };
46 auto profile2 = copp::solver::topp3_socp::solve(second_problem, options);
47
48 // Step 5: Interpolate the final third-order profile in time.
49 auto time = copp::interpolation::s_to_t_topp3(s, profile2, 0.0);
50
51 std::cout << "TOPP3-SOCP done with 2 refinement rounds.\n";
52 std::cout << "profile length = " << profile2.len() << "\n";
53 std::cout << "t_final = " << time.t_final << "\n";
54
55 return 0;
56}
Owning raw constraint-buffer facade.
Definition robot.hpp:245
Constraints & add_constraint_1st(Span< const double > amax, std::size_t idx_s)
Constraints & append_s(Span< const double > s)
ConstraintsRef ref() noexcept
Borrow this owning object as a solver/constraint reference.
Prepared TOPP3 problem descriptor.
Definition topp3.hpp:43
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).
COPP_API Profile3rd solve(const Problem &problem, const clarabel::Options &options={})
Solve TOPP3-SOCP and return an accepted third-order profile.
Third-order endpoint boundary values.
Definition core.hpp:87
Shared Clarabel options for COPP/TOPP SOCP-style solvers.
Definition clarabel.hpp:117
int main()