@@ -69,6 +69,9 @@ class Trajectory
6969 * acceleration respectively. Deduction assumes that the provided velocity or acceleration have to
7070 * be reached at the time defined in the segment.
7171 *
72+ * This function assumes that sampling is only done at monotonically increasing \p sample_time
73+ * for any trajectory.
74+ *
7275 * Specific case returns for start_segment_itr and end_segment_itr:
7376 * - Sampling before the trajectory start:
7477 * start_segment_itr = begin(), end_segment_itr = begin()
@@ -85,9 +88,12 @@ class Trajectory
8588 *
8689 * \param[in] sample_time Time at which trajectory will be sampled.
8790 * \param[in] interpolation_method Specify whether splines, another method, or no interpolation at
88- * all. \param[out] expected_state Calculated new at \p sample_time. \param[out] start_segment_itr
89- * Iterator to the start segment for given \p sample_time. See description above. \param[out]
90- * end_segment_itr Iterator to the end segment for given \p sample_time. See description above.
91+ * all.
92+ * \param[out] output_state Calculated new at \p sample_time.
93+ * \param[out] start_segment_itr Iterator to the start segment for given \p sample_time. See
94+ * description above.
95+ * \param[out] end_segment_itr Iterator to the end segment for given \p sample_time. See
96+ * description above.
9197 */
9298 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
9399 bool sample (
@@ -147,6 +153,14 @@ class Trajectory
147153 JOINT_TRAJECTORY_CONTROLLER_PUBLIC
148154 bool is_sampled_already () const { return sampled_already_; }
149155
156+ // / Get the index of the segment start returned by the last \p sample() operation.
157+ /* *
158+ * As the trajectory is only accessed at monotonically increasing sampling times, this index is
159+ * used to speed up the selection of relevant trajectory points.
160+ */
161+ JOINT_TRAJECTORY_CONTROLLER_PUBLIC
162+ size_t last_sample_index () const { return last_sample_idx_; }
163+
150164private:
151165 void deduce_from_derivatives (
152166 trajectory_msgs::msg::JointTrajectoryPoint & first_state,
@@ -160,6 +174,7 @@ class Trajectory
160174 trajectory_msgs::msg::JointTrajectoryPoint state_before_traj_msg_;
161175
162176 bool sampled_already_ = false ;
177+ size_t last_sample_idx_ = 0 ;
163178};
164179
165180/* *
0 commit comments