Skip to content

Commit

Permalink
Deal with time_step==0
Browse files Browse the repository at this point in the history
  • Loading branch information
uavster committed Aug 17, 2023
1 parent 9ef98e5 commit 04b4f35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ Trajectory::Trajectory(const Path& path, const Eigen::VectorXd& max_velocity, co
, time_step_(time_step)
, cached_time_(std::numeric_limits<double>::max())
{
if (time_step_ == 0)
{
valid_ = false;
RCLCPP_ERROR(LOGGER, "The trajectory is invalid because the time step is 0.");
return;
}
trajectory_.push_back(TrajectoryStep(0.0, 0.0));
double after_acceleration = getMinMaxPathAcceleration(0.0, 0.0, true);
while (valid_ && !integrateForward(trajectory_, after_acceleration) && valid_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,26 +541,34 @@ TEST(time_optimal_trajectory_generation, testSingleDofDiscontinuity)
TEST(time_optimal_trajectory_generation, testRelevantZeroMaxAccelerationsInvalidateTrajectory)
{
EXPECT_FALSE(Trajectory(Path(std::list<Eigen::VectorXd>{ Eigen::Vector2d(0, 0), Eigen::Vector2d(1, 1) }),
Eigen::Vector2d(1, 1), Eigen::Vector2d(0, 1))
/*max_velocity=*/Eigen::Vector2d(1, 1), /*max_acceleration=*/Eigen::Vector2d(0, 1))
.isValid());
EXPECT_FALSE(Trajectory(Path(std::list<Eigen::VectorXd>{ Eigen::Vector2d(0, 0), Eigen::Vector2d(1, 1) }),
Eigen::Vector2d(1, 1), Eigen::Vector2d(1, 0))
/*max_velocity=*/Eigen::Vector2d(1, 1), /*max_acceleration=*/Eigen::Vector2d(1, 0))
.isValid());
EXPECT_FALSE(Trajectory(Path(std::list<Eigen::VectorXd>{ Eigen::Vector2d(0, 0), Eigen::Vector2d(1, 1) }),
Eigen::Vector2d(1, 1), Eigen::Vector2d(0, 0))
/*max_velocity=*/Eigen::Vector2d(1, 1), /*max_acceleration=*/Eigen::Vector2d(0, 0))
.isValid());
}

TEST(time_optimal_trajectory_generation, testIrrelevantZeroMaxAccelerationsDontInvalidateTrajectory)
{
EXPECT_TRUE(Trajectory(Path(std::list<Eigen::VectorXd>{ Eigen::Vector2d(0, 0), Eigen::Vector2d(0, 1) }),
Eigen::Vector2d(1, 1), Eigen::Vector2d(0, 1))
/*max_velocity=*/Eigen::Vector2d(1, 1), /*max_acceleration=*/Eigen::Vector2d(0, 1))
.isValid());
EXPECT_TRUE(Trajectory(Path(std::list<Eigen::VectorXd>{ Eigen::Vector2d(0, 0), Eigen::Vector2d(1, 0) }),
Eigen::Vector2d(1, 1), Eigen::Vector2d(1, 0))
/*max_velocity=*/Eigen::Vector2d(1, 1), /*max_acceleration=*/Eigen::Vector2d(1, 0))
.isValid());
}

TEST(time_optimal_trajectory_generation, testTimeStepZeroMakesTrajectoryInvalid)
{
EXPECT_FALSE(Trajectory(Path(std::list<Eigen::VectorXd>{ Eigen::Vector2d(0, 0), Eigen::Vector2d(1, 1) }),
/*max_velocity=*/Eigen::Vector2d(1, 1), /*max_acceleration=*/Eigen::Vector2d(1, 1),
/*time_step=*/0)
.isValid());
}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 04b4f35

Please sign in to comment.