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 (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 /* 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), threadPitch(0)
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")->Get<double>();
63  }
64  else
65  {
66  this->threadPitch = 1.0;
67  gzwarn << "<thread_pitch> element not specified. "
68  << "Using default value of "
69  << this->threadPitch
70  << ". \n";
71  }
72 
73  if (_sdf->HasElement("axis"))
74  {
75  sdf::ElementPtr axisElem = _sdf->GetElement("axis");
76  this->SetAxis(0, axisElem->Get<math::Vector3>("xyz"));
77  if (axisElem->HasElement("limit"))
78  {
79  sdf::ElementPtr limitElem =
80  _sdf->GetElement("axis")->GetElement("limit");
81 
82  // Perform this three step ordering to ensure the
83  // parameters are set properly. This is taken from
84  // the ODE wiki.
85  this->SetHighStop(0, limitElem->Get<double>("upper"));
86  this->SetLowStop(0, limitElem->Get<double>("lower"));
87  this->SetHighStop(0, limitElem->Get<double>("upper"));
88  }
89  }
90  }
91 
95  public: virtual void SetAnchor(int _index, const math::Vector3 &_anchor);
96 
100  public: virtual math::Vector3 GetAnchor(int _index) const;
101 
107  public: virtual void SetThreadPitch(int _index, double _threadPitch) = 0;
108 
114  public: virtual double GetThreadPitch(unsigned int _index) = 0;
115 
118 
120  protected: double threadPitch;
121  };
123 
124  template<class T>
125  void ScrewJoint<T>::SetAnchor(int /*_index*/,
126  const math::Vector3 &_anchor)
127  {this->fakeAnchor = _anchor;}
128 
129  template<class T>
131  {return this->fakeAnchor;}
132  }
133 }
134 #endif