All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ScrewJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 /* Desc: A screw or primastic/rotational joint
18  * Author: Nate Koenig, John Hsu
19  * Date: 21 May 2003
20  */
21 
22 #ifndef _SCREWJOINT_HH_
23 #define _SCREWJOINT_HH_
24 
25 #include "gazebo/physics/Joint.hh"
26 #include "gazebo/common/Console.hh"
27 
28 namespace gazebo
29 {
30  namespace physics
31  {
34 
37  template<class T>
38  class ScrewJoint : public T
39  {
42  public: explicit ScrewJoint(BasePtr _parent) : T(_parent)
43  {this->AddType(Base::SCREW_JOINT);}
44 
46  public: virtual ~ScrewJoint()
47  { }
48 
50  public: virtual unsigned int GetAngleCount() const
51  {return 2;}
52 
55  public: virtual void Load(sdf::ElementPtr _sdf)
56  {
57  T::Load(_sdf);
58 
59  if (_sdf->HasElement("thread_pitch"))
60  {
61  this->threadPitch =
62  _sdf->GetElement("thread_pitch")->GetValueDouble();
63  }
64  else
65  {
66  gzerr << "should not see this\n";
67  this->threadPitch = 1.0;
68  }
69 
70  if (_sdf->HasElement("axis"))
71  {
72  sdf::ElementPtr axisElem = _sdf->GetElement("axis");
73  this->SetAxis(0, axisElem->GetValueVector3("xyz"));
74  if (axisElem->HasElement("limit"))
75  {
76  sdf::ElementPtr limitElem =
77  _sdf->GetElement("axis")->GetElement("limit");
78 
79  // Perform this three step ordering to ensure the
80  // parameters are set properly. This is taken from
81  // the ODE wiki.
82  this->SetHighStop(0, limitElem->GetValueDouble("upper"));
83  this->SetLowStop(0, limitElem->GetValueDouble("lower"));
84  this->SetHighStop(0, limitElem->GetValueDouble("upper"));
85  }
86  }
87  }
88 
92  public: virtual void SetAnchor(int _index,
93  const math::Vector3 &_anchor);
94 
98  public: virtual math::Vector3 GetAnchor(int _index) const;
99 
105  public: virtual void SetThreadPitch(int _index, double _threadPitch) = 0;
106 
112  public: virtual double GetThreadPitch(unsigned int _index) = 0;
113 
116 
118  protected: double threadPitch;
119  };
121 
122  template<class T>
123  void ScrewJoint<T>::SetAnchor(int /*_index*/,
124  const math::Vector3 &_anchor)
125  {this->fakeAnchor = _anchor;}
126 
127  template<class T>
129  {return this->fakeAnchor;}
130  }
131 }
132 #endif