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
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"<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"<
↧