COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
path_from_parametric.cpp
Go to the documentation of this file.
1// Tutorial example: construct a path from a scalar parametric formula.
2//
3// `copp::Jet3` carries value, first, second, and third derivatives with respect
4// to the path parameter `s`, so ordinary-looking math can produce all geometric
5// derivatives needed by TOPP2/TOPP3.
6
7#include <cmath>
8#include <iostream>
9#include <vector>
10
11#include <copp/copp.hpp>
12
13int main()
14{
15 // Step 1: Return one `Jet3` per path dimension. COPP probes this callback
16 // to infer `dim`, then evaluates it with derivative seed `ds/ds = 1`.
18 [](copp::Jet3 s) {
19 return std::vector<copp::Jet3>{
20 copp::sin(s),
21 copp::cos(2.0 * s),
22 };
23 },
24 0.0,
25 1.0);
26
27 // Step 2: Evaluate all derivatives up to third order at three samples.
28 std::vector<double> samples{0.0, 0.5, 1.0};
29 auto out = path.evaluate_up_to_3rd(samples);
30
31 // Step 3: Optional derivative matrices are populated according to the
32 // evaluation method. Here `dq`, `ddq`, and `dddq` are all present.
33 std::cout << "dim = " << path.dim() << "\n";
34 std::cout << "q(0, 1) = " << out.q(0, 1) << "\n";
35 std::cout << "dq(0, 1) = " << out.dq.value()(0, 1) << "\n";
36 std::cout << "ddq(0, 1) = " << out.ddq.value()(0, 1) << "\n";
37 std::cout << "dddq(0, 1) = " << out.dddq.value()(0, 1) << "\n";
38}
static Path from_parametric(PathParametric parametric, double s_min, double s_max)
Build a path from a scalar-parametric formula.
PathDerivatives evaluate_up_to_3rd(Span< const double > s) const
Evaluate position, first derivative, second derivative, and third derivative.
Jet3 sin(Jet3 x) noexcept
Definition path.hpp:156
Jet3 cos(Jet3 x) noexcept
Definition path.hpp:169
int main()
Third-order forward-mode automatic-differentiation scalar.
Definition path.hpp:44