Skip to content

Commit 04047a0

Browse files
committed
World::reset clears constraint impulses
1 parent c978337 commit 04047a0

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

dart/simulation/World.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ void World::reset()
274274
mFrame = 0;
275275
mRecording->clear();
276276
mConstraintSolver->clearLastCollisionResult();
277+
278+
for (auto& skel : mSkeletons) {
279+
skel->clearConstraintImpulses();
280+
skel->setImpulseApplied(false);
281+
}
277282
}
278283

279284
//==============================================================================

dart/simulation/World.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ class DART_API World : public virtual common::Subject
239239
// Simulation
240240
//--------------------------------------------------------------------------
241241

242-
/// Reset the time, frame counter and recorded histories
242+
/// Reset the time, frame counter and recorded histories.
243+
///
244+
/// This also clears constraint impulses on all Skeletons in the World so
245+
/// stale constraint forces do not leak across independent simulation runs.
243246
void reset();
244247

245248
/// Calculate the dynamics and integrate the world for one step

tests/integration/dynamics/test_SkeletonState.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,35 @@ TEST(Issue1089, JointImpulseState)
169169
joint->getConstraintImpulse(i), static_cast<double>((i + 1) * 2));
170170
}
171171
}
172+
173+
//==============================================================================
174+
TEST(Issue1086, WorldResetClearsConstraintImpulses)
175+
{
176+
auto world = std::make_shared<dart::simulation::World>();
177+
auto skel = dart::dynamics::Skeleton::create("skel");
178+
179+
const auto pair
180+
= skel->createJointAndBodyNodePair<dart::dynamics::FreeJoint>(nullptr);
181+
auto* joint = pair.first;
182+
auto body = pair.second;
183+
184+
body->setConstraintImpulse(Eigen::Vector6d::Ones());
185+
for (std::size_t i = 0; i < joint->getNumDofs(); ++i) {
186+
joint->setVelocityChange(i, 1.0);
187+
joint->setConstraintImpulse(i, 1.0);
188+
}
189+
skel->setImpulseApplied(true);
190+
191+
EXPECT_FALSE(body->getConstraintImpulse().isZero());
192+
EXPECT_TRUE(skel->isImpulseApplied());
193+
194+
world->addSkeleton(skel);
195+
world->reset();
196+
197+
EXPECT_TRUE(body->getConstraintImpulse().isZero());
198+
for (std::size_t i = 0; i < joint->getNumDofs(); ++i) {
199+
EXPECT_DOUBLE_EQ(joint->getVelocityChange(i), 0.0);
200+
EXPECT_DOUBLE_EQ(joint->getConstraintImpulse(i), 0.0);
201+
}
202+
EXPECT_FALSE(skel->isImpulseApplied());
203+
}

0 commit comments

Comments
 (0)