Skip to content

Commit

Permalink
Fix bug with negative execution times in Executor::step. (#450)
Browse files Browse the repository at this point in the history
* Fix bug with negative execution times in KinematicSimulationTrajectoryExecutor.

* Fix tests.

* Update CHANGELOG.md.
  • Loading branch information
brianhou authored Jul 19, 2018
1 parent cfba2f6 commit e46aba0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Control

* Fixed CollisionGroup bugs in Hand executors: [#299](https://github.com/personalrobotics/aikido/pull/299)
* Rewrote executors for faster-than-realtime simulation: [#316](https://github.com/personalrobotics/aikido/pull/316)
* Rewrote executors for faster-than-realtime simulation: [#316](https://github.com/personalrobotics/aikido/pull/316), [#450](https://github.com/personalrobotics/aikido/pull/450)
* Introduced uniform and dart namespaces: [#342](https://github.com/personalrobotics/aikido/pull/342)
* Removed Barrett-specific hand executors: [#380](https://github.com/personalrobotics/aikido/pull/380)

Expand Down
4 changes: 3 additions & 1 deletion src/control/KinematicSimulationTrajectoryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ void KinematicSimulationTrajectoryExecutor::step(
const auto executionTime
= std::chrono::duration<double>(timeSinceBeginning).count();

// executionTime may be negative if the thread calling \c step is queued
// before and dequeued after \c execute is called.
if (executionTime < 0)
throw std::invalid_argument("Timepoint is before execution start time.");
return;

auto state = mStateSpace->createState();
mTraj->evaluate(executionTime, state);
Expand Down
6 changes: 3 additions & 3 deletions tests/control/test_KinematicSimulationTrajectoryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ TEST_F(
EXPECT_DOUBLE_EQ(mSkeleton->getDof(0)->getPosition(), 1.0);
}

TEST_F(KinematicSimulationTrajectoryExecutorTest, step_NegativeTimepoint_Throws)
TEST_F(
KinematicSimulationTrajectoryExecutorTest, step_NegativeTimepoint_NoThrows)
{
KinematicSimulationTrajectoryExecutor executor(mSkeleton);

Expand All @@ -219,8 +220,7 @@ TEST_F(KinematicSimulationTrajectoryExecutorTest, step_NegativeTimepoint_Throws)
auto simulationClock = std::chrono::system_clock::now();
auto future = executor.execute(mTraj);

EXPECT_THROW(
executor.step(simulationClock - stepTime), std::invalid_argument);
EXPECT_NO_THROW(executor.step(simulationClock - stepTime));

std::future_status status;
do
Expand Down
5 changes: 2 additions & 3 deletions tests/control/test_QueuedTrajectoryExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST_F(
EXPECT_EQ(f1.wait_for(waitTime), std::future_status::ready);
}

TEST_F(QueuedTrajectoryExecutorTest, step_NegativeTimepoint_Throws)
TEST_F(QueuedTrajectoryExecutorTest, step_NegativeTimepoint_NoThrows)
{
QueuedTrajectoryExecutor executor(std::move(mExecutor));

Expand All @@ -202,8 +202,7 @@ TEST_F(QueuedTrajectoryExecutorTest, step_NegativeTimepoint_Throws)
auto f2 = executor.execute(mTraj2);
executor.step(simulationClock); // dequeue trajectory

EXPECT_THROW(
executor.step(simulationClock - stepTime), std::invalid_argument);
EXPECT_NO_THROW(executor.step(simulationClock - stepTime));

std::future_status status;
do
Expand Down

0 comments on commit e46aba0

Please sign in to comment.