Gazebo | Ignition | Community
Ask Your Question

How can i change a Gazebo model properties in runtime? [closed]

asked 2018-05-02 07:43:20 -0500

lumaro gravatar image

updated 2018-05-03 04:04:59 -0500

Hello I want to change the mass property of a link in runtime. When i use the SetMass() function, Gazebo detect the change of mass value in the properties menu (the left one) but in the simulation the link continues behaving as if nothing had happened.

Should I use other function to update the values? Thank you.

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->jointR1_ = this->model->GetJoint("r1");
    this->link1 = this->mbox->GetLink("link");

link1->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)



       physics::ModelPtr model;
       physics::ModelPtr mbox;
       physics::WorldPtr world;
       event::ConnectionPtr updateConnection;
       physics::JointPtr jointR1_;
       physics::LinkPtr  link1;


  // Register this plugin with the simulator

(re): I have tried to use the "virtual void UpdateParameters (sdf::ElementPtr _sdf)" function, but the console show me an error:

Error [Element.hh:360] Unable to find value for key[pose]
Error [] Missing element description for [gravity]

My new lines of code are:

sdf::ElementPtr sdflink;
    this->sdflink->GetAttribute("name")->Set ("newName");
    this->sdflink->GetElement("pose")->Set(math::Pose(math::Vector3(-3, 0, 0), math::Quaternion(0, 0, 0)));

What is going on?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by lumaro
close date 2018-05-04 04:11:57.035899

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-04 04:11:24 -0500

lumaro gravatar image

Hey there, i found a solution, just update the mass with UpdateMass(); function.

edit flag offensive delete link more


Hi, I am also trying to do similar work. I have my robot carrying a payload. I want to change the payload mass at runtime. I found a way to do it, with rosservice call gazebo set link properties, "Gazebo detect the change of mass value in the properties menu (the left one) but in the simulation, the link continues behaving as if nothing had happened" if I understand your work correctly, you wrote a Model plugin and doing similar operation would you please specify where you added UpdateMass();?

r3hman gravatar imager3hman ( 2018-12-13 06:03:54 -0500 )edit

Question Tools



Asked: 2018-05-02 07:43:20 -0500

Seen: 2,075 times

Last updated: May 04 '18