All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Joint.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: The base joint class
18  * Author: Nate Koenig, Andrew Howard
19  * Date: 21 May 2003
20  */
21 
22 #ifndef _JOINT_HH_
23 #define _JOINT_HH_
24 
25 #include <string>
26 
27 #include <boost/any.hpp>
28 
29 #include "gazebo/common/Event.hh"
30 #include "gazebo/common/Events.hh"
31 #include "gazebo/math/Angle.hh"
32 #include "gazebo/math/Vector3.hh"
33 #include "gazebo/msgs/MessageTypes.hh"
34 
36 #include "gazebo/physics/Base.hh"
38 
42 #define MAX_JOINT_AXIS 2
43 
44 namespace gazebo
45 {
46  namespace physics
47  {
50 
53  class Joint : public Base
54  {
57  public: enum Attribute
58  {
61 
64 
67 
70 
73 
75  ERP,
76 
78  CFM,
79 
82 
84  VEL,
85 
88 
91  };
92 
95  public: explicit Joint(BasePtr _parent);
96 
98  public: virtual ~Joint();
99 
104  public: void Load(LinkPtr _parent, LinkPtr _child,
105  const math::Pose &_pose);
106 
114  public: void Load(LinkPtr _parent, LinkPtr _child,
115  const math::Vector3 &_pos) GAZEBO_DEPRECATED;
116 
119  public: virtual void Load(sdf::ElementPtr _sdf);
120 
122  public: virtual void Init();
123 
125  public: void Update();
126 
129  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
130 
132  public: virtual void Reset();
133 
136  public: void SetState(const JointState &_state);
137 
140  public: void SetModel(ModelPtr _model);
141 
147  public: virtual LinkPtr GetJointLink(int _index) const = 0;
148 
153  public: virtual bool AreConnected(LinkPtr _one, LinkPtr _two) const = 0;
154 
158  public: virtual void Attach(LinkPtr _parent, LinkPtr _child);
159 
161  public: virtual void Detach();
162 
167  public: virtual void SetAxis(int _index, const math::Vector3 &_axis) = 0;
168 
172  public: virtual void SetDamping(int _index, double _damping) = 0;
173 
175  public: virtual void ApplyDamping();
176 
180  public: template<typename T>
182  {return jointUpdate.Connect(_subscriber);}
183 
187  {jointUpdate.Disconnect(_conn);}
188 
192  public: math::Vector3 GetLocalAxis(int _index) const;
193 
197  public: virtual math::Vector3 GetGlobalAxis(int _index) const = 0;
198 
202  public: virtual void SetAnchor(int _index,
203  const math::Vector3 &_anchor) = 0;
204 
208  public: virtual math::Vector3 GetAnchor(int _index) const = 0;
209 
213  public: virtual void SetHighStop(int _index,
214  const math::Angle &_angle);
215 
219  public: virtual void SetLowStop(int _index,
220  const math::Angle &_angle);
221 
228  public: virtual math::Angle GetHighStop(int _index) = 0;
229 
236  public: virtual math::Angle GetLowStop(int _index) = 0;
237 
241  public: virtual double GetEffortLimit(int _index);
242 
246  public: virtual double GetVelocityLimit(int _index);
247 
251  public: virtual void SetVelocity(int _index, double _vel) = 0;
252 
256  public: virtual double GetVelocity(int _index) const = 0;
257 
266  public: virtual void SetForce(int _index, double _force);
267 
277  public: virtual double GetForce(int _index) GAZEBO_DEPRECATED;
278 
288  public: virtual double GetForce(unsigned int _index);
289 
297  public: virtual JointWrench GetForceTorque(int _index)
298  GAZEBO_DEPRECATED = 0;
299 
307  public: virtual JointWrench GetForceTorque(unsigned int _index) = 0;
308 
317  public: virtual void SetMaxForce(int _index, double _force) = 0;
318 
327  public: virtual double GetMaxForce(int _index) = 0;
328 
332  public: math::Angle GetAngle(int _index) const;
333 
336  public: virtual unsigned int GetAngleCount() const = 0;
337 
347  public: void SetAngle(int _index, math::Angle _angle);
348 
358  public: virtual math::Vector3 GetLinkForce(unsigned int _index) const = 0;
359 
369  public: virtual math::Vector3 GetLinkTorque(
370  unsigned int _index) const = 0;
371 
377  public: virtual void SetAttribute(const std::string &_key, int _index,
378  const boost::any &_value) = 0;
379 
384  public: virtual double GetAttribute(const std::string &_key,
385  unsigned int _index) = 0;
386 
389  public: LinkPtr GetChild() const;
390 
393  public: LinkPtr GetParent() const;
394 
397  public: void FillMsg(msgs::Joint &_msg);
398 
402  public: double GetInertiaRatio(unsigned int _index) const;
403 
408  public: math::Angle GetLowerLimit(unsigned int _index) const
409  {
410  if (_index < this->GetAngleCount())
411  return this->lowerLimit[_index];
412 
413  gzwarn << "requesting lower limit of joint index out of bound\n";
414  return math::Angle();
415  }
416 
421  public: math::Angle GetUpperLimit(unsigned int _index) const
422  {
423  if (_index < this->GetAngleCount())
424  return this->upperLimit[_index];
425 
426  gzwarn << "requesting upper limit of joint index out of bound\n";
427  return math::Angle();
428  }
429 
433  protected: virtual math::Angle GetAngleImpl(int _index) const = 0;
434 
437  private: void LoadImpl(const math::Pose &_pose);
438 
442  private: void LoadImpl(const math::Vector3 &_pos) GAZEBO_DEPRECATED;
443 
447  private: void ComputeInertiaRatio();
448 
450  protected: LinkPtr childLink;
451 
453  protected: LinkPtr parentLink;
454 
456  protected: ModelPtr model;
457 
461 
467  protected: math::Pose anchorPose;
468 
470  protected: LinkPtr anchorLink;
471 
473  private: event::EventT<void ()> jointUpdate;
474 
476  protected: double dampingCoefficient;
477 
479  private: math::Angle staticAngle;
480 
483 
488  protected: double forceApplied[MAX_JOINT_AXIS];
489 
491  protected: double effortLimit[MAX_JOINT_AXIS];
492 
494  protected: double velocityLimit[MAX_JOINT_AXIS];
495 
498  protected: double inertiaRatio[MAX_JOINT_AXIS];
499 
502 
505 
507  protected: bool useCFMDamping;
508  };
510  }
511 }
512 #endif