mimic_plugin.cpp
Go to the documentation of this file.
00001 #include <gazebo_mimic_plugin/mimic_plugin.h>
00002 
00003 using namespace gazebo;
00004 
00005 MimicPlugin::MimicPlugin():  ModelPlugin()
00006 {
00007   kill_sim = false;
00008 
00009   joint_.reset();
00010   mimic_joint_.reset();
00011 }
00012 
00013 MimicPlugin::~MimicPlugin()
00014 {
00015   event::Events::DisconnectWorldUpdateBegin(this->updateConnection);
00016 
00017   kill_sim = true;
00018 }
00019 
00020 void MimicPlugin::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf )
00021 {
00022   this->model_ = _parent;
00023   this->world_ = this->model_->GetWorld();
00024 
00025   joint_name_ = "joint";
00026   if (_sdf->HasElement("joint"))
00027     joint_name_ = _sdf->GetElement("joint")->Get<std::string>();
00028 
00029   mimic_joint_name_ = "mimicJoint";
00030   if (_sdf->HasElement("mimicJoint"))
00031     mimic_joint_name_ = _sdf->GetElement("mimicJoint")->Get<std::string>();
00032 
00033   multiplier_ = 1.0;
00034   if (_sdf->HasElement("multiplier"))
00035     multiplier_ = _sdf->GetElement("multiplier")->Get<double>();
00036 
00037   // Get the name of the parent model
00038   std::string modelName = _sdf->GetParent()->Get<std::string>("name");
00039 
00040   // Listen to the update event. This event is broadcast every
00041   // simulation iteration.
00042   this->updateConnection = event::Events::ConnectWorldUpdateBegin(
00043       boost::bind(&MimicPlugin::UpdateChild, this));
00044   
00045   ROS_INFO_STREAM("MimicPlugin model name: "<< modelName);
00046 
00047   joint_ = model_->GetJoint(joint_name_);
00048   mimic_joint_ = model_->GetJoint(mimic_joint_name_);
00049 }
00050 
00051 void MimicPlugin::UpdateChild()
00052 {
00053    mimic_joint_->SetAngle(0, math::Angle(joint_->GetAngle(0).Radian()*multiplier_));
00054 }
00055 
00056 GZ_REGISTER_MODEL_PLUGIN(MimicPlugin);


barrett_hand_gazebo
Author(s):
autogenerated on Thu Jun 6 2019 20:14:34