Skip to content

Commit 71a3684

Browse files
committed
Remove joint motor constraint on joint force cmd
Signed-off-by: Ian Chen <ichen@openrobotics.org>
1 parent 6b41b75 commit 71a3684

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

bullet-featherstone/src/JointFeatures.cc

+12-3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ void JointFeatures::SetJointVelocity(
271271
return;
272272

273273
const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
274+
274275
model->body->getJointVelMultiDof(identifier->indexInBtModel)[_dof] =
275276
static_cast<btScalar>(_value);
276277
model->body->wakeUp();
@@ -287,11 +288,11 @@ void JointFeatures::SetJointAcceleration(
287288
void JointFeatures::SetJointForce(
288289
const Identity &_id, const std::size_t _dof, const double _value)
289290
{
290-
const auto *joint = this->ReferenceInterface<JointInfo>(_id);
291+
auto *joint = this->ReferenceInterface<JointInfo>(_id);
291292

292293
if (!std::isfinite(_value))
293294
{
294-
gzerr << "Invalid joint velocity value [" << _value
295+
gzerr << "Invalid joint force value [" << _value
295296
<< "] commanded on joint [" << joint->name << " DOF " << _dof
296297
<< "]. The command will be ignored\n";
297298
return;
@@ -301,7 +302,15 @@ void JointFeatures::SetJointForce(
301302
if (!identifier)
302303
return;
303304

304-
const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
305+
auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
306+
auto *world = this->ReferenceInterface<WorldInfo>(model->world);
307+
308+
// Disable velocity control by removing joint motor constraint
309+
if (joint->motor)
310+
{
311+
world->world->removeMultiBodyConstraint(joint->motor.get());
312+
joint->motor.reset();
313+
}
305314

306315
// clamp the values
307316
double force = std::clamp(_value,

test/common_test/joint_features.cc

+10-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ TYPED_TEST(JointFeaturesTest, JointSetCommand)
146146
auto base_link = model->GetLink("base");
147147
ASSERT_NE(nullptr, base_link);
148148

149-
// Check that invalid velocity commands don't cause collisions to fail
149+
// Check that invalid force commands don't cause collisions to fail
150150
for (std::size_t i = 0; i < 1000; ++i)
151151
{
152152
// Silence console spam
@@ -181,6 +181,15 @@ TYPED_TEST(JointFeaturesTest, JointSetCommand)
181181
EXPECT_NEAR(0.0, joint->GetVelocity(0), 1e-1);
182182
}
183183

184+
// Set joint force to 0 and expect that the velocity command is no
185+
// longer enforced, i.e. joint should not freeze in subsequent steps
186+
joint->SetForce(0, 0.0);
187+
for (std::size_t i = 0; i < numSteps; ++i)
188+
{
189+
world->Step(output, state, input);
190+
EXPECT_LT(0.0, std::fabs(joint->GetVelocity(0)));
191+
}
192+
184193
// Check that invalid velocity commands don't cause collisions to fail
185194
for (std::size_t i = 0; i < 1000; ++i)
186195
{

0 commit comments

Comments
 (0)