Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GravityEnabled boolean component #2451

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/gz/sim/components/Gravity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ namespace components
/// \brief Store the gravity acceleration.
using Gravity = Component<math::Vector3d, class GravityTag>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.Gravity", Gravity)

/// \brief Store the gravity acceleration.
using GravityEnabled = Component<bool, class GravityEnabledTag>;
IGN_GAZEBO_REGISTER_COMPONENT(
"ign_gazebo_components.GravityEnabled", GravityEnabled)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Link *_link)

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

// Visuals
Expand Down
21 changes: 6 additions & 15 deletions src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1161,21 +1161,12 @@ void PhysicsPrivate::CreateLinkEntities(const EntityComponentManager &_ecm)
}

// 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);
}
const components::GravityEnabled *gravityEnabled =
_ecm.Component<components::GravityEnabled>(_entity);
if (nullptr != gravityEnabled)
{
// gravityEnabled set in SdfEntityCreator::CreateEntities()
link.SetEnableGravity(gravityEnabled->Data());
}

auto linkPtrPhys = modelPtrPhys->ConstructLink(link);
Expand Down