Joint.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 #ifndef GAZEBO_PHYSICS_JOINT_HH_
18 #define GAZEBO_PHYSICS_JOINT_HH_
19 
20 #include <string>
21 #include <vector>
22 
23 #include <boost/any.hpp>
24 #include <ignition/math/Pose3.hh>
25 #include <ignition/math/Vector3.hh>
26 
27 #include "gazebo/common/Event.hh"
28 #include "gazebo/common/Events.hh"
29 #include "gazebo/math/Angle.hh"
30 #include "gazebo/math/Pose.hh"
31 #include "gazebo/math/Vector3.hh"
32 #include "gazebo/msgs/MessageTypes.hh"
33 
35 #include "gazebo/physics/Base.hh"
37 #include "gazebo/util/system.hh"
38 
42 #define MAX_JOINT_AXIS 2
43 
44 namespace gazebo
45 {
46  namespace physics
47  {
50 
53  class GZ_PHYSICS_VISIBLE 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 
90  LO_STOP
91  };
92 
95  public: explicit Joint(BasePtr _parent);
96 
98  public: virtual ~Joint();
99 
105  public: void Load(LinkPtr _parent, LinkPtr _child,
106  const math::Pose &_pose) GAZEBO_DEPRECATED(8.0);
107 
112  public: void Load(LinkPtr _parent, LinkPtr _child,
113  const ignition::math::Pose3d &_pose);
114 
117  public: virtual void Load(sdf::ElementPtr _sdf);
118 
120  public: virtual void Init();
121 
123  public: virtual void Fini();
124 
126  public: void Update();
127 
130  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
131 
133  public: virtual void Reset();
134  using Base::Reset;
135 
138  public: void SetState(const JointState &_state);
139 
142  public: void SetModel(ModelPtr _model);
143 
149  public: virtual LinkPtr GetJointLink(unsigned int _index) const = 0;
150 
155  public: virtual bool AreConnected(LinkPtr _one, LinkPtr _two) const = 0;
156 
160  public: virtual void Attach(LinkPtr _parent, LinkPtr _child);
161 
163  public: virtual void Detach();
164 
171  public: virtual void SetAxis(unsigned int _index,
172  const math::Vector3 &_axis) GAZEBO_DEPRECATED(8.0);
173 
179  public: virtual void SetAxis(const unsigned int _index,
180  const ignition::math::Vector3d &_axis) = 0;
181 
186  public: virtual void SetDamping(unsigned int _index, double _damping) = 0;
187 
192  public: double GetDamping(unsigned int _index);
193 
197  public: virtual void ApplyStiffnessDamping();
198 
205  public: virtual void SetStiffnessDamping(unsigned int _index,
206  double _stiffness, double _damping, double _reference = 0) = 0;
207 
213  public: virtual void SetStiffness(unsigned int _index,
214  const double _stiffness) = 0;
215 
221  public: double GetStiffness(unsigned int _index);
222 
227  public: double GetSpringReferencePosition(unsigned int _index) const;
228 
232  public: template<typename T>
234  {return jointUpdate.Connect(_subscriber);}
235 
240  GAZEBO_DEPRECATED(8.0)
241  {jointUpdate.Disconnect(_conn->Id());}
242 
247  public: math::Vector3 GetLocalAxis(unsigned int _index) const
248  GAZEBO_DEPRECATED(8.0);
249 
253  public: ignition::math::Vector3d LocalAxis(const unsigned int _index)
254  const;
255 
260  public: virtual math::Vector3 GetGlobalAxis(
261  unsigned int _index) const GAZEBO_DEPRECATED(8.0);
262 
266  public: virtual ignition::math::Vector3d GlobalAxis(
267  unsigned int _index) const = 0;
268 
273  public: virtual void SetAnchor(unsigned int _index,
274  const math::Vector3 &_anchor) GAZEBO_DEPRECATED(8.0);
275 
279  public: virtual void SetAnchor(const unsigned int _index,
280  const ignition::math::Vector3d &_anchor) = 0;
281 
286  public: virtual math::Vector3 GetAnchor(unsigned int _index) const
287  GAZEBO_DEPRECATED(8.0);
288 
292  public: virtual ignition::math::Vector3d Anchor(
293  const unsigned int _index) const = 0;
294 
299  public: virtual bool SetHighStop(unsigned int _index,
300  const math::Angle &_angle) GAZEBO_DEPRECATED(8.0);
301 
306  public: virtual bool SetLowStop(unsigned int _index,
307  const math::Angle &_angle) GAZEBO_DEPRECATED(8.0);
308 
316  public: virtual math::Angle GetHighStop(unsigned int _index)
317  GAZEBO_DEPRECATED(8.0);
318 
326  public: virtual math::Angle GetLowStop(unsigned int _index)
327  GAZEBO_DEPRECATED(8.0);
328 
332  public: virtual double GetEffortLimit(unsigned int _index);
333 
337  public: virtual void SetEffortLimit(unsigned int _index, double _effort);
338 
342  public: virtual double GetVelocityLimit(unsigned int _index);
343 
347  public: virtual void SetVelocityLimit(unsigned int _index,
348  double _velocity);
349 
357  public: virtual void SetVelocity(unsigned int _index, double _vel) = 0;
358 
362  public: virtual double GetVelocity(unsigned int _index) const = 0;
363 
372  public: virtual void SetForce(unsigned int _index, double _effort) = 0;
373 
379  public: double CheckAndTruncateForce(unsigned int _index, double _effort);
380 
387  public: virtual double GetForce(unsigned int _index);
388 
411  public: virtual JointWrench GetForceTorque(unsigned int _index) = 0;
412 
417  public: math::Angle GetAngle(unsigned int _index) const
418  GAZEBO_DEPRECATED(8.0);
419 
436  public: virtual double Position(const unsigned int _index = 0) const
437  final;
438 
442  public: virtual unsigned int GetAngleCount() const GAZEBO_DEPRECATED(8.0);
443 
446  public: virtual unsigned int DOF() const = 0;
447 
456  public: virtual bool SetPosition(unsigned int _index, double _position);
457 
466  protected: bool SetPositionMaximal(unsigned int _index, double _position);
467 
475  protected: bool SetVelocityMaximal(unsigned int _index, double _velocity);
476 
484  public: virtual math::Vector3 GetLinkForce(unsigned int _index) const
485  GAZEBO_DEPRECATED(8.0);
486 
493  public: virtual ignition::math::Vector3d LinkForce(
494  const unsigned int _index) const = 0;
495 
503  public: virtual math::Vector3 GetLinkTorque(
504  unsigned int _index) const GAZEBO_DEPRECATED(8.0);
505 
512  public: virtual ignition::math::Vector3d LinkTorque(
513  const unsigned int _index) const = 0;
514 
524  public: virtual bool SetParam(const std::string &_key,
525  unsigned int _index,
526  const boost::any &_value) = 0;
527 
532  public: virtual double GetParam(const std::string &_key,
533  unsigned int _index);
534 
537  public: LinkPtr GetChild() const;
538 
541  public: LinkPtr GetParent() const;
542 
545  public: msgs::Joint::Type GetMsgType() const;
546 
549  public: virtual void FillMsg(msgs::Joint &_msg);
550 
558  public: double GetInertiaRatio(const unsigned int _index) const;
559 
570  public: double GetInertiaRatio(const math::Vector3 &_axis) const
571  GAZEBO_DEPRECATED(8.0);
572 
582  public: double InertiaRatio(const ignition::math::Vector3d &_axis) const;
583 
589  public: math::Angle GetLowerLimit(unsigned int _index) const
590  GAZEBO_DEPRECATED(8.0);
591 
596  public: virtual double LowerLimit(unsigned int _index = 0) const;
597 
603  public: math::Angle GetUpperLimit(unsigned int _index) const
604  GAZEBO_DEPRECATED(8.0);
605 
617  public: virtual double UpperLimit(const unsigned int _index = 0) const;
618 
624  public: void SetLowerLimit(unsigned int _index, math::Angle _limit)
625  GAZEBO_DEPRECATED(8.0);
626 
638  public: virtual void SetLowerLimit(const unsigned int _index,
639  const double _limit);
640 
646  public: void SetUpperLimit(unsigned int _index, math::Angle _limit)
647  GAZEBO_DEPRECATED(8.0);
648 
653  public: virtual void SetUpperLimit(const unsigned int _index,
654  const double _limit);
655 
658  public: virtual void SetProvideFeedback(bool _enable);
659 
661  public: virtual void CacheForceTorque();
662 
666  public: void SetStopStiffness(unsigned int _index, double _stiffness);
667 
671  public: void SetStopDissipation(unsigned int _index, double _dissipation);
672 
676  public: double GetStopStiffness(unsigned int _index) const;
677 
681  public: double GetStopDissipation(unsigned int _index) const;
682 
687  public: math::Pose GetInitialAnchorPose() const GAZEBO_DEPRECATED(8.0);
688 
692  public: ignition::math::Pose3d InitialAnchorPose() const;
693 
699  public: math::Pose GetWorldPose() const GAZEBO_DEPRECATED(8.0);
700 
705  public: ignition::math::Pose3d WorldPose() const;
706 
713  public: math::Pose GetParentWorldPose() const GAZEBO_DEPRECATED(8.0);
714 
720  public: ignition::math::Pose3d ParentWorldPose() const;
721 
728  public: math::Pose GetAnchorErrorPose() const GAZEBO_DEPRECATED(8.0);
729 
735  public: ignition::math::Pose3d AnchorErrorPose() const;
736 
743  public: math::Quaternion GetAxisFrame(unsigned int _index) const
744  GAZEBO_DEPRECATED(8.0);
745 
751  public: ignition::math::Quaterniond AxisFrame(
752  const unsigned int _index) const;
753 
767  public: math::Quaternion GetAxisFrameOffset(unsigned int _index) const
768  GAZEBO_DEPRECATED(8.0);
769 
782  public: ignition::math::Quaterniond AxisFrameOffset(
783  const unsigned int _index) const;
784 
789  public: double GetWorldEnergyPotentialSpring(unsigned int _index) const;
790 
795  protected: virtual math::Angle GetAngleImpl(
796  unsigned int _index) const GAZEBO_DEPRECATED(8.0);
797 
805  protected: virtual double PositionImpl(const unsigned int _index = 0)
806  const = 0;
807 
818  protected: bool FindAllConnectedLinks(const LinkPtr &_originalParentLink,
819  Link_V &_connectedLinks);
820 
827  protected: math::Pose ComputeChildLinkPose(unsigned int _index,
828  double _position) GAZEBO_DEPRECATED(8.0);
829 
835  protected: ignition::math::Pose3d ChildLinkPose(
836  const unsigned int _index, const double _position);
837 
839  protected: virtual void RegisterIntrospectionItems();
840 
843  private: void RegisterIntrospectionPosition(const unsigned int _index);
844 
847  private: void RegisterIntrospectionVelocity(const unsigned int _index);
848 
851  private: void LoadImpl(const ignition::math::Pose3d &_pose);
852 
854  protected: LinkPtr childLink;
855 
857  protected: LinkPtr parentLink;
858 
860  protected: ModelPtr model;
861 
864  protected: ignition::math::Vector3d anchorPos;
865 
871  protected: ignition::math::Pose3d anchorPose;
872 
874  protected: ignition::math::Pose3d parentAnchorPose;
875 
877  protected: LinkPtr anchorLink;
878 
880  protected: double dissipationCoefficient[MAX_JOINT_AXIS];
881 
883  protected: double stiffnessCoefficient[MAX_JOINT_AXIS];
884 
886  protected: double springReferencePosition[MAX_JOINT_AXIS];
887 
889  protected: gazebo::event::ConnectionPtr applyDamping;
890 
892  protected: double effortLimit[MAX_JOINT_AXIS];
893 
895  protected: double velocityLimit[MAX_JOINT_AXIS];
896 
898  protected: double lowerLimit[MAX_JOINT_AXIS];
899 
901  protected: double upperLimit[MAX_JOINT_AXIS];
902 
905  protected: JointWrench wrench;
906 
910  protected: bool axisParentModelFrame[MAX_JOINT_AXIS];
911 
914  private: static sdf::ElementPtr sdfJoint;
915 
917  protected: bool provideFeedback;
918 
920  private: std::vector<std::string> sensors;
921 
923  private: event::EventT<void ()> jointUpdate;
924 
926  private: double staticPosition;
927 
929  private: double stopStiffness[MAX_JOINT_AXIS];
930 
932  private: double stopDissipation[MAX_JOINT_AXIS];
933  };
935  }
936 }
937 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
Attribute
Joint attribute types.
Definition: Joint.hh:57
Encapsulates a position and rotation in three space.
Definition: Pose.hh:42
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
virtual void Reset()
Reset the object.
Upper joint limit.
Definition: Joint.hh:87
void DisconnectJointUpdate(event::ConnectionPtr &_conn) GAZEBO_DEPRECATED(8.0)
Disconnect a boost::slot the the joint update signal.
Definition: Joint.hh:239
Maximum force.
Definition: Joint.hh:81
event::ConnectionPtr ConnectJointUpdate(T _subscriber)
Connect a boost::slot the the joint update signal.
Definition: Joint.hh:233
Suspension error reduction parameter.
Definition: Joint.hh:63
Base class for most physics classes.
Definition: Base.hh:77
Constraint force mixing.
Definition: Joint.hh:78
Suspension constraint force mixing.
Definition: Joint.hh:66
keeps track of state of a physics::Joint
Definition: JointState.hh:43
Error reduction parameter.
Definition: Joint.hh:75
Fudge factor.
Definition: Joint.hh:60
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
Base class for all joints.
Definition: Joint.hh:53
Velocity.
Definition: Joint.hh:84
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
Wrench information from a joint.
Definition: JointWrench.hh:40
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
An angle and related functions.
Definition: Angle.hh:53
Stop limit error reduction parameter.
Definition: Joint.hh:69
std::vector< LinkPtr > Link_V
Definition: PhysicsTypes.hh:225
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
Stop limit constraint force mixing.
Definition: Joint.hh:72