Home | Tutorials | Wiki | Issues
Ask Your Question
0

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

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

lumaro gravatar image

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

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->mbox=this->world->GetModel("minibox");
    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)
    {

     }

  private: 

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

  };

  // Register this plugin with the simulator
  GZ_REGISTER_MODEL_PLUGIN(joint_c)
}

(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 [Element.cc:684] Missing element description for [gravity]

My new lines of code are:

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

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
0

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

lumaro gravatar image

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

edit flag offensive delete link more

Comments

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 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 758 times

Last updated: May 04 '18