Skip to content

Commit

Permalink
feat: add function that returns the total trajectory duration
Browse files Browse the repository at this point in the history
  • Loading branch information
bpapaspyros committed Jan 31, 2025
1 parent 822401b commit bd0c01c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class TrajectoryBase : public State {
*/
const std::vector<std::chrono::nanoseconds> get_times_from_start() const;

/**
* @brief Get the total duration of the trajectory
* @return the total duration of the trajectory
*/
const std::chrono::nanoseconds get_trajectory_duration() const;

/**
* @brief Get number of points in trajectory
* @return the number of points in trajectory
Expand Down Expand Up @@ -367,6 +373,11 @@ inline const std::vector<std::chrono::nanoseconds> TrajectoryBase<TrajectoryT>::
return times_from_start;
}

template<typename TrajectoryT>
inline const std::chrono::nanoseconds TrajectoryBase<TrajectoryT>::get_trajectory_duration() const {
return this->get_size() ? this->get_times_from_start().back() : std::chrono::nanoseconds(0);
}

template<typename TrajectoryT>
inline unsigned int TrajectoryBase<TrajectoryT>::get_size() const {
return this->points_.size();
Expand Down
1 change: 1 addition & 0 deletions source/state_representation/test/tests/test_trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ TYPED_TEST_P(TrajectoryTest, Getters) {
EXPECT_EQ(this->trajectory->get_time_from_start(i), time_from_start);
EXPECT_EQ(this->trajectory->get_duration(i), durations[i]);
}
EXPECT_EQ(this->trajectory->get_trajectory_duration(), time_from_start);

this->trajectory->reset();
EXPECT_EQ(this->trajectory->get_size(), 0);
Expand Down

0 comments on commit bd0c01c

Please sign in to comment.