ODEJoint.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 #ifndef _ODEJOINT_HH_
18 #define _ODEJOINT_HH_
19 
20 #include <boost/any.hpp>
21 #include <string>
22 
24 #include "gazebo/physics/Joint.hh"
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace physics
30  {
33 
35  class GZ_PHYSICS_VISIBLE ODEJoint : public Joint
36  {
38  public: enum CFMMode
39  {
41  NONE = 0x00000000,
43  DAMPING_ACTIVE = 0x00000001,
45  JOINT_LIMIT = 0x00000002
46  };
47 
50  public: ODEJoint(BasePtr _parent);
51 
53  public: virtual ~ODEJoint();
54 
55  // Documentation inherited.
56  public: virtual void Load(sdf::ElementPtr _sdf);
57 
58  // Documentation inherited.
59  public: virtual void Fini();
60 
61  // Documentation inherited.
62  public: virtual void Reset();
63 
64  // Documentation inherited.
65  public: virtual LinkPtr GetJointLink(unsigned int _index) const;
66 
67  // Documentation inherited.
68  public: virtual bool AreConnected(LinkPtr _one, LinkPtr _two) const;
69 
70  // Documentation inherited.
71  public: virtual void CacheForceTorque();
72 
79  public: virtual double GetParam(unsigned int _parameter) const;
80 
87  public: virtual void SetParam(unsigned int _parameter, double _value);
88 
89  // Documentation inherited
90  public: virtual void SetDamping(unsigned int _index, double _damping);
91 
92  // Documentation inherited.
93  public: virtual bool SetPosition(unsigned int _index, double _position);
94 
95  // Documentation inherited.
96  public: virtual void SetStiffness(unsigned int _index,
97  const double _stiffness);
98 
99  // Documentation inherited.
100  public: virtual void SetStiffnessDamping(unsigned int _index,
101  double _stiffness, double _damping, double _reference = 0);
102 
103  // Documentation inherited.
104  public: virtual void Attach(LinkPtr _parent, LinkPtr _child);
105 
106  // Documentation inherited.
107  public: virtual void Detach();
108 
111  public: void SetERP(double _erp);
112 
115  public: double GetERP();
116 
119  public: void SetCFM(double _cfm);
120 
123  public: double GetCFM();
124 
127  public: dJointFeedback *GetFeedback();
128 
131  public: bool UsesImplicitSpringDamper();
132 
135  public: void UseImplicitSpringDamper(const bool _implicit);
136 
139  public: void ApplyImplicitStiffnessDamping();
140 
142  public: void ApplyExplicitStiffnessDamping();
143 
146  public: double GetStopCFM()
147  {
148  return this->stopCFM;
149  }
150 
153  public: double GetStopERP()
154  {
155  return this->stopERP;
156  }
157 
167  private: double ApplyAdaptiveDamping(unsigned int _index,
168  const double _damping);
169 
176  private: void KpKdToCFMERP(const double _dt,
177  const double _kp, const double _kd,
178  double &_cfm, double &_erp);
179 
186  private: void CFMERPToKpKd(const double _dt,
187  const double _cfm, const double _erp,
188  double &_kp, double &_kd);
189 
191  private: int implicitDampingState[MAX_JOINT_AXIS];
192 
194  private: double currentKd[MAX_JOINT_AXIS];
195 
197  private: double currentKp[MAX_JOINT_AXIS];
198 
201  private: bool stiffnessDampingInitialized;
202 
204  private: bool useImplicitSpringDamper;
205 
206  // Documentation inherited.
207  public: virtual bool SetHighStop(unsigned int _index,
208  const math::Angle &_angle);
209 
210  // Documentation inherited.
211  public: virtual bool SetLowStop(unsigned int _index,
212  const math::Angle &_angle);
213 
214  // Documentation inherited.
215  public: virtual math::Angle GetHighStop(unsigned int _index);
216 
217  // Documentation inherited.
218  public: virtual math::Angle GetLowStop(unsigned int _index);
219 
220  // Documentation inherited.
221  public: virtual math::Vector3 GetLinkForce(unsigned int _index) const;
222 
223  // Documentation inherited.
224  public: virtual math::Vector3 GetLinkTorque(unsigned int _index) const;
225 
226  // Documentation inherited.
227  public: virtual void SetAxis(unsigned int _index,
228  const math::Vector3 &_axis);
229 
230  // Documentation inherited.
231  public: virtual bool SetParam(const std::string &_key,
232  unsigned int _index,
233  const boost::any &_value);
234 
235  // Documentation inherited.
236  public: virtual double GetParam(const std::string &_key,
237  unsigned int _index);
238 
239  // Documentation inherited.
240  public: virtual void SetProvideFeedback(bool _enable);
241 
242  // Documentation inherited.
243  public: virtual JointWrench GetForceTorque(unsigned int _index);
244 
245  // Documentation inherited.
246  public: virtual void SetForce(unsigned int _index, double _force);
247 
248  // Documentation inherited.
249  public: virtual double GetForce(unsigned int _index);
250 
251  // Documentation inherited.
252  public: virtual void ApplyStiffnessDamping();
253 
254  // Documentation inherited.
263  protected: virtual void SetForceImpl(
264  unsigned int _index, double _force) = 0;
265 
269  private: void SaveForce(unsigned int _index, double _force);
270 
272  protected: dJointID jointId;
273 
275  private: dJointFeedback *feedback;
276 
278  private: double stopCFM;
279 
281  private: double stopERP;
282 
288  private: double forceApplied[MAX_JOINT_AXIS];
289 
292  private: common::Time forceAppliedTime;
293  };
295  }
296 }
297 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
double GetStopERP()
Get access to stopERP.
Definition: ODEJoint.hh:153
dJointID jointId
This is our ODE ID.
Definition: ODEJoint.hh:272
double GetStopCFM()
Get access to stopCFM.
Definition: ODEJoint.hh:146
CFMMode
internal variables used for implicit damping
Definition: ODEJoint.hh:38
#define MAX_JOINT_AXIS
maximum number of axis per joint anticipated.
Definition: Joint.hh:39
Base class for all joints.
Definition: Joint.hh:50
Wrench information from a joint.
Definition: JointWrench.hh:39
ODE joint interface.
Definition: ODEJoint.hh:35
An angle and related functions.
Definition: Angle.hh:53
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44