ODEJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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  {
32  class GAZEBO_VISIBLE ODEJoint : public Joint
33  {
35  public: enum CFMMode
36  {
38  NONE = 0x00000000,
40  DAMPING_ACTIVE = 0x00000001,
42  JOINT_LIMIT = 0x00000002
43  };
44 
47  public: ODEJoint(BasePtr _parent);
48 
50  public: virtual ~ODEJoint();
51 
52  // Documentation inherited.
53  public: virtual void Load(sdf::ElementPtr _sdf);
54 
55  // Documentation inherited.
56  public: virtual void Reset();
57 
58  // Documentation inherited.
59  public: virtual LinkPtr GetJointLink(unsigned int _index) const;
60 
61  // Documentation inherited.
62  public: virtual bool AreConnected(LinkPtr _one, LinkPtr _two) const;
63 
70  public: virtual double GetParam(unsigned int _parameter) const;
71 
78  public: virtual void SetParam(unsigned int _parameter, double _value);
79 
80  // Documentation inherited
81  public: virtual void SetDamping(unsigned int _index, double _damping);
82 
83  // Documentation inherited.
84  public: virtual bool SetPosition(unsigned int _index, double _position);
85 
86  // Documentation inherited.
87  public: virtual void SetStiffness(unsigned int _index,
88  const double _stiffness);
89 
90  // Documentation inherited.
91  public: virtual void SetStiffnessDamping(unsigned int _index,
92  double _stiffness, double _damping, double _reference = 0);
93 
94  // Documentation inherited.
95  public: virtual void Attach(LinkPtr _parent, LinkPtr _child);
96 
97  // Documentation inherited.
98  public: virtual void Detach();
99 
102  public: void SetERP(double _erp);
103 
106  public: double GetERP();
107 
110  public: void SetCFM(double _cfm);
111 
114  public: double GetCFM();
115 
118  public: dJointFeedback *GetFeedback();
119 
122  public: bool UsesImplicitSpringDamper();
123 
126  public: void UseImplicitSpringDamper(const bool _implicit);
127 
130  public: void ApplyImplicitStiffnessDamping();
131 
133  public: void ApplyExplicitStiffnessDamping();
134 
137  public: double GetStopCFM()
138  {
139  return this->stopCFM;
140  }
141 
144  public: double GetStopERP()
145  {
146  return this->stopERP;
147  }
148 
158  private: double ApplyAdaptiveDamping(unsigned int _index,
159  const double _damping);
160 
167  private: void KpKdToCFMERP(const double _dt,
168  const double _kp, const double _kd,
169  double &_cfm, double &_erp);
170 
177  private: void CFMERPToKpKd(const double _dt,
178  const double _cfm, const double _erp,
179  double &_kp, double &_kd);
180 
182  private: int implicitDampingState[MAX_JOINT_AXIS];
183 
185  private: double currentKd[MAX_JOINT_AXIS];
186 
188  private: double currentKp[MAX_JOINT_AXIS];
189 
192  private: bool stiffnessDampingInitialized;
193 
195  private: bool useImplicitSpringDamper;
196 
197  // Documentation inherited.
198  public: virtual bool SetHighStop(unsigned int _index,
199  const math::Angle &_angle);
200 
201  // Documentation inherited.
202  public: virtual bool SetLowStop(unsigned int _index,
203  const math::Angle &_angle);
204 
205  // Documentation inherited.
206  public: virtual math::Angle GetHighStop(unsigned int _index);
207 
208  // Documentation inherited.
209  public: virtual math::Angle GetLowStop(unsigned int _index);
210 
211  // Documentation inherited.
212  public: virtual math::Vector3 GetLinkForce(unsigned int _index) const;
213 
214  // Documentation inherited.
215  public: virtual math::Vector3 GetLinkTorque(unsigned int _index) const;
216 
217  // Documentation inherited.
218  public: virtual void SetAxis(unsigned int _index,
219  const math::Vector3 &_axis);
220 
221  // Documentation inherited.
222  public: virtual bool SetParam(const std::string &_key,
223  unsigned int _index,
224  const boost::any &_value);
225 
226  // Documentation inherited.
227  public: virtual double GetParam(const std::string &_key,
228  unsigned int _index);
229 
230  // Documentation inherited.
231  public: virtual void SetProvideFeedback(bool _enable);
232 
233  // Documentation inherited.
234  public: virtual JointWrench GetForceTorque(unsigned int _index);
235 
236  // Documentation inherited.
237  public: virtual void SetForce(unsigned int _index, double _force);
238 
239  // Documentation inherited.
240  public: virtual double GetForce(unsigned int _index);
241 
242  // Documentation inherited.
243  public: virtual void ApplyStiffnessDamping();
244 
245  // Documentation inherited.
254  protected: virtual void SetForceImpl(
255  unsigned int _index, double _force) = 0;
256 
260  private: void SaveForce(unsigned int _index, double _force);
261 
263  protected: dJointID jointId;
264 
266  private: dJointFeedback *feedback;
267 
269  private: double stopCFM;
270 
272  private: double stopERP;
273 
279  private: double forceApplied[MAX_JOINT_AXIS];
280 
283  private: common::Time forceAppliedTime;
284  };
285  }
286 }
287 #endif
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:66
double GetStopCFM()
Get access to stopCFM.
Definition: ODEJoint.hh:137
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
dJointID jointId
This is our ODE ID.
Definition: ODEJoint.hh:263
CFMMode
internal variables used for implicit damping
Definition: ODEJoint.hh:35
#define MAX_JOINT_AXIS
maximum number of axis per joint anticipated.
Definition: Joint.hh:39
double GetStopERP()
Get access to stopERP.
Definition: ODEJoint.hh:144
Base class for all joints.
Definition: Joint.hh:50
Wrench information from a joint.
Definition: JointWrench.hh:39
ODE joint interface.
Definition: ODEJoint.hh:32
An angle and related functions.
Definition: Angle.hh:52
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:90
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43