COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
topp3_lp.cpp
Go to the documentation of this file.
1// Tutorial example: solve a minimal third-order TOPP3-LP problem.
2//
3// TOPP3 introduces the node profile `a = dot{s}^2` and `b = ddot{s}`. A
4// `topp3::Problem` immediately linearizes third-order constraints at the
5// supplied `a_linearization` before the LP/SOCP solver is called.
6
7#include <iostream>
8#include <vector>
9
10#include <copp/copp.hpp>
11
12int main()
13{
14 // Step 1: Build a raw one-dimensional station/first-order 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> a_linearization{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: Choose boundary values and an initial linearization profile.
24 // Here the boundary speed is nonzero, so no stationary interval is inferred.
25 const copp::Boundary3 boundary{0.25, 0.25, 0.0, 0.0};
27 constraints.ref(),
28 a_linearization,
29 0,
30 boundary,
31 };
32
33 // Step 3: Solve the LP formulation and convert the profile to time.
35 options.allow_almost_solved = true;
36
37 auto profile = copp::solver::topp3_lp::solve(problem, options);
38 auto time = copp::interpolation::s_to_t_topp3(s, profile, 0.0);
39
40 std::cout << "TOPP3-LP done.\n";
41 std::cout << "profile length = " << profile.len() << "\n";
42 std::cout << "stationary start/end = "
43 << profile.num_stationary_start << " / "
44 << profile.num_stationary_end << "\n";
45 std::cout << "t_final = " << time.t_final << "\n";
46
47 return 0;
48}
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-LP 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()
Definition topp3_lp.cpp:12