Dynamically load plugin
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->SetName("package_joint");
newJoint->SetModel(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;
else
std::cout<<"Model GetJoint : OK \n"<<std::endl;
}
};
// Register this plugin with the simulator
GZ_REGISTER_WORLD_PLUGIN(CreatePackage)
}
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.