Dynamically load plugin

asked 2015-06-25 04:35:57 -0600

mehdi gravatar image

I created a plugin that creates a joint between two links of two models.

#include <map>
#include "gazebo/gazebo.hh"
#include "gazebo/common/common.hh"
#include "gazebo/physics/physics.hh"

namespace gazebo
class CreatePackage : public WorldPlugin
  public: void Load(physics::WorldPtr _parent, sdf::ElementPtr /*_sdf*/)
    gazebo::physics::ModelPtr package = _parent->GetModel("my_package");
    gazebo::physics::LinkPtr package_link = package->GetLink("simple_box");
    gazebo::physics::ModelPtr maru = _parent->GetModel("maru");
    gazebo::physics::LinkPtr gripper_rot_link = maru->GetLink("gripper_rot");
    gazebo::physics::JointPtr newJoint;
    newJoint = _parent->GetPhysicsEngine()->CreateJoint("fixed", maru);
    newJoint->Load(package_link, gripper_rot_link, gripper_rot_link->GetWorldPose());
    newJoint->Attach(package_link, gripper_rot_link);
    newJoint->SetAxis(0,  gazebo::math::Vector3(0.0f,0.0f,1.0f) );
    if( maru->GetJoint("package_joint") == NULL )
        std::cout<<"Model GetJoint : FALSE \n"<<std::endl;
        std::cout<<"Model GetJoint : OK \n"<<std::endl;


  // Register this plugin with the simulator

Now that my robot is loaded and my gzserver and gzclient are running, how do I tell Gazebo to spawn that joint using this plugin? All examples in the tutorials and the example codes put the plugin directly in the sdf within a model.

edit retag flag offensive close merge delete