Class Trajectory

Nested Relationships

Nested Types

Class Documentation

class Trajectory

Public Types

using iterator = base_iterator<Waypoint>
using const_iterator = base_iterator<const Waypoint>

Public Functions

Trajectory()

Create an empty Trajectory.

Trajectory(const Trajectory &other)
Trajectory &operator=(const Trajectory &other)
Trajectory(Trajectory&&) = default

Warning

After using the move constructor or move assignment operator, the Trajectory that was moved from will be unusable until a fresh Trajectory instance is assigned to it (using either the copy or move constructor). Attempting to use a Trajectory that was moved from will result in a segfault if you do not assign it a new instance.

Trajectory &operator=(Trajectory&&) = default
InsertionResult insert(Time time, Eigen::Vector3d position, Eigen::Vector3d velocity)

Add a Waypoint to this Trajectory.

The Waypoint will be inserted into the Trajectory according to its time, ensuring correct ordering of all Waypoints.

InsertionResult insert(const Waypoint &other)

Insert a copy of another Trajectory’s Waypoint into this one.

iterator find(Time time)

Find the Waypoint of this Trajectory that comes after or exactly on the given time.

Note

This will return Trajectory::end() if the time is before the Trajectory starts or after the Trajectory finishes.

Parameters:

time[in] The time of interest.

Returns:

an iterator to the Waypoint that is active during the given time, or Trajectory::end() if the time falls outside the range of the Trajectory

const_iterator find(Time time) const

const-qualified version of find()

Waypoint &operator[](std::size_t index)

Get a reference to the Waypoint at the specified index. No bounds checking is performed, so there will be undefined behavior if the index is out of bounds.

const Waypoint &operator[](std::size_t index) const

Const-qualified index operator.

Waypoint &at(std::size_t index)

Get a reference to the Waypoint at the specified index. Bound checking will be performed, and an exception will be thrown if index is out of bounds.

const Waypoint &at(std::size_t index) const

Const-qualified at()

iterator lower_bound(Time time)

Get the first waypoint of this Trajectory that occurs at a time greater than or equal to the specified time. This is effectively the same as find(Time), except it will return Trajectory::begin() if the time comes before the start of the Trajectory.

Parameters:

time[in] The inclusive lower bound on the time of interest.

Returns:

an iterator to the first Waypoint that occurs at a time on or after the given time, or Trajectory::end() if the time is after the end of the Trajectory.

const_iterator lower_bound(Time time) const

const-qualified version of lower_bound()

std::size_t index_after(Time time) const

Get the index of first waypoint that comes after the specified time. If the last waypoint in the trajectory comes before the specified time then size() will be returned.

iterator erase(iterator waypoint)

Erase the specified waypoint.

Returns:

an iterator following the last removed element

iterator erase(iterator first, iterator last)

Erase the range of elements: [first, last).

Note

The last element is not included in the range.

Returns:

an iterator following the last removed element

iterator begin()

Returns an iterator to the fist Waypoint of the Trajectory.

If the Trajectory is empty, the returned iterator will be equal to end().

const_iterator begin() const

const-qualified version of begin()

const_iterator cbegin() const

Explicitly call the const-qualified version of begin()

iterator end()

Returns an iterator to the element following the last Waypoint of the Trajectory. This iterator acts as a placeholder; attempting to dereference it results in undefined behavior.

Note

In compliance with C++ standards, this is really a one-past-the-end iterator and must not be dereferenced. It should only be used to identify when an iteration must end. See: https://en.cppreference.com/w/cpp/container/list/end

const_iterator end() const

const-qualified version of end()

const_iterator cend() const

Explicitly call the const-qualified version of end()

Waypoint &front()

Get a mutable reference to the first Waypoint in this Trajectory.

Warning

Calling this function on an empty trajectory is undefined.

const Waypoint &front() const

Get a const reference to the first Waypoint in this Trajectory.

Warning

Calling this function on an empty trajectory is undefined.

Waypoint &back()

Get a mutable reference to the last Waypoint in this Trajectory.

Warning

Calling this function on an empty trajectory is undefined.

const Waypoint &back() const

Get a const reference to the last Waypoint in this Trajectory.

Warning

Calling this function on an empty trajectory is undefined.

const Time *start_time() const

Get the start time, if available. This will return a nullptr if the Trajectory is empty.

const Time *finish_time() const

Get the finish time of the Trajectory, if available. This will return a nullptr if the Trajectory is empty.

Duration duration() const

Get the duration of the Trajectory. This will be 0 if the Trajectory is empty or if it has only one Waypoint.

std::size_t size() const

Get the number of Waypoints in the Trajectory. To be used in conflict detection, the Trajectory must have a size of at least 2.

bool empty() const

Return true if the trajectory has no waypoints, false otherwise.

Friends

friend class internal::TrajectoryIteratorImplementation
template<typename W>
class base_iterator

Public Functions

W &operator*() const

Dereference operator.

W *operator->() const

Drill-down operator.

base_iterator &operator++()

Pre-increment operator: ++it

Note

This is more efficient than the post-increment operator.

Returns:

a reference to the iterator that was operated on

base_iterator &operator--()

Pre-decrement operator: &#8212;it

Note

This is more efficient than the post-decrement operator

Returns:

a reference to the iterator that was operated on

base_iterator operator++(int)

Post-increment operator: it++

Returns:

a copy of the iterator before it was incremented

base_iterator operator--(int)

Post-decrement operator: it&#8212;

Returns:

a copy of the iterator before it was decremented

base_iterator operator+(int offset) const

Get the iterator that would be offset from this one by the specified amount

base_iterator operator-(int offset) const

Get the iterator that would be offset from this one by the specified amount in the opposite direction.

bool operator==(const base_iterator &other) const

Equality comparison operator.

bool operator!=(const base_iterator &other) const

Inequality comparison operator.

bool operator<(const base_iterator &other) const

Less-than comparison operator (the left-hand side is earlier in the trajectory than the right-hand side)

bool operator>(const base_iterator &other) const

Greater-than comparison operator (the left-hand side is later in the trajectory than the right-hand side)

bool operator<=(const base_iterator &other) const

Less-than-or-equal comparison operator.

bool operator>=(const base_iterator &other) const

Greater-than-or-equal comparison operator.

operator const_iterator() const
base_iterator(const base_iterator &other) = default
base_iterator(base_iterator &&other) = default
base_iterator &operator=(const base_iterator &other) = default
base_iterator &operator=(base_iterator &&other) = default
base_iterator()

Friends

friend class internal::TrajectoryIteratorImplementation
struct InsertionResult

Public Members

iterator it
bool inserted
class Waypoint

Public Functions

Eigen::Vector3d position() const

Get the intended physical location of the robot at the end of this Trajectory Waypoint.

This is a 2D homogeneous position. The first two values in the vector are x and y coordinates, while the third is rotation about the z-axis.

Waypoint &position(Eigen::Vector3d new_position)

Set the intended physical location of the robot at the end of this Trajectory Waypoint.

This is a 2D homogeneous position. The first two values in the vector are x and y coordinates, while the third is rotation about the z-axis.

Parameters:

new_position[in] The new position for this Trajectory Waypoint.

Eigen::Vector3d velocity() const

Get the intended velocity of the robot at the end of this Trajectory Waypoint.

This is a 2D homogeneous position. The first two values in the vector are x and y velocities, while the third is rotational velocity about the z-axis.

Waypoint &velocity(Eigen::Vector3d new_velocity)

Set the intended velocity of the robot at the end of this Trajectory Waypoint.

This is a 2D homogeneous position. The first two values in the vector are x and y coordinates, while the third is rotation about the z-axis.

Parameters:

new_velocity[in] The new velocity at this Trajectory Waypoint.

Time time() const

Get the time that the trajectory will reach this Waypoint.

std::size_t index() const

The index of this waypoint within its trajectory. Waypoints are indexed according to their chronological order. Adjusting the time of any waypoint in a trajectory could change its index and/or the index of other waypoints.

Waypoint &change_time(Time new_time)

Change the timing of this Trajectory Waypoint. Note that this function will only affect this waypoint, and may cause this waypoint to be reordered within the Trajectory.

To change the timing for this waypoint while preserving the relative times of all subsequent Trajectory Waypoints, use adjust_times() instead.

See also

adjust_times(Time new_time)

Note

If this Waypoint’s time crosses over another Waypoint’s time, that signficantly changes the topology of the Trajectory, because it will change the order in which the positions are traversed.

Warning

If you change the time value of this Waypoint such that it falls directly on another Waypoint’s time, you will get a std::invalid_argument exception, because discontinuous jumps are not supported, and indicate a significant mishandling of trajectory data, which is most likely a serious bug that should be remedied.

Parameters:

new_time[in] The new timing for this Trajectory Waypoint.

void adjust_times(Duration delta_t)

Adjust the timing of this waypoint and all subsequent waypoints by the given duration. This is guaranteed to maintain the ordering of the Trajectory Waypoints, and is more efficient than changing all the times directly.

Warning

If a negative delta_t is given, it must not cause this Waypoint’s time to be less than or equal to the time of its preceding Waypoint, or else a std::invalid_argument exception will be thrown.

Parameters:

delta_t[in] How much to change the timing of this waypoint and all later waypoints. If negative, it must not cross over the time of the previous waypoint, or else a std::invalid_argument will be thrown.