Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions moveit_core/robot_trajectory/src/robot_trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ RobotTrajectory& RobotTrajectory::setRobotTrajectoryMsg(const moveit::core::Robo
void RobotTrajectory::findWayPointIndicesForDurationAfterStart(double duration, int& before, int& after,
double& blend) const
{
if (duration < 0.0)
if (duration < 0.0 || waypoints_.empty())
Copy link
Author

Choose a reason for hiding this comment

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

The change in line 539 is not enough to handle the case that waypoints is empty. i.e. index an empty deque with [0]

{
before = 0;
after = 0;
Expand All @@ -530,13 +530,13 @@ void RobotTrajectory::findWayPointIndicesForDurationAfterStart(double duration,
after = std::min<int>(index, num_points - 1);

// Compute duration blend
double before_time = running_duration - duration_from_previous_[index];
if (after == before)
{
blend = 1.0;
}
else
{
double before_time = running_duration - duration_from_previous_[index];
blend = (duration - before_time) / duration_from_previous_[index];
}
}
Expand Down
74 changes: 74 additions & 0 deletions moveit_core/robot_trajectory/test/test_robot_trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,80 @@ TEST_F(RobotTrajectoryTestFixture, RobotTrajectoryDensity)
EXPECT_FALSE(density.has_value());
}

TEST_F(RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndices)
{
robot_trajectory::RobotTrajectoryPtr trajectory;
initTestTrajectory(trajectory);
EXPECT_EQ(trajectory->size(), 5);
EXPECT_EQ(trajectory->getDuration(), 0.5);

int before = -1;
int after = -1;
double blend = -1.0;

trajectory->findWayPointIndicesForDurationAfterStart(0.15, before, after, blend);
EXPECT_EQ(before, 0);
EXPECT_EQ(after, 1);
EXPECT_NEAR(blend, /*between 0 and 1*/ 0.5, 1e-6);

trajectory->findWayPointIndicesForDurationAfterStart(0.3, before, after, blend);
EXPECT_EQ(before, 1);
EXPECT_EQ(after, 2);
EXPECT_NEAR(blend, /*exactly at 2*/ 1.0, 1e-6);
}

TEST_F(RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesTotal)
{
robot_trajectory::RobotTrajectoryPtr trajectory;
initTestTrajectory(trajectory);

int before = -1;
int after = -1;
double blend = -1.0;

const double total_duration = trajectory->getDuration();
trajectory->findWayPointIndicesForDurationAfterStart(total_duration, before, after, blend);
EXPECT_EQ(before, 3);
EXPECT_EQ(after, 4);
EXPECT_DOUBLE_EQ(blend, 1.0);
}

TEST_F(RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesOutOfBounds)
{
robot_trajectory::RobotTrajectoryPtr trajectory;
initTestTrajectory(trajectory);

const double total_duration = trajectory->getDuration();
const double outbound_duration = total_duration + 100.0;
EXPECT_GT(outbound_duration, total_duration);

int before = -1;
int after = -1;
double blend = -1.0;
trajectory->findWayPointIndicesForDurationAfterStart(outbound_duration, before, after, blend);
EXPECT_EQ(before, 4);
EXPECT_EQ(after, 4);
EXPECT_DOUBLE_EQ(blend, 1.0);
}

TEST_F(RobotTrajectoryTestFixture, RobotTrajectoryFindWayPointIndicesOutOfBoundsEmpty)
{
robot_trajectory::RobotTrajectory empty_traj(robot_model_, arm_jmg_name_);
const double total_duration = empty_traj.getDuration();
EXPECT_DOUBLE_EQ(total_duration, 0.0);

const double outbound_duration = 1.0;
EXPECT_GT(outbound_duration, total_duration);

int before = -1;
int after = -1;
double blend = -1.0;
empty_traj.findWayPointIndicesForDurationAfterStart(outbound_duration, before, after, blend);
EXPECT_EQ(before, 0);
EXPECT_EQ(after, 0);
EXPECT_DOUBLE_EQ(blend, 0.0);
}

TEST_F(OneRobot, Unwind)
{
const double epsilon = 1e-4;
Expand Down
Loading