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 #include <vector>
27 
28 #include <boost/any.hpp>
29 
30 #include "gazebo/common/Event.hh"
31 #include "gazebo/common/Events.hh"
32 #include "gazebo/math/Angle.hh"
33 #include "gazebo/math/Vector3.hh"
34 #include "gazebo/msgs/MessageTypes.hh"
35 
37 #include "gazebo/physics/Base.hh"
39 
43 #define MAX_JOINT_AXIS 2
44 
45 namespace gazebo
46 {
47  namespace physics
48  {
51 
54  class Joint : public Base
55  {
58  public: enum Attribute
59  {
62 
65 
68 
71 
74 
76  ERP,
77 
79  CFM,
80 
83 
85  VEL,
86 
89 
92  };
93 
96  public: explicit Joint(BasePtr _parent);
97 
99  public: virtual ~Joint();
100 
105  public: void Load(LinkPtr _parent, LinkPtr _child,
106  const math::Pose &_pose);
107 
110  public: virtual void Load(sdf::ElementPtr _sdf);
111 
113  public: virtual void Init();
114 
116  public: void Update();
117 
120  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
121 
123  public: virtual void Reset();
124 
127  public: void SetState(const JointState &_state);
128 
131  public: void SetModel(ModelPtr _model);
132 
138  public: virtual LinkPtr GetJointLink(int _index) const = 0;
139 
144  public: virtual bool AreConnected(LinkPtr _one, LinkPtr _two) const = 0;
145 
149  public: virtual void Attach(LinkPtr _parent, LinkPtr _child);
150 
152  public: virtual void Detach();
153 
159  public: virtual void SetAxis(int _index, const math::Vector3 &_axis) = 0;
160 
165  public: virtual void SetDamping(int _index, double _damping) = 0;
166 
171  public: double GetDamping(int _index);
172 
174  public: virtual void ApplyDamping();
175 
179  public: template<typename T>
181  {return jointUpdate.Connect(_subscriber);}
182 
186  {jointUpdate.Disconnect(_conn);}
187 
191  public: math::Vector3 GetLocalAxis(int _index) const;
192 
196  public: virtual math::Vector3 GetGlobalAxis(int _index) const = 0;
197 
201  public: virtual void SetAnchor(int _index,
202  const math::Vector3 &_anchor) = 0;
203 
207  public: virtual math::Vector3 GetAnchor(int _index) const = 0;
208 
212  public: virtual void SetHighStop(int _index,
213  const math::Angle &_angle);
214 
218  public: virtual void SetLowStop(int _index,
219  const math::Angle &_angle);
220 
227  public: virtual math::Angle GetHighStop(int _index) = 0;
228 
235  public: virtual math::Angle GetLowStop(int _index) = 0;
236 
240  public: virtual double GetEffortLimit(int _index);
241 
245  public: virtual double GetVelocityLimit(int _index);
246 
250  public: virtual void SetVelocity(int _index, double _vel) = 0;
251 
255  public: virtual double GetVelocity(int _index) const = 0;
256 
265  public: virtual void SetForce(int _index, double _effort) = 0;
266 
272  public: double CheckAndTruncateForce(int _index, double _effort);
273 
280  public: virtual double GetForce(unsigned int _index);
281 
304  public: virtual JointWrench GetForceTorque(unsigned int _index) = 0;
305 
311  public: virtual void SetMaxForce(int _index, double _force) = 0;
312 
318  public: virtual double GetMaxForce(int _index) = 0;
319 
323  public: math::Angle GetAngle(int _index) const;
324 
327  public: virtual unsigned int GetAngleCount() const = 0;
328 
338  public: void SetAngle(int _index, math::Angle _angle);
339 
346  public: virtual math::Vector3 GetLinkForce(unsigned int _index) const = 0;
347 
354  public: virtual math::Vector3 GetLinkTorque(
355  unsigned int _index) const = 0;
356 
362  public: virtual void SetAttribute(const std::string &_key, int _index,
363  const boost::any &_value) = 0;
364 
369  public: virtual double GetAttribute(const std::string &_key,
370  unsigned int _index) = 0;
371 
374  public: LinkPtr GetChild() const;
375 
378  public: LinkPtr GetParent() const;
379 
382  public: void FillMsg(msgs::Joint &_msg);
383 
387  public: double GetInertiaRatio(unsigned int _index) const;
388 
393  public: math::Angle GetLowerLimit(unsigned int _index) const;
394 
399  public: math::Angle GetUpperLimit(unsigned int _index) const;
400 
403  public: virtual void SetProvideFeedback(bool _enable);
404 
406  public: virtual void CacheForceTorque() { }
407 
410  public: double GetDampingCoefficient() const;
411 
415  protected: virtual math::Angle GetAngleImpl(int _index) const = 0;
416 
419  private: void LoadImpl(const math::Pose &_pose);
420 
424  private: void ComputeInertiaRatio();
425 
427  protected: LinkPtr childLink;
428 
430  protected: LinkPtr parentLink;
431 
433  protected: ModelPtr model;
434 
438 
444  protected: math::Pose anchorPose;
445 
447  protected: LinkPtr anchorLink;
448 
450  protected: double dampingCoefficient;
451 
454 
456  protected: double effortLimit[MAX_JOINT_AXIS];
457 
459  protected: double velocityLimit[MAX_JOINT_AXIS];
460 
463  protected: double inertiaRatio[MAX_JOINT_AXIS];
464 
467 
470 
473  protected: JointWrench wrench;
474 
476  protected: bool useCFMDamping;
477 
480  private: static sdf::ElementPtr sdfJoint;
481 
483  protected: bool provideFeedback;
484 
486  private: std::vector<std::string> sensors;
487 
489  private: event::EventT<void ()> jointUpdate;
490 
492  private: math::Angle staticAngle;
493  };
495  }
496 }
497 #endif