我想在运行时减少模型重量。我目前正在开发一个插件,但它似乎不起作用。我正在使用带有 pixhawk 4 sitl 的虹膜模型。我的目的是模拟像消防员一样的液体喷洒无人机。为此,我必须及时减轻无人机的重量。谢谢你。这是我拥有的代码:
#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
namespace gazebo
{
class joint_c : public ModelPlugin
{
public:
void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
{
this->model = _parent;
this->world= this->model->GetWorld();
this->iris=this->world->ModelByName("iris");
this->base_link = this->iris->GetLink("base_link");
base_link->GetInertial()->SetMass(800000); // Changing the mass
this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&joint_c::OnUpdate, this, _1));
}
public:
void OnUpdate(const common::UpdateInfo &_info)
{
}
private:
physics::ModelPtr model;
physics::ModelPtr iris;
physics::WorldPtr world;
event::ConnectionPtr updateConnection;
physics::LinkPtr base_link;
};
// Register this plugin with the simulator
GZ_REGISTER_MODEL_PLUGIN(joint_c)
}