GearboxJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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/Angle.hh"
30 #include "gazebo/math/Vector3.hh"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace physics
36  {
39 
42  template<class 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 GetAngleCount() 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 
107  protected: double gearRatio;
108 
110  protected: std::string referenceBody;
111  };
113  }
114 }
115 #endif
116 
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:68
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:318
virtual double GetGearboxRatio() const
Get gearbox joint gear ratio.
Definition: GearboxJoint.hh:96
double gearRatio
Gearbox gearRatio.
Definition: GearboxJoint.hh:107
GearboxJoint(BasePtr _parent)
Constructor.
Definition: GearboxJoint.hh:47
virtual unsigned int GetAngleCount() const
Definition: GearboxJoint.hh:54
#define gzerr
Output an error message.
Definition: Console.hh:49
A double axis gearbox joint.
Definition: GearboxJoint.hh:43
virtual void Init()
Initialize joint.
Definition: GearboxJoint.hh:89
virtual ~GearboxJoint()
Destructor.
Definition: GearboxJoint.hh:50
std::string referenceBody
reference link/body for computing joint angles
Definition: GearboxJoint.hh:110
GearboxJoint type.
Definition: Base.hh:117
virtual void Load(sdf::ElementPtr _sdf)
Load joint.
Definition: GearboxJoint.hh:59
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.