Skip to content

Commit

Permalink
Add support for no gravity link (#2398)
Browse files Browse the repository at this point in the history
Signed-off-by: youhy <haoyuan2019@outlook.com>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Co-authored-by: Ian Chen <ichen@openrobotics.org>
  • Loading branch information
AzulRadio and iche033 committed Jun 13, 2024
1 parent 3c52690 commit 45239e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Link *_link)
linkEntity, components::WindMode(_link->EnableWind()));
}

if (!_link->EnableGravity())
{
// If disable gravity, create a gravity component to the entity
// This gravity will have value 0,0,0
this->dataPtr->ecm->CreateComponent(
linkEntity, components::Gravity());
}

// Visuals
for (uint64_t visualIndex = 0; visualIndex < _link->VisualCount();
++visualIndex)
Expand Down
18 changes: 18 additions & 0 deletions src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,24 @@ void PhysicsPrivate::CreateLinkEntities(const EntityComponentManager &_ecm)
link.SetInertial(inertial->Data());
}

// get link gravity
const components::Gravity *gravity =
_ecm.Component<components::Gravity>(_entity);
if (nullptr != gravity)
{
// Entity has a gravity component that is all zeros when
// <gravity> is set to false
// See SdfEntityCreator::CreateEntities()
if (gravity->Data() == math::Vector3d::Zero)
{
link.SetEnableGravity(false);
}
else
{
link.SetEnableGravity(true);
}
}

auto linkPtrPhys = modelPtrPhys->ConstructLink(link);
this->entityLinkMap.AddEntity(_entity, linkPtrPhys);
this->topLevelModelMap.insert(std::make_pair(_entity,
Expand Down

0 comments on commit 45239e9

Please sign in to comment.