GearboxJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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/msgs/msgs.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
43  template<class T>
44  class GZ_PHYSICS_VISIBLE GearboxJoint : public T
45  {
48  public: GearboxJoint(BasePtr _parent) : T(_parent), gearRatio(1.0)
49  { this->AddType(Base::GEARBOX_JOINT); }
51  public: virtual ~GearboxJoint()
52  { }
53 
54  // Documentation inherited.
55  public: virtual unsigned int GetAngleCount() const
56  {return 2;}
57 
60  public: virtual void Load(sdf::ElementPtr _sdf)
61  {
62  T::Load(_sdf);
63  if (_sdf->HasElement("gearbox_ratio"))
64  {
65  this->gearRatio =
66  _sdf->Get<double>("gearbox_ratio");
67  }
68  else
69  {
70  gzerr << "gearbox_ratio_not_specified, set to 1.\n";
71  this->gearRatio = 1.0;
72  /* below should bring in default values for sdf 1.4+
73  this->gearRatio =
74  _sdf->Get<double>("gearbox_ratio");
75  */
76  }
77 
78  if (_sdf->HasElement("gearbox_reference_body"))
79  {
80  this->referenceBody =
81  _sdf->Get<std::string>("gearbox_reference_body");
82  }
83  else
84  {
85  gzerr << "Gearbox joint missing reference body.\n";
86  }
87  }
88 
90  protected: virtual void Init()
91  {
92  T::Init();
93  }
94 
97  public: virtual double GetGearboxRatio() const
98  { return this->gearRatio; }
99 
105  public: virtual void SetGearboxRatio(double _gearRatio) = 0;
106 
107  // Documentation inherited
108  public: virtual void FillMsg(msgs::Joint &_msg)
109  {
110  Joint::FillMsg(_msg);
111  msgs::Joint::Gearbox *gearboxMsg = _msg.mutable_gearbox();
112  gearboxMsg->set_gearbox_reference_body(this->referenceBody);
113  gearboxMsg->set_gearbox_ratio(this->gearRatio);
114  }
115 
117  protected: double gearRatio;
118 
120  protected: std::string referenceBody;
121  };
123  }
124 }
125 #endif
virtual void Load(sdf::ElementPtr _sdf)
Load joint.
Definition: GearboxJoint.hh:60
std::string referenceBody
reference link/body for computing joint angles
Definition: GearboxJoint.hh:120
virtual unsigned int GetAngleCount() const
Definition: GearboxJoint.hh:55
GearboxJoint type.
Definition: Base.hh:112
#define gzerr
Output an error message.
Definition: Console.hh:50
virtual void Init()
Initialize joint.
Definition: GearboxJoint.hh:90
A double axis gearbox joint.
Definition: GearboxJoint.hh:44
virtual ~GearboxJoint()
Destructor.
Definition: GearboxJoint.hh:51
virtual double GetGearboxRatio() const
Get gearbox joint gear ratio.
Definition: GearboxJoint.hh:97
GearboxJoint(BasePtr _parent)
Constructor.
Definition: GearboxJoint.hh:48
double gearRatio
Gearbox gearRatio.
Definition: GearboxJoint.hh:117
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:108
virtual void FillMsg(msgs::Joint &_msg)
Fill a joint message.