COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
Path Construction And Evaluation

copp::Path represents the geometric path q = q(s). Solvers do not optimize geometry; they optimize how quickly this already-defined path is traversed.

Include

or:

Output Shapes

Every batch evaluation uses a station vector s of length N and returns column-major matrices with shape (dim x N):

std::vector<double> samples{0.0, 0.5, 1.0};
auto out = path.evaluate_up_to_2nd(samples);
double q_axis0_at_mid = out.q(0, 1);
double dq_axis0_at_mid = out.dq.value()(0, 1);
double ddq_axis0_at_mid = out.ddq.value()(0, 1);

Waypoint Splines

Waypoint paths are the easiest entry point. Each inner initializer-list is one waypoint vector:

{0.0, 0.0},
{0.5, 0.25},
{1.0, 1.0},
});
auto range = path.s_range(); // {0.0, 1.0}
auto dim = path.dim(); // 2
static Path from_waypoints(MatrixView waypoints, SplineConfig config={})
Build a spline path from waypoint positions.
std::pair< double, double > s_range() const
Return the valid path-parameter interval (s_min, s_max).

If you already have a matrix, use the native COPP shape (dim x n_points):

auto waypoints = copp::Matrix::from_columns({
{0.0, 0.0},
{0.5, 0.25},
{1.0, 1.0},
});
auto path = copp::Path::from_waypoints(waypoints.view());
static Matrix from_columns(std::initializer_list< std::initializer_list< double > > columns)
Build a matrix from column-major initializer-list notation.
Definition core.hpp:433

The default spline configuration follows Rust/Python:

  • order 5
  • range [0, 1]
  • out-of-range behavior: error
  • zero boundary derivative states

Custom range and clamping:

config.s_min = -1.0;
config.s_max = 1.0;
auto path = copp::Path::from_waypoints(waypoints.view(), config);
@ Clamp
Clamp out-of-range query samples to the nearest endpoint.
Definition path.hpp:301
Configuration for waypoint spline construction.
Definition path.hpp:315
OutOfRangeMode out_of_range
Definition path.hpp:319

Scalar Parametric Paths

Path::from_parametric uses copp::Jet3 automatic differentiation. The callback receives a seeded scalar s; ordinary arithmetic and COPP math helpers propagate derivatives up to third order.

[](copp::Jet3 s) {
return std::vector<copp::Jet3>{
copp::cos(2.0 * s),
};
},
0.0,
1.0);
std::vector<double> samples{0.0, 0.5, 1.0};
auto out = path.evaluate_up_to_3rd(samples);
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
Third-order forward-mode automatic-differentiation scalar.
Definition path.hpp:44

For tighter loops, avoid allocating a vector inside every callback invocation by using the writer overload:

2,
0.0,
1.0,
q[0] = copp::powi(s, 3);
q[1] = copp::sin(s);
});
Non-owning view of a contiguous one-dimensional array.
Definition core.hpp:139
Jet3 powi(Jet3 x, int n) noexcept
Definition path.hpp:229

Supported helpers include sin, cos, exp, log/ln, sqrt, and powi.

Batch Evaluator Paths

Use evaluator paths when the path comes from an external model or when you already know analytic derivatives. The callback is batch-oriented to avoid crossing the C++/Rust bridge once per station.

2,
0.0,
1.0,
for (std::size_t j = 0; j < s.size(); ++j) {
const double x = s[j];
q(0, j) = x;
dq(0, j) = 1.0;
ddq(0, j) = 0.0;
q(1, j) = x * x;
dq(1, j) = 2.0 * x;
ddq(1, j) = 2.0;
}
});
Mutable column-major matrix view used by callback APIs.
Definition core.hpp:288
static Path from_evaluator_2nd(std::size_t dim, double s_min, double s_max, PathEvaluator2nd evaluator)
Build a path from a batch evaluator with explicit derivatives up to second order.
constexpr std::size_t size() const noexcept
Definition core.hpp:169

Third-order evaluators add dddq:

1,
0.0,
1.0,
for (std::size_t j = 0; j < s.size(); ++j) {
const double x = s[j];
q(0, j) = x * x * x;
dq(0, j) = 3.0 * x * x;
ddq(0, j) = 6.0 * x;
dddq(0, j) = 6.0;
}
});
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.

The path owns the callback object. Throw copp::Error or another std::exception from the callback to report evaluator failure.

Tutorial Sources