Skip to content

Commit

Permalink
Make halt motiona act like a brake (#830)
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Koenig <[email protected]>

Co-authored-by: Nate Koenig <[email protected]>
  • Loading branch information
nkoenig and Nate Koenig authored May 24, 2021
1 parent 996684c commit be5581f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,10 @@ void PhysicsPrivate::UpdatePhysics(EntityComponentManager &_ecm)
if (nullptr == jointPhys)
return true;

auto jointVelFeature =
this->entityJointMap.EntityCast<JointVelocityCommandFeatureList>(
_entity);

auto haltMotionComp = _ecm.Component<components::HaltMotion>(
_ecm.ParentEntity(_entity));
bool haltMotion = false;
Expand All @@ -1277,14 +1281,19 @@ void PhysicsPrivate::UpdatePhysics(EntityComponentManager &_ecm)
haltMotion = haltMotionComp->Data();
}


// Model is out of battery
// Model is out of battery or halt motion has been triggered.
if (this->entityOffMap[_ecm.ParentEntity(_entity)] || haltMotion)
{
std::size_t nDofs = jointPhys->GetDegreesOfFreedom();
for (std::size_t i = 0; i < nDofs; ++i)
{
jointPhys->SetForce(i, 0);

// Halt motion requires the vehicle to come to a full stop,
// while running out of battery can leave existing joint velocity
// in place.
if (haltMotion && jointVelFeature)
jointVelFeature->SetVelocityCommand(i, 0);
}
return true;
}
Expand Down Expand Up @@ -1389,9 +1398,6 @@ void PhysicsPrivate::UpdatePhysics(EntityComponentManager &_ecm)
<< velocityCmd.size() << ".\n";
}

auto jointVelFeature =
this->entityJointMap.EntityCast<JointVelocityCommandFeatureList>(
_entity);
if (!jointVelFeature)
{
return true;
Expand Down

0 comments on commit be5581f

Please sign in to comment.