22 #include <gazebo/transport/Node.hh> 45 if (_sdf->HasElement(
"center_of_gravity_check"))
63 auto linkBox = this->
parentLink->GetBoundingBox();
64 auto linkBoxMax = linkBox.max;
65 auto linkBoxMin = linkBox.min;
66 linkBoxMin.z = std::numeric_limits<double>::lowest();
67 linkBoxMax.z = std::numeric_limits<double>::max();
68 auto disposalBox = math::Box(linkBoxMin, linkBoxMax);
72 bool removeModel =
true;
76 math::Vector3 modelCog = math::Vector3::Zero;
77 double modelMass = 0.0;
78 for (
auto modelLink :
model->GetLinks())
80 double linkMass = modelLink->GetInertial()->GetMass();
81 modelCog += modelLink->GetWorldCoGPose().pos * linkMass;
82 modelMass += linkMass;
86 modelCog /= modelMass;
88 removeModel = disposalBox.Contains(modelCog);
92 gzdbg <<
"[" << this->
model->GetName() <<
"] Removing model: " <<
model->GetName() <<
"\n";
void OnUpdate(const common::UpdateInfo &_info)
Callback that receives the world update event.
void ActOnContactingModels()
Act on models that are ontop of the sensor's link.
A plugin for a contact sensor attached to a model disposal unit.
virtual ~ObjectDisposalPlugin()
Destructor.
bool centerOfGravityCheck
If true, only delete models if their CoG is within the bounding box of the link.
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the model plugin.