BulletJoint.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 Bullet joint class
18  * Author: Nate Koenig, Andrew Howard
19  * Date: 21 May 2003
20  */
21 
22 #ifndef _BULLETJOINT_HH_
23 #define _BULLETJOINT_HH_
24 
25 #include <boost/any.hpp>
26 #include <string>
27 
29 #include "gazebo/physics/Joint.hh"
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace physics
35  {
39 
41  class GZ_PHYSICS_VISIBLE BulletJoint : public Joint
42  {
44  public: explicit BulletJoint(BasePtr _parent);
45 
47  public: virtual ~BulletJoint();
48 
50  public: virtual void Load(sdf::ElementPtr _sdf) override;
51 
52  // Documentation inherited.
53  public: virtual void Fini() override;
54 
56  public: virtual void Reset() override;
57 
60  public: LinkPtr GetJointLink(unsigned int _index) const override;
61 
63  public: bool AreConnected(LinkPtr _one, LinkPtr _two) const override;
64 
66  public: virtual void Detach() override;
67 
69  public: virtual void SetAnchor(const unsigned int _index,
70  const ignition::math::Vector3d &_anchor)
71  override;
72 
73  // Documentation inherited
74  public: virtual void SetDamping(unsigned int _index, double _damping)
75  override;
76 
77  // Documentation inherited.
78  public: virtual bool SetPosition(
79  const unsigned int _index, const double _position,
80  const bool _preserveWorldVelocity = false) override;
81 
82  // Documentation inherited.
83  public: virtual void SetStiffness(unsigned int _index,
84  const double _stiffness) override;
85 
86  // Documentation inherited.
87  public: virtual void SetStiffnessDamping(unsigned int _index,
88  double _stiffness, double _damping, double _reference = 0) override;
89 
91  public: virtual ignition::math::Vector3d Anchor(
92  const unsigned int _index) const override;
93 
96  public: virtual ignition::math::Vector3d LinkForce(
97  const unsigned int _index) const override;
98 
101  public: virtual ignition::math::Vector3d LinkTorque(
102  const unsigned int _index) const override;
103 
104  // Documentation inherited.
105  public: virtual bool SetParam(const std::string &_key,
106  unsigned int _index,
107  const boost::any &_value) override;
108 
109  // Documentation inherited.
110  public: virtual double GetParam(const std::string &_key,
111  unsigned int _index) override;
112 
113  // Documentation inherited.
114  public: virtual void SetProvideFeedback(bool _enable) override;
115 
116  // Documentation inherited.
117  public: virtual void CacheForceTorque() override;
118 
119  // Documentation inherited.
120  public: virtual JointWrench GetForceTorque(unsigned int _index) override;
121 
122  // Documentation inherited.
123  public: virtual void SetForce(unsigned int _index, double _force)
124  override;
125 
126  // Documentation inherited.
127  public: virtual double GetForce(unsigned int _index) override;
128 
129  // Documentation inherited.
130  public: virtual void Init() override;
131 
132  // Documentation inherited.
133  public: virtual void ApplyStiffnessDamping() override;
134 
145  protected: virtual void SetForceImpl(unsigned int _index,
146  double _force) = 0;
147 
150  protected: void SetupJointFeedback();
151 
155  private: void SaveForce(unsigned int _index, double _force);
156 
158  protected: btTypedConstraint *constraint;
159 
161  protected: btDynamicsWorld *bulletWorld;
162 
164  private: btJointFeedback *feedback;
165 
168  private: bool stiffnessDampingInitialized;
169 
175  private: double forceApplied[MAX_JOINT_AXIS];
176 
179  private: common::Time forceAppliedTime;
180  };
182  }
183 }
184 #endif
#define MAX_JOINT_AXIS
maximum number of axis per joint anticipated.
Definition: Joint.hh:39
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:48
Base class for all joints.
Definition: BulletJoint.hh:42
virtual ~BulletJoint()
Destructor.
virtual void SetDamping(unsigned int _index, double _damping) override
Set the joint damping.
virtual ignition::math::Vector3d LinkForce(const unsigned int _index) const override
Get the force the joint applies to the first body.
virtual void ApplyStiffnessDamping() override
Callback to apply spring stiffness and viscous damping effects to joint.
virtual void Detach() override
Detach this joint from all bodies.
virtual ignition::math::Vector3d LinkTorque(const unsigned int _index) const override
Get the torque the joint applies to the first body.
virtual ignition::math::Vector3d Anchor(const unsigned int _index) const override
Get the anchor point.
btDynamicsWorld * bulletWorld
Pointer to Bullet's btDynamicsWorld.
Definition: BulletJoint.hh:161
virtual bool SetPosition(const unsigned int _index, const double _position, const bool _preserveWorldVelocity=false) override
The child links of this joint are updated based on desired position.
virtual JointWrench GetForceTorque(unsigned int _index) override
get internal force and torque values at a joint.
virtual double GetForce(unsigned int _index) override
virtual void SetProvideFeedback(bool _enable) override
Set whether the joint should generate feedback.
LinkPtr GetJointLink(unsigned int _index) const override
Get the body to which the joint is attached according the _index.
virtual double GetParam(const std::string &_key, unsigned int _index) override
Get a non-generic parameter for the joint.
void SetupJointFeedback()
: Setup joint feedback datatructure.
virtual void SetForce(unsigned int _index, double _force) override
Set the force applied to this physics::Joint.
virtual void SetStiffnessDamping(unsigned int _index, double _stiffness, double _damping, double _reference=0) override
Set the joint spring stiffness.
virtual void Fini() override
Finialize the object.
virtual void SetAnchor(const unsigned int _index, const ignition::math::Vector3d &_anchor) override
Set the anchor point.
BulletJoint(BasePtr _parent)
Constructor.
bool AreConnected(LinkPtr _one, LinkPtr _two) const override
Determines of the two bodies are connected by a joint.
btTypedConstraint * constraint
Pointer to a contraint object in Bullet.
Definition: BulletJoint.hh:158
virtual void CacheForceTorque() override
Cache Joint Force Torque Values if necessary for physics engine.
virtual void Reset() override
Reset the joint.
virtual void SetForceImpl(unsigned int _index, double _force)=0
Set the force applied to this physics::Joint.
virtual void SetStiffness(unsigned int _index, const double _stiffness) override
Set the joint spring stiffness.
virtual void Init() override
Initialize a joint.
virtual void Load(sdf::ElementPtr _sdf) override
Load a BulletJoint.
virtual bool SetParam(const std::string &_key, unsigned int _index, const boost::any &_value) override
Set a non-generic parameter for the joint.
Wrench information from a joint.
Definition: JointWrench.hh:41
Base class for all joints.
Definition: Joint.hh:51
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
Forward declarations for the common classes.
Definition: Animation.hh:27