Gazebo | Ignition | Community
Ask Your Question
0

How can I change model weight during runtime?

asked 2022-01-24 07:08:30 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

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)
  }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-12 07:44:49 -0600

I think the GetMass() and SetMass functions in the Gazebo inertial physics library could do the trick.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-01-24 07:08:30 -0600

Seen: 304 times

Last updated: Feb 12 '22