mimic_plugin.cpp
Go to the documentation of this file.
2 
3 using namespace gazebo;
4 
5 MimicPlugin::MimicPlugin(): ModelPlugin()
6 {
7  kill_sim = false;
8 
9  joint_.reset();
10  mimic_joint_.reset();
11 }
12 
14 {
15  event::Events::DisconnectWorldUpdateBegin(this->updateConnection);
16 
17  kill_sim = true;
18 }
19 
20 void MimicPlugin::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf )
21 {
22  this->model_ = _parent;
23  this->world_ = this->model_->GetWorld();
24 
25  joint_name_ = "joint";
26  if (_sdf->HasElement("joint"))
27  joint_name_ = _sdf->GetElement("joint")->Get<std::string>();
28 
29  mimic_joint_name_ = "mimicJoint";
30  if (_sdf->HasElement("mimicJoint"))
31  mimic_joint_name_ = _sdf->GetElement("mimicJoint")->Get<std::string>();
32 
33  multiplier_ = 1.0;
34  if (_sdf->HasElement("multiplier"))
35  multiplier_ = _sdf->GetElement("multiplier")->Get<double>();
36 
37  // Get the name of the parent model
38  std::string modelName = _sdf->GetParent()->Get<std::string>("name");
39 
40  // Listen to the update event. This event is broadcast every
41  // simulation iteration.
42  this->updateConnection = event::Events::ConnectWorldUpdateBegin(
43  boost::bind(&MimicPlugin::UpdateChild, this));
44 
45  ROS_INFO_STREAM("MimicPlugin model name: "<< modelName);
46 
47  joint_ = model_->GetJoint(joint_name_);
48  mimic_joint_ = model_->GetJoint(mimic_joint_name_);
49 }
50 
52 {
53  //mimic_joint_->SetAngle(0, math::Angle(joint_->GetAngle(0).Radian()*multiplier_));
54  mimic_joint_->SetPosition(0,joint_->GetAngle(0).Radian()*multiplier_);
55 }
56 
event::ConnectionPtr updateConnection
Definition: mimic_plugin.h:22
physics::JointPtr mimic_joint_
Definition: mimic_plugin.h:25
physics::JointPtr joint_
Definition: mimic_plugin.h:24
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
GZ_REGISTER_MODEL_PLUGIN(MimicPlugin)
#define ROS_INFO_STREAM(args)
double multiplier_
Definition: mimic_plugin.h:18
physics::WorldPtr world_
Definition: mimic_plugin.h:20
physics::ModelPtr model_
Definition: mimic_plugin.h:19
std::string mimic_joint_name_
Definition: mimic_plugin.h:16
void UpdateChild()
std::string joint_name_
Definition: mimic_plugin.h:17


barrett_hand_gazebo
Author(s):
autogenerated on Mon Jun 10 2019 12:51:58