How can I change model weight during runtime?
I want to decrease model weigth in runtime. I am currently working on a plugin but it doesn't seem to work. I am using iris model with pixhawk 4 sitl. My purpose is to simulate a liquid spraying drone like a firefighter. To do that I have to decrease the weigth of the drone in time. Thank you. Here is the code that I have:
#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)
}