gz-sim
gz-sim copied to clipboard
Disable gravity for links
Gazebo Classic supports the <link><gravity>
SDF element, which makes links float.
That hasn't been ported to Ignition yet, we aren't even parsing the flag into sdf::Link.
Ive been working on a plugin to disable grav, but not sure the right way to do it (ignition documentation is really rough...). I have the plugin loading, and the gravity is being printed out as 0 0 0 , but not sure if its being applied to the model at all. Any suggestions?
void AntiGrav::Configure(const ignition::gazebo::Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
ignition::gazebo::EntityComponentManager &_ecm,
ignition::gazebo::EventManager &/*_eventMgr*/)
{
std::string link_name_;
//ignition::gazebo::Model model{ ignition::gazebo::kNullEntity};
ignition::gazebo::Model model{_entity};
// Get sdf parameters
if (_sdf->HasElement("linkName"))
{
link_name_ = _sdf->Get<std::string>("linkName");
}
else
{
ignerr << "The AntiGrav plugin for " << "[MODEL NAME] " << "requires a `linkName` parameter tag" <<std::endl;
return;
}
if(!model.Valid(_ecm))
{
ignerr << "AntiGrav plugin should be attached to a model entity. " << std::endl;
return;
}
ignition::gazebo::Entity E = model.LinkByName(_ecm,link_name_);
_ecm.CreateComponent<ignition::gazebo::components::Gravity>(_entity,ignition::gazebo::components::Gravity());
//const components::Gravity *gravity = _ecm.Component<components::Gravity>(this->dataPtr->world);
const ignition::gazebo::components::Gravity *gravity = _ecm.Component<ignition::gazebo::components::Gravity>(_entity);
if(nullptr == gravity)
{
ignmsg << "gravity is a null pointer" << std::endl;
}
else
{
ignmsg << gravity->Data().X() << gravity->Data().Y() << gravity->Data().Z() << std::endl;
}
}