COPP C++ API 0.2.3
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
copp::ConstraintsRef Class Reference

Non-owning view of a Rust-backed constraint buffer. More...

#include <robot.hpp>

Public Member Functions

 ConstraintsRef () noexcept=default
bool valid () const noexcept
 Return whether this reference points to a live bridge handle.
std::size_t dim () const
 Return the robot/path dimension.
std::size_t len () const
 Return the number of stored path stations.
std::size_t size () const
 Alias for len(), useful for STL-style code.
std::size_t capacity () const
 Return the allocated station-buffer capacity.
bool is_empty () const
 Return whether no path stations are stored.
std::pair< std::size_t, std::size_t > idx_s_range () const
 Return the active global station-id interval [first, second).
ConstraintsRef & append_s (Span< const double > s)
 Append strictly increasing path station samples.
std::vector< double > s_values (std::size_t idx_s_from, std::size_t idx_s_to) const
 Export stored station samples over [idx_s_from, idx_s_to).
std::vector< double > amax_values (std::size_t idx_s_from, std::size_t idx_s_to) const
 Export first-order upper bounds over [idx_s_from, idx_s_to).
double s_value (std::size_t idx_s) const
 Read one stored station sample by global station id.
double amax_value (std::size_t idx_s) const
 Read one first-order upper bound by global station id.
ConstraintsRef & amax_substitute (Span< const double > amax, std::size_t idx_s)
 Overwrite first-order upper bounds starting at idx_s.
ConstraintsRef & clear (bool keep_idx_s=false)
 Clear all stored stations and constraints.
ConstraintsRef & pop_front_n (std::size_t n_cols)
 Remove n_cols logical stations from the front.
ConstraintsRef & pop_back_n (std::size_t n_cols)
 Remove n_cols logical stations from the back.
ConstraintsRef & pop_front_until (std::size_t idx_s_cut)
 Remove front stations until the kept window starts at idx_s_cut.
ConstraintsRef & pop_back_until (std::size_t idx_s_cut)
 Remove back stations until the kept window ends at or before idx_s_cut.
ConstraintsRef & add_constraint_1st (Span< const double > amax, std::size_t idx_s)
 Add or tighten first-order constraints from a vector.
ConstraintsRef & add_constraint_1st (MatrixView amax, std::size_t idx_s)
 Add or tighten first-order constraints from an R x N matrix.
ConstraintsRef & add_constraint_2nd (MatrixView acc_a, MatrixView acc_b, MatrixView acc_max, std::size_t idx_s, bool is_negative=false)
 Append second-order raw constraint rows.
ConstraintsRef & add_constraint_3rd (MatrixView jerk_a, MatrixView jerk_b, MatrixView jerk_c, MatrixView jerk_d, MatrixView jerk_max, std::size_t idx_s, bool is_negative=false)
 Append third-order raw constraint rows.
std::array< double, 2 > exceed_topp2 (Span< const double > a, std::size_t idx_s_start=0) const
 Evaluate the maximum TOPP2 constraint violation of a node profile.
std::array< double, 3 > exceed_topp3 (Span< const double > a, Span< const double > b, std::size_t num_stationary_start, std::size_t num_stationary_end, std::size_t idx_s_start=0) const
 Evaluate the maximum TOPP3 constraint violation of a node profile (a, b).
std::array< double, 3 > exceed_topp3 (const Profile3rd &profile, std::size_t idx_s_start=0) const
 Evaluate exceed_topp3 for an owned third-order profile.

Friends

class Robot
class Constraints
const void * detail::constraints_handle (ConstraintsRef constraints) noexcept
void * detail::constraints_handle_mut (ConstraintsRef constraints) noexcept

Detailed Description

Non-owning view of a Rust-backed constraint buffer.

ConstraintsRef is returned by Robot::constraints() and by Constraints::ref(). It is intentionally lightweight and copyable: it only stores a borrowed pointer to an owning C++ facade object. The owner must outlive every copied reference.

The first C++ milestone mirrors the Python Constraints surface for raw TOPP constraints: station management, first-order bound replacement, and raw first-/second-/third-order constraint rows. Physical velocity, acceleration, jerk, and torque limits live on Robot, because they need path derivative data and robot semantics.

Definition at line 87 of file robot.hpp.

Constructor & Destructor Documentation

◆ ConstraintsRef()

copp::ConstraintsRef::ConstraintsRef ( )
defaultnoexcept

Member Function Documentation

◆ valid()

bool copp::ConstraintsRef::valid ( ) const
noexcept

Return whether this reference points to a live bridge handle.

◆ dim()

std::size_t copp::ConstraintsRef::dim ( ) const

Return the robot/path dimension.

◆ len()

std::size_t copp::ConstraintsRef::len ( ) const

Return the number of stored path stations.

◆ size()

std::size_t copp::ConstraintsRef::size ( ) const

Alias for len(), useful for STL-style code.

◆ capacity()

std::size_t copp::ConstraintsRef::capacity ( ) const

Return the allocated station-buffer capacity.

◆ is_empty()

bool copp::ConstraintsRef::is_empty ( ) const

Return whether no path stations are stored.

◆ idx_s_range()

std::pair< std::size_t, std::size_t > copp::ConstraintsRef::idx_s_range ( ) const

Return the active global station-id interval [first, second).

◆ append_s()

ConstraintsRef & copp::ConstraintsRef::append_s ( Span< const double > s)

Append strictly increasing path station samples.

The values are borrowed only for this call. If the buffer is not empty, the first new sample must be greater than the current last stored station.

Parameters
sNew station samples in strictly increasing order.
Returns
*this for chaining.
Exceptions
copp::Errorif station order or range validation fails.

◆ s_values()

std::vector< double > copp::ConstraintsRef::s_values ( std::size_t idx_s_from,
std::size_t idx_s_to ) const

Export stored station samples over [idx_s_from, idx_s_to).

◆ amax_values()

std::vector< double > copp::ConstraintsRef::amax_values ( std::size_t idx_s_from,
std::size_t idx_s_to ) const

Export first-order upper bounds over [idx_s_from, idx_s_to).

◆ s_value()

double copp::ConstraintsRef::s_value ( std::size_t idx_s) const

Read one stored station sample by global station id.

◆ amax_value()

double copp::ConstraintsRef::amax_value ( std::size_t idx_s) const

Read one first-order upper bound by global station id.

◆ amax_substitute()

ConstraintsRef & copp::ConstraintsRef::amax_substitute ( Span< const double > amax,
std::size_t idx_s )

Overwrite first-order upper bounds starting at idx_s.

Unlike add_constraint_1st, this replaces amax values instead of taking the elementwise minimum. It is mainly used by reachability algorithms that refine an existing profile.

◆ clear()

ConstraintsRef & copp::ConstraintsRef::clear ( bool keep_idx_s = false)

Clear all stored stations and constraints.

If keep_idx_s is true, the current global station origin is kept; otherwise it is reset to zero.

◆ pop_front_n()

ConstraintsRef & copp::ConstraintsRef::pop_front_n ( std::size_t n_cols)

Remove n_cols logical stations from the front.

◆ pop_back_n()

ConstraintsRef & copp::ConstraintsRef::pop_back_n ( std::size_t n_cols)

Remove n_cols logical stations from the back.

◆ pop_front_until()

ConstraintsRef & copp::ConstraintsRef::pop_front_until ( std::size_t idx_s_cut)

Remove front stations until the kept window starts at idx_s_cut.

◆ pop_back_until()

ConstraintsRef & copp::ConstraintsRef::pop_back_until ( std::size_t idx_s_cut)

Remove back stations until the kept window ends at or before idx_s_cut.

◆ add_constraint_1st() [1/2]

ConstraintsRef & copp::ConstraintsRef::add_constraint_1st ( Span< const double > amax,
std::size_t idx_s )

Add or tighten first-order constraints from a vector.

The input represents one amax value per station. Stored amax is updated as the elementwise minimum of the existing and new values.

Parameters
amaxNode-based upper bounds for a = (ds/dt)^2.
idx_sGlobal station id of amax[0].

◆ add_constraint_1st() [2/2]

ConstraintsRef & copp::ConstraintsRef::add_constraint_1st ( MatrixView amax,
std::size_t idx_s )

Add or tighten first-order constraints from an R x N matrix.

Each matrix column is reduced to its minimum before being fused into the stored amax row. This matches Rust/Python raw constraint semantics.

◆ add_constraint_2nd()

ConstraintsRef & copp::ConstraintsRef::add_constraint_2nd ( MatrixView acc_a,
MatrixView acc_b,
MatrixView acc_max,
std::size_t idx_s,
bool is_negative = false )

Append second-order raw constraint rows.

For every station column, each row encodes acc_a * a + acc_b * b <= acc_max. If is_negative is true, the row is inserted with signs flipped; this is how lower bounds are represented internally.

Parameters
acc_aMatrix of a coefficients.
acc_bMatrix of b = dds/dt coefficients.
acc_maxMatrix of right-hand sides.
idx_sGlobal station id of the first column.
is_negativeWhether to insert the sign-flipped lower-bound row.

◆ add_constraint_3rd()

ConstraintsRef & copp::ConstraintsRef::add_constraint_3rd ( MatrixView jerk_a,
MatrixView jerk_b,
MatrixView jerk_c,
MatrixView jerk_d,
MatrixView jerk_max,
std::size_t idx_s,
bool is_negative = false )

Append third-order raw constraint rows.

For every station column, each row encodes sqrt(a) * (jerk_a*a + jerk_b*b + jerk_c*c + jerk_d) <= jerk_max. Linearization is performed later by TOPP3/COPP3 problem builders.

Parameters
jerk_aCoefficient matrix multiplying a.
jerk_bCoefficient matrix multiplying b.
jerk_cCoefficient matrix multiplying third-order control c.
jerk_dConstant term matrix.
jerk_maxRight-hand-side matrix.
idx_sGlobal station id of the first column.
is_negativeWhether to insert the sign-flipped lower-bound row.

◆ exceed_topp2()

std::array< double, 2 > copp::ConstraintsRef::exceed_topp2 ( Span< const double > a,
std::size_t idx_s_start = 0 ) const

Evaluate the maximum TOPP2 constraint violation of a node profile.

a holds a = (ds/dt)^2 on consecutive stations starting at idx_s_start. Each interval's path acceleration is reconstructed as b[k] = (a[k+1] - a[k]) / (2 ds[k]) and checked against the second-order rows of both endpoint stations.

Parameters
aNode profile to check.
idx_s_startGlobal station id of a[0].
Returns
{exceed_1st, exceed_2nd}, each <= 0 when feasible and positive (the violation magnitude) when violated. The first-order term covers 0 <= a[k] <= amax[k]. Both entries are NaN when the station range is unavailable or b cannot be reconstructed from a.

◆ exceed_topp3() [1/2]

std::array< double, 3 > copp::ConstraintsRef::exceed_topp3 ( Span< const double > a,
Span< const double > b,
std::size_t num_stationary_start,
std::size_t num_stationary_end,
std::size_t idx_s_start = 0 ) const

Evaluate the maximum TOPP3 constraint violation of a node profile (a, b).

The third-order term uses the original nonlinear sqrt(a) * (jerk_a*a + jerk_b*b + jerk_c*c + jerk_d) <= jerk_max form with c = (b[k+1] - b[k]) / ds[k], not the linearized rows, and skips the two stationary boundary blocks. It checks the profile that is actually delivered, so run it after post-processing such as Profile3rd::force_positive_a.

Parameters
aNode profile a = (ds/dt)^2.
bNode profile b = d^2s/dt^2, same length as a.
num_stationary_startStationary intervals at the start.
num_stationary_endStationary intervals at the end.
idx_s_startGlobal station id of a[0].
Returns
{exceed_1st, exceed_2nd, exceed_3rd}, each <= 0 when feasible and positive when violated. All entries are NaN when the station range is unavailable, a and b disagree in length, fewer than two stations are given, or a or b contains a non-finite value.

◆ exceed_topp3() [2/2]

std::array< double, 3 > copp::ConstraintsRef::exceed_topp3 ( const Profile3rd & profile,
std::size_t idx_s_start = 0 ) const

Evaluate exceed_topp3 for an owned third-order profile.

◆ Robot

friend class Robot
friend

Definition at line 266 of file robot.hpp.

◆ Constraints

friend class Constraints
friend

Definition at line 267 of file robot.hpp.

◆ detail::constraints_handle

const void * detail::constraints_handle ( ConstraintsRef constraints)
friend

◆ detail::constraints_handle_mut

void * detail::constraints_handle_mut ( ConstraintsRef constraints)
friend

The documentation for this class was generated from the following file: