All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GearboxJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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/math/Angle.hh"
24 #include "gazebo/math/Vector3.hh"
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace physics
30  {
33 
36  template<class T>
37  class GAZEBO_VISIBLE GearboxJoint : public T
38  {
41  public: GearboxJoint(BasePtr _parent) : 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 GetAngleCount() 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 
101  protected: double gearRatio;
102 
104  protected: std::string referenceBody;
105  };
107  }
108 }
109 #endif
110 
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:66
virtual double GetGearboxRatio() const
Get gearbox joint gear ratio.
Definition: GearboxJoint.hh:90
double gearRatio
Gearbox gearRatio.
Definition: GearboxJoint.hh:101
GearboxJoint(BasePtr _parent)
Constructor.
Definition: GearboxJoint.hh:41
virtual unsigned int GetAngleCount() const
Definition: GearboxJoint.hh:48
#define gzerr
Output an error message.
Definition: Console.hh:47
A double axis gearbox joint.
Definition: GearboxJoint.hh:37
virtual void Init()
Initialize joint.
Definition: GearboxJoint.hh:83
virtual ~GearboxJoint()
Destructor.
Definition: GearboxJoint.hh:44
std::string referenceBody
reference link/body for computing joint angles
Definition: GearboxJoint.hh:104
GearboxJoint type.
Definition: Base.hh:111
virtual void Load(sdf::ElementPtr _sdf)
Load joint.
Definition: GearboxJoint.hh:53
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48