Skip to content

Commit

Permalink
Off by one in getAverageSegmentDuration (#1079)
Browse files Browse the repository at this point in the history
* Off by one in getAverageSegmentDuration

* Case for one waypoint

Co-authored-by: AndyZe <andyz@utexas.edu>

* Warn if too few waypoints to get duration

Co-authored-by: AndyZe <andyz@utexas.edu>

* Discount first duration_from_previous from average duration if it is 0

* Restore empty duration from previous check as per Andy's suggestion

* Changed warning message for case with 1 segment with 0 duration to be distinct from empty durations

Co-authored-by: AndyZe <andyz@utexas.edu>
Co-authored-by: Henning Kayser <henningkayser@picknik.ai>
Co-authored-by: AndyZe <zelenak@picknik.ai>
  • Loading branch information
4 people committed Mar 14, 2022
1 parent a7b757d commit d5b2d26
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions moveit_core/robot_trajectory/src/robot_trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,22 @@ double RobotTrajectory::getDuration() const
double RobotTrajectory::getAverageSegmentDuration() const
{
if (duration_from_previous_.empty())
{
RCLCPP_WARN(rclcpp::get_logger("RobotTrajectory"), "Too few waypoints to calculate a duration. Returning 0.");
return 0.0;
}

// If the initial segment has a duration of 0, exclude it from the average calculation
if (duration_from_previous_[0] == 0)
{
if (duration_from_previous_.size() <= 1)
{
RCLCPP_WARN(rclcpp::get_logger("RobotTrajectory"), "First and only waypoint has a duration of 0.");
return 0.0;
}
else
return getDuration() / static_cast<double>(duration_from_previous_.size() - 1);
}
else
return getDuration() / static_cast<double>(duration_from_previous_.size());
}
Expand Down

0 comments on commit d5b2d26

Please sign in to comment.