Skip to content

Trajectory classes - #270

Open
domire8 wants to merge 2 commits into
mainfrom
staging/trajectory
Open

Trajectory classes#270
domire8 wants to merge 2 commits into
mainfrom
staging/trajectory

Conversation

@domire8

@domire8 domire8 commented Apr 16, 2026

Copy link
Copy Markdown
Member

Description

It is time to revisit the implementation of trajectory classes from some time ago. Please review this while keeping all our work on different trajectory controllers in mind, asking yourself what do I need from a trajectory representation, what interfaces would be convenient?

Currently, the proposed implementation has the following interfaces:

  • get_duration by index
  • get_durations all of them
  • get_time_from_start by index
  • get_times_from_start all of them
  • get_trajectory_duration
  • get_size
  • delete_point the last one, or by index
  • reset
  • get_points get all states
  • get_point get the state by index
  • add_point with state + duration
  • add_points with states + durations
  • insert_point with state and duration by index
  • set_point with state and duration by index
  • set_points with all states and durations
  • operator[] to get pair<state, duration> by index
  • Additionally, Cartesian trajectories have an associated reference frame
  • Joint trajectories have associated joint names

Something that I don't like a loot is that we don't have getters for the durations in double but only std::chrono::nanoseconds but at the same time, we usually have to translate to a ROS message anyway so it doesn't really matter. It's also more correct to use std::chrono types.

Review guidelines

Estimated Time of Review: 15 minutes

Checklist before merging:

  • Confirm that the relevant changelog(s) are up-to-date in case of any user-facing changes

@domire8
domire8 force-pushed the staging/trajectory branch from f3b47f1 to a59e74b Compare April 27, 2026 13:14
ANALOG_IO_STATE = 19,
CARTESIAN_TRAJECTORY = 20,
JOINT_TRAJECTORY = 21,
#ifdef EXPERIMENTAL_FEATURES

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be time to remove those

@domire8

domire8 commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

NOTE: this is a staging branch. I would invite you to review these changes as a baseline for what is to come next. Once I have approval for this part, I will open PRs for python implementation as well as the clproto updates next.

@domire8
domire8 marked this pull request as ready for review April 27, 2026 13:38
@domire8
domire8 requested a review from eeberhard as a code owner April 27, 2026 13:38
@domire8
domire8 force-pushed the staging/trajectory branch from a59e74b to a43c74c Compare April 29, 2026 07:50
@domire8
domire8 requested review from SprGrf and yrh012 April 29, 2026 07:50
/**
* @brief Delete the last point from trajectory
*/
void delete_point();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just the next?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the next what?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the delete_point by index. But I imagine it's just handy.

* @param points vector of new points
* @throw IncompatibleSizeException if points vector is empty
*/
void set_points(const std::vector<TrajectoryT>& points);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to provide exactly the points size of the current trajectory, maybe that should be mentioned

/**
* @brief Set the trajectory points from a vector of points
* @param points vector of new points
* @throw IncompatibleSizeException if points vector is empty

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or if the provided points size does not match the current size

Comment on lines +137 to +160
void add_point(const TrajectoryT& new_point);

/**
* @brief Add new points to trajectory
* @param new_point the new point
* @throw IncompatibleSizeException if points vector is empty
*/
void add_points(const std::vector<TrajectoryT>& new_points);

/**
* @brief Insert new trajectory point between two already existing points
* @param new_point the new point
* @param index the desired position of the new point in the queue
* @throw std::out_of_range if index is out of range
*/
void insert_point(const TrajectoryT& new_point, unsigned int index);

/**
* @brief Set the trajectory point at given index
* @param point the new point
* @param index the index
* @throw std::out_of_range if index is out of range
*/
void set_point(const TrajectoryT& point, unsigned int index);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you read through it's obvious what each does, but I feel we could maybe merge 'add' and 'insert' with an overload maybe.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be neat indeed and it would also resolve the previous point about insert_points

* @param joint_names the joint names of the trajectory point
* @return the joint state representation of the trajectory point
*/
JointState to_joint_state(const std::vector<std::string>& joint_names) const {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about the opposite/symmetric in JointState?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both in this and the next comment: a method to_trajectory_point for Joint/CartesianStates. But now that I see this again, not sure how beneficial it would be, the constructor is easy enough to use, and you would would have to provide the duration either way.

* @param reference_frame the underlying reference frame of the trajectory point
* @return the Cartesian state representation of the trajectory point
*/
CartesianState to_cartesian_state(const std::string& reference_frame) const {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines +96 to +97
* @brief Get list of trajectory points
* @return queue of the Cartesian states of the trajectory

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed, but probably exists before; are we using points and states interchangeably? I am afraid it might get a bit confusing. Especially since we are returning actual points from the base class, but states from here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can see where you are coming from, let me think about it. But users should not bother with what's in the base class, those are not public interfaces of this class

* @param index the desired position of the new point in the queue
* @throw std::out_of_range if index is out of range
*/
void insert_point(const TrajectoryT& new_point, unsigned int index);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think we need an insert_points as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants