Skip to content

Commit

Permalink
Fix test for bullet
Browse files Browse the repository at this point in the history
Also increase ERP parameter to 0.3

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed Jul 13, 2023
1 parent 6c42a98 commit cc9984d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bullet-featherstone/src/JointFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void JointFeatures::SetJointMimicConstraint(
followerJoint->gearConstraint->setMaxAppliedImpulse(btScalar(1e8));
// setErp is needed to correct position constraint errors
// this is especially relevant to the offset and reference parameters
followerJoint->gearConstraint->setErp(btScalar(0.2));
followerJoint->gearConstraint->setErp(btScalar(0.3));
world->world->addMultiBodyConstraint(followerJoint->gearConstraint.get());
}
} // namespace bullet_featherstone
Expand Down
78 changes: 40 additions & 38 deletions test/common_test/joint_mimic_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ TEST_F(JointMimicFeatureTest, PrismaticRevoluteMimicTest)
// prismatic_joint_3 : Mimics revolute_joint_1
for (const std::string &name : this->pluginNames)
{
if(this->PhysicsEngineName(name) != "dartsim")
if(this->PhysicsEngineName(name) != "dartsim" &&
this->PhysicsEngineName(name) != "bullet-featherstone")
{
GTEST_SKIP();
}
Expand Down Expand Up @@ -151,22 +152,17 @@ TEST_F(JointMimicFeatureTest, PrismaticRevoluteMimicTest)

// Let the simulation run without mimic constraint.
// The positions of joints should not be equal.
double prismaticJointPrevPos = 0;
double revoluteJointPrevPos = 0;
for (int i = 0; i < 10; i++)
{
world->Step(output, state, input);
if (i > 5)
{
EXPECT_NE(prismaticJointPrevPos, prismaticFollowerJoint1->GetPosition(0));
EXPECT_NE(prismaticJointPrevPos, revoluteFollowerJoint1->GetPosition(0));
EXPECT_NE(revoluteJointPrevPos, revoluteFollowerJoint2->GetPosition(0));
EXPECT_NE(revoluteJointPrevPos, prismaticFollowerJoint2->GetPosition(0));
EXPECT_NE(leaderJoint->GetPosition(0), prismaticFollowerJoint1->GetPosition(0));
EXPECT_NE(leaderJoint->GetPosition(0), revoluteFollowerJoint1->GetPosition(0));
// this following expectation fails. I think the revolute joints are too similar?
// EXPECT_NE(revoluteFollowerJoint1->GetPosition(0), revoluteFollowerJoint2->GetPosition(0));
EXPECT_NE(revoluteFollowerJoint1->GetPosition(0), prismaticFollowerJoint2->GetPosition(0));
}

// Update previous positions.
prismaticJointPrevPos = leaderJoint->GetPosition(0);
revoluteJointPrevPos = revoluteFollowerJoint1->GetPosition(0);
}

auto testMimicFcn = [&](double multiplier, double offset, double reference)
Expand All @@ -192,32 +188,41 @@ TEST_F(JointMimicFeatureTest, PrismaticRevoluteMimicTest)
prismaticFollowerJoint2->SetPosition(0, 0);
revoluteFollowerJoint1->SetPosition(0, 0);
revoluteFollowerJoint2->SetPosition(0, 0);
for (int _ = 0; _ < 10; _++)
for (int _ = 0; _ < 200; _++)
world->Step(output, state, input);

// Follower joint's position should be equal to that of leader joint in previous timestep,
// considering the offsets and multipliers.
prismaticJointPrevPos = leaderJoint->GetPosition(0);
revoluteJointPrevPos = revoluteFollowerJoint1->GetPosition(0);
for (int _ = 0; _ < 10; _++)
{
world->Step(output, state, input);
// Check for prismatic -> prismatic mimicking.
EXPECT_FLOAT_EQ(multiplier * (prismaticJointPrevPos - reference) + offset,
prismaticFollowerJoint1->GetPosition(0));
const double positionTolerance = 0.1;
EXPECT_NEAR(multiplier * (leaderJoint->GetPosition(0) - reference) + offset,
prismaticFollowerJoint1->GetPosition(0), positionTolerance)
<< "multiplier [" << multiplier
<< "], reference [" << reference
<< "], offset [" << offset
<< "], leaderPos [" << leaderJoint->GetPosition(0)
<< "], followerPos [" << prismaticFollowerJoint1->GetPosition(0) << "]";
// Check for prismatic -> revolute mimicking.
EXPECT_FLOAT_EQ(multiplier * (prismaticJointPrevPos - reference) + offset,
revoluteFollowerJoint1->GetPosition(0));
EXPECT_NEAR(multiplier * (leaderJoint->GetPosition(0) - reference) + offset,
revoluteFollowerJoint1->GetPosition(0), positionTolerance)
<< "multiplier [" << multiplier
<< "], reference [" << reference
<< "], offset [" << offset
<< "], leaderPos [" << leaderJoint->GetPosition(0)
<< "], followerPos [" << revoluteFollowerJoint1->GetPosition(0) << "]";
// Check for revolute -> revolute mimicking.
EXPECT_FLOAT_EQ(multiplier * (revoluteJointPrevPos - reference) + offset,
revoluteFollowerJoint2->GetPosition(0));
EXPECT_NEAR(multiplier * (revoluteFollowerJoint1->GetPosition(0) - reference) + offset,
revoluteFollowerJoint2->GetPosition(0), positionTolerance)
<< "multiplier [" << multiplier
<< "], reference [" << reference
<< "], offset [" << offset << "]";
// Check for revolute --> prismatic mimicking.
EXPECT_FLOAT_EQ(multiplier * (revoluteJointPrevPos - reference) + offset,
prismaticFollowerJoint2->GetPosition(0));

// Update previous positions.
prismaticJointPrevPos = leaderJoint->GetPosition(0);
revoluteJointPrevPos = revoluteFollowerJoint1->GetPosition(0);
EXPECT_NEAR(multiplier * (revoluteFollowerJoint1->GetPosition(0) - reference) + offset,
prismaticFollowerJoint2->GetPosition(0), positionTolerance)
<< "multiplier [" << multiplier
<< "], reference [" << reference
<< "], offset [" << offset << "]";
}
};

Expand Down Expand Up @@ -331,7 +336,8 @@ TEST_F(JointMimicFeatureTest, PendulumMimicTest)
{
for (const std::string &name : this->pluginNames)
{
if(this->PhysicsEngineName(name) != "dartsim")
if(this->PhysicsEngineName(name) != "dartsim" &&
this->PhysicsEngineName(name) != "bullet-featherstone")
{
GTEST_SKIP();
}
Expand Down Expand Up @@ -366,12 +372,10 @@ TEST_F(JointMimicFeatureTest, PendulumMimicTest)

// Let the simulation run without mimic constraint.
// The positions of joints should not be equal.
double leaderJointPrevPosAxis = 0;
for (int _ = 0; _ < 10; _++)
{
world->Step(output, state, input);
EXPECT_NE(leaderJointPrevPosAxis, followerJoint->GetPosition(0));
leaderJointPrevPosAxis = leaderJoint->GetPosition(0);
EXPECT_NE(leaderJoint->GetPosition(0), followerJoint->GetPosition(0));
}

auto testMimicFcn = [&](double multiplier, double offset, double reference)
Expand All @@ -381,17 +385,15 @@ TEST_F(JointMimicFeatureTest, PendulumMimicTest)
// Reset positions and run a few iterations so the positions reach nontrivial values.
leaderJoint->SetPosition(0, 0);
followerJoint->SetPosition(0, 0);
for (int _ = 0; _ < 10; _++)
for (int _ = 0; _ < 125; _++)
world->Step(output, state, input);

// Follower joint's position should be equal to that of leader joint in previous timestep.
leaderJointPrevPosAxis = leaderJoint->GetPosition(0);
const double positionTolerance = 3e-3;
for (int _ = 0; _ < 10; _++)
{
world->Step(output, state, input);
EXPECT_FLOAT_EQ(multiplier * (leaderJointPrevPosAxis - reference) + offset,
followerJoint->GetPosition(0));
leaderJointPrevPosAxis = leaderJoint->GetPosition(0);
EXPECT_NEAR(multiplier * (leaderJoint->GetPosition(0) - reference) + offset,
followerJoint->GetPosition(0), positionTolerance);
}
};

Expand Down

0 comments on commit cc9984d

Please sign in to comment.