How to use AttachStaticModel function

asked 2018-04-27 06:48:02 -0600

this post is marked as community wiki

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

I am implementing a simple robot with two links and one revolute joint. I want that the model would be able to attach a second model (a simple box) and move it . I am trying to use the AttachStaticModel function, but the model does not attach it. I have read that SetStatic function can be a problem, so i had simulated the four possibles cases. Can someone give me an example of how can i use the attach function or tell me where is the problem?

Thank you

#include "boost/bind.hpp"
#include "gazebo/gazebo.hh"
#include "gazebo/physics/physics.hh"
#include "gazebo/common/common.hh"
#include "stdio.h"
#include <fstream>

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");
    std::cout<<" \ntime \n"<<std::endl; 

this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&joint_c::OnUpdate, this, _1));
}



  public: void OnUpdate(const common::UpdateInfo &_info)
    {

    //Non static
    if(_info.simTime.Float()>5 && _info.simTime.Float()<15){
    this->mbox->SetStatic(false);
    this->model->SetStatic(false);      
    this->model->AttachStaticModel(this->mbox,math::Pose(0,0,0.6,0,0,0));
        if(_info.simTime.Float()>10){
            this->jointR1_->SetVelocity(0, 0.5);
        }
    }
    //Second model static


    if(_info.simTime.Float()>15 && _info.simTime.Float()<25){
    this->mbox->SetStatic(true);
    this->model->SetStatic(false);      
    this->model->AttachStaticModel(this->mbox,math::Pose(0,0,0.6,0,0,0));
        if(_info.simTime.Float()>20){
            this->jointR1_->SetVelocity(0, -0.5);
        }
    }
    //First model static
    if(_info.simTime.Float()>25 && _info.simTime.Float()<35){
    this->mbox->SetStatic(false);
    this->model->SetStatic(true);       
    this->model->AttachStaticModel(this->mbox,math::Pose(0,0,0.6,0,0,0));
    link1->AttachStaticModel(this->mbox,math::Pose(0,0,0.6,0,0,0));
        if(_info.simTime.Float()>30){
            this->jointR1_->SetVelocity(0, 0.5);
        }
    }
    //Both static
    if(_info.simTime.Float()>35 && _info.simTime.Float()<45){
    this->mbox->SetStatic(true);
    this->model->SetStatic(true);       
    this->model->AttachStaticModel(this->mbox,math::Pose(0,0,0.6,0,0,0));
        if(_info.simTime.Float()>40){
            this->jointR1_->SetVelocity(0, -0.5);
        }
    }
std::cout<<_info.simTime.Float()<<" \ntime \n"<<std::endl;


}

    common::Time last_update_time_;

  private: 

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



  };
  GZ_REGISTER_MODEL_PLUGIN(joint_c)
}
edit retag flag offensive close merge delete