COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
path_from_evaluator_3rd.cpp
Go to the documentation of this file.
1// Tutorial example: construct a path from a batch third-order evaluator.
2//
3// Third-order evaluators are required for jerk constraints and TOPP3/COPP3
4// workflows. They can also serve lower-order path requests when a TOPP2 solver
5// only needs q/dq/ddq.
6
7#include <cmath>
8#include <cstddef>
9#include <iostream>
10#include <vector>
11
12#include <copp/copp.hpp>
13
14int main()
15{
16 constexpr std::size_t dim = 2;
17
18 // Step 1: Fill q, dq, ddq, and dddq for every sample. The callback owns no
19 // buffers; all output storage is borrowed from COPP for this call.
21 dim,
22 0.0,
23 1.0,
28 copp::MatrixRef dddq) {
29 for (std::size_t j = 0; j < s.size(); ++j)
30 {
31 const double x = s[j];
32 q(0, j) = x * x * x;
33 dq(0, j) = 3.0 * x * x;
34 ddq(0, j) = 6.0 * x;
35 dddq(0, j) = 6.0;
36
37 q(1, j) = std::sin(x);
38 dq(1, j) = std::cos(x);
39 ddq(1, j) = -std::sin(x);
40 dddq(1, j) = -std::cos(x);
41 }
42 });
43
44 // Step 2: Query all derivatives. Each result matrix has shape `(2 x 3)`.
45 std::vector<double> samples{0.0, 0.5, 1.0};
46 auto out = path.evaluate_up_to_3rd(samples);
47
48 // Step 3: Inspect the cubic coordinate at the final sample.
49 std::cout << "dim = " << path.dim() << "\n";
50 std::cout << "q(0, 2) = " << out.q(0, 2) << "\n";
51 std::cout << "dq(0, 2) = " << out.dq.value()(0, 2) << "\n";
52 std::cout << "ddq(0, 2) = " << out.ddq.value()(0, 2) << "\n";
53 std::cout << "dddq(0, 2) = " << out.dddq.value()(0, 2) << "\n";
54}
Mutable column-major matrix view used by callback APIs.
Definition core.hpp:288
static Path from_evaluator_3rd(std::size_t dim, double s_min, double s_max, PathEvaluator3rd evaluator)
Build a path from a batch evaluator with explicit derivatives up to third order.
PathDerivatives evaluate_up_to_3rd(Span< const double > s) const
Evaluate position, first derivative, second derivative, and third derivative.
Non-owning view of a contiguous one-dimensional array.
Definition core.hpp:139
constexpr std::size_t size() const noexcept
Definition core.hpp:169