GearboxJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _GEARBOXJOINT_HH_
19 #define _GEARBOXJOINT_HH_
20 
21 #include <string>
22 
23 #include "gazebo/msgs/msgs.hh"
24 #include "gazebo/util/system.hh"
25 
26 namespace gazebo
27 {
28  namespace physics
29  {
32 
35  template<class T>
36  class GZ_PHYSICS_VISIBLE GearboxJoint : public T
37  {
40  public: explicit GearboxJoint(BasePtr _parent)
41  : T(_parent), gearRatio(1.0)
42  { this->AddType(Base::GEARBOX_JOINT); }
44  public: virtual ~GearboxJoint()
45  { }
46 
47  // Documentation inherited.
48  public: virtual unsigned int DOF() const
49  {return 2;}
50 
53  public: virtual void Load(sdf::ElementPtr _sdf)
54  {
55  T::Load(_sdf);
56  if (_sdf->HasElement("gearbox_ratio"))
57  {
58  this->gearRatio =
59  _sdf->Get<double>("gearbox_ratio");
60  }
61  else
62  {
63  gzerr << "gearbox_ratio_not_specified, set to 1.\n";
64  this->gearRatio = 1.0;
65  /* below should bring in default values for sdf 1.4+
66  this->gearRatio =
67  _sdf->Get<double>("gearbox_ratio");
68  */
69  }
70 
71  if (_sdf->HasElement("gearbox_reference_body"))
72  {
73  this->referenceBody =
74  _sdf->Get<std::string>("gearbox_reference_body");
75  }
76  else
77  {
78  gzerr << "Gearbox joint missing reference body.\n";
79  }
80  }
81 
83  protected: virtual void Init()
84  {
85  T::Init();
86  }
87 
90  public: virtual double GetGearboxRatio() const
91  { return this->gearRatio; }
92 
98  public: virtual void SetGearboxRatio(double _gearRatio) = 0;
99 
100  // Documentation inherited
101  public: virtual void FillMsg(msgs::Joint &_msg)
102  {
103  Joint::FillMsg(_msg);
104  msgs::Joint::Gearbox *gearboxMsg = _msg.mutable_gearbox();
105  gearboxMsg->set_gearbox_reference_body(this->referenceBody);
106  gearboxMsg->set_gearbox_ratio(this->gearRatio);
107  }
108 
110  protected: double gearRatio;
111 
113  protected: std::string referenceBody;
114  };
116  }
117 }
118 #endif
virtual unsigned int DOF() const
Definition: GearboxJoint.hh:48
virtual void Load(sdf::ElementPtr _sdf)
Load joint.
Definition: GearboxJoint.hh:53
Forward declarations for the common classes.
Definition: Animation.hh:26
std::string referenceBody
reference link/body for computing joint angles
Definition: GearboxJoint.hh:113
GearboxJoint type.
Definition: Base.hh:107
#define gzerr
Output an error message.
Definition: Console.hh:50
virtual void Init()
Initialize joint.
Definition: GearboxJoint.hh:83
A double axis gearbox joint.
Definition: GearboxJoint.hh:36
virtual ~GearboxJoint()
Destructor.
Definition: GearboxJoint.hh:44
virtual double GetGearboxRatio() const
Get gearbox joint gear ratio.
Definition: GearboxJoint.hh:90
GearboxJoint(BasePtr _parent)
Constructor.
Definition: GearboxJoint.hh:40
double gearRatio
Gearbox gearRatio.
Definition: GearboxJoint.hh:110
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:78
virtual void FillMsg(msgs::Joint &_msg)
Definition: GearboxJoint.hh:101
virtual void FillMsg(msgs::Joint &_msg)
Fill a joint message.