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 #ifdef _WIN32
22  // Ensure that Winsock2.h is included before Windows.h, which can get
23  // pulled in by anybody (e.g., Boost).
24  #include <Winsock2.h>
25 #endif
26 
27 #include <string>
28 
29 #include "gazebo/math/Vector3.hh"
30 #include "gazebo/msgs/msgs.hh"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace physics
36  {
39 
42  template<class T>
43  class GZ_PHYSICS_VISIBLE GearboxJoint : public T
44  {
47  public: GearboxJoint(BasePtr _parent) : T(_parent), gearRatio(1.0)
48  { this->AddType(Base::GEARBOX_JOINT); }
50  public: virtual ~GearboxJoint()
51  { }
52 
53  // Documentation inherited.
54  public: virtual unsigned int DOF() const
55  {return 2;}
56 
59  public: virtual void Load(sdf::ElementPtr _sdf)
60  {
61  T::Load(_sdf);
62  if (_sdf->HasElement("gearbox_ratio"))
63  {
64  this->gearRatio =
65  _sdf->Get<double>("gearbox_ratio");
66  }
67  else
68  {
69  gzerr << "gearbox_ratio_not_specified, set to 1.\n";
70  this->gearRatio = 1.0;
71  /* below should bring in default values for sdf 1.4+
72  this->gearRatio =
73  _sdf->Get<double>("gearbox_ratio");
74  */
75  }
76 
77  if (_sdf->HasElement("gearbox_reference_body"))
78  {
79  this->referenceBody =
80  _sdf->Get<std::string>("gearbox_reference_body");
81  }
82  else
83  {
84  gzerr << "Gearbox joint missing reference body.\n";
85  }
86  }
87 
89  protected: virtual void Init()
90  {
91  T::Init();
92  }
93 
96  public: virtual double GetGearboxRatio() const
97  { return this->gearRatio; }
98 
104  public: virtual void SetGearboxRatio(double _gearRatio) = 0;
105 
106  // Documentation inherited
107  public: virtual void FillMsg(msgs::Joint &_msg)
108  {
109  Joint::FillMsg(_msg);
110  msgs::Joint::Gearbox *gearboxMsg = _msg.mutable_gearbox();
111  gearboxMsg->set_gearbox_reference_body(this->referenceBody);
112  gearboxMsg->set_gearbox_ratio(this->gearRatio);
113  }
114 
116  protected: double gearRatio;
117 
119  protected: std::string referenceBody;
120  };
122  }
123 }
124 #endif
virtual void Load(sdf::ElementPtr _sdf)
Load joint.
Definition: GearboxJoint.hh:59
Forward declarations for the common classes.
Definition: Animation.hh:33
std::string referenceBody
reference link/body for computing joint angles
Definition: GearboxJoint.hh:119
GearboxJoint type.
Definition: Base.hh:112
#define gzerr
Output an error message.
Definition: Console.hh:50
virtual void Init()
Initialize joint.
Definition: GearboxJoint.hh:89
A double axis gearbox joint.
Definition: GearboxJoint.hh:43
virtual ~GearboxJoint()
Destructor.
Definition: GearboxJoint.hh:50
virtual double GetGearboxRatio() const
Get gearbox joint gear ratio.
Definition: GearboxJoint.hh:96
virtual unsigned int DOF() const
Definition: GearboxJoint.hh:54
GearboxJoint(BasePtr _parent)
Constructor.
Definition: GearboxJoint.hh:47
double gearRatio
Gearbox gearRatio.
Definition: GearboxJoint.hh:116
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
virtual void FillMsg(msgs::Joint &_msg)
Definition: GearboxJoint.hh:107
virtual void FillMsg(msgs::Joint &_msg)
Fill a joint message.