Link.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_LINK_HH_
18 #define GAZEBO_PHYSICS_LINK_HH_
19 
20 #ifdef _WIN32
21  // Ensure that Winsock2.h is included before Windows.h, which can get
22  // pulled in by anybody (e.g., Boost).
23  #include <Winsock2.h>
24 #endif
25 
26 #include <map>
27 #include <vector>
28 #include <string>
29 #include <ignition/math/Matrix3.hh>
30 
31 #include "gazebo/msgs/msgs.hh"
32 
33 #include "gazebo/common/Event.hh"
35 
37 #include "gazebo/physics/Entity.hh"
39 #include "gazebo/physics/Joint.hh"
40 #include "gazebo/util/system.hh"
41 
42 namespace gazebo
43 {
44  namespace physics
45  {
46  class Model;
47  class Collision;
48  class Battery;
49  class LinkPrivate;
50 
53 
58  class GZ_PHYSICS_VISIBLE Link : public Entity
59  {
62  public: explicit Link(EntityPtr _parent);
63 
65  public: virtual ~Link();
66 
69  public: virtual void Load(sdf::ElementPtr _sdf);
70 
72  public: virtual void Init();
73 
75  public: void Fini();
76 
78  public: void Reset();
79  using Entity::Reset;
80 
82  public: void ResetPhysicsStates();
83 
86  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
87 
90  public: void Update(const common::UpdateInfo &_info);
91  using Base::Update;
92 
95  public: void SetScale(const ignition::math::Vector3d &_scale);
96 
99  public: virtual void SetEnabled(bool _enable) const = 0;
100 
103  public: virtual bool GetEnabled() const = 0;
104 
108  public: virtual bool SetSelected(bool _set);
109 
112  public: virtual void SetGravityMode(bool _mode) = 0;
113 
116  public: virtual bool GetGravityMode() const = 0;
117 
120  public: virtual void SetWindMode(const bool _mode);
121 
124  public: virtual bool WindMode() const;
125 
130  public: virtual void SetSelfCollide(bool _collide) = 0;
131 
140  public: void SetCollideMode(const std::string &_mode);
141 
149  public: bool GetSelfCollide() const;
150 
153  public: void SetLaserRetro(float _retro);
154 
157  public: virtual void SetLinearVel(
158  const ignition::math::Vector3d &_vel) = 0;
159 
162  public: virtual void SetAngularVel(
163  const ignition::math::Vector3d &_vel) = 0;
164 
167  public: virtual void SetForce(
168  const ignition::math::Vector3d &_force) = 0;
169 
172  public: virtual void SetTorque(
173  const ignition::math::Vector3d &_torque) = 0;
174 
177  public: virtual void AddForce(const ignition::math::Vector3d &_force) = 0;
178 
182  public: virtual void AddRelativeForce(
183  const ignition::math::Vector3d &_force) = 0;
184 
188  public: virtual void AddForceAtWorldPosition(
189  const ignition::math::Vector3d &_force,
190  const ignition::math::Vector3d &_pos) = 0;
191 
200  public: virtual void AddForceAtRelativePosition(
201  const ignition::math::Vector3d &_force,
202  const ignition::math::Vector3d &_relPos) = 0;
203 
210  public: virtual void AddLinkForce(
211  const ignition::math::Vector3d &_force,
212  const ignition::math::Vector3d &_offset =
213  ignition::math::Vector3d::Zero) = 0;
214 
217  public: virtual void AddTorque(
218  const ignition::math::Vector3d &_torque) = 0;
219 
223  public: virtual void AddRelativeTorque(
224  const ignition::math::Vector3d &_torque) = 0;
225 
230  public: ignition::math::Pose3d WorldCoGPose() const;
231 
235  public: virtual ignition::math::Vector3d WorldLinearVel() const;
236 
244  public: virtual ignition::math::Vector3d WorldLinearVel(
245  const ignition::math::Vector3d &_offset) const = 0;
246 
254  public: virtual ignition::math::Vector3d WorldLinearVel(
255  const ignition::math::Vector3d &_offset,
256  const ignition::math::Quaterniond &_q) const = 0;
257 
262  public: virtual ignition::math::Vector3d WorldCoGLinearVel() const = 0;
263 
266  public: ignition::math::Vector3d RelativeLinearVel() const;
267 
270  public: ignition::math::Vector3d RelativeAngularVel() const;
271 
274  public: ignition::math::Vector3d RelativeLinearAccel() const;
275 
278  public: ignition::math::Vector3d WorldLinearAccel() const;
279 
282  public: ignition::math::Vector3d RelativeAngularAccel() const;
283 
289  public: ignition::math::Vector3d WorldAngularMomentum() const;
290 
298  public: ignition::math::Vector3d WorldAngularAccel() const;
299 
302  public: ignition::math::Vector3d RelativeForce() const;
303 
306  public: virtual ignition::math::Vector3d WorldForce() const = 0;
307 
310  public: ignition::math::Vector3d RelativeTorque() const;
311 
315  public: virtual ignition::math::Vector3d WorldTorque() const = 0;
316 
319  public: ModelPtr GetModel() const;
320 
323  public: InertialPtr GetInertial() const {return this->inertial;}
324 
327  public: void SetInertial(const InertialPtr &_inertial);
328 
334  public: ignition::math::Pose3d WorldInertialPose() const;
335 
339  public: ignition::math::Matrix3d WorldInertiaMatrix() const;
340 
346  public: CollisionPtr GetCollisionById(unsigned int _id) const;
348 
352  public: CollisionPtr GetCollision(const std::string &_name);
353 
357  public: CollisionPtr GetCollision(unsigned int _index) const;
358 
361  public: Collision_V GetCollisions() const;
362 
366  public: virtual ignition::math::Box BoundingBox() const;
367 
370  public: virtual void SetLinearDamping(double _damping) = 0;
371 
374  public: virtual void SetAngularDamping(double _damping) = 0;
375 
378  public: double GetLinearDamping() const;
379 
382  public: double GetAngularDamping() const;
383 
387  public: virtual void SetKinematic(const bool &_kinematic);
388 
392  public: virtual bool GetKinematic() const {return false;}
393 
400  public: unsigned int GetSensorCount() const;
401 
413  public: std::string GetSensorName(unsigned int _index) const;
414 
418  public: event::ConnectionPtr ConnectEnabled(
419  std::function<void (bool)> _subscriber);
420 
423  public: void FillMsg(msgs::Link &_msg);
424 
427  public: void ProcessMsg(const msgs::Link &_msg);
428 
431  public: void AddChildJoint(JointPtr _joint);
432 
435  public: void AddParentJoint(JointPtr _joint);
436 
439  public: void RemoveParentJoint(const std::string &_jointName);
440 
443  public: void RemoveChildJoint(const std::string &_jointName);
444 
445  // Documentation inherited.
446  public: virtual void RemoveChild(EntityPtr _child);
447  using Base::RemoveChild;
448 
452  public: void AttachStaticModel(ModelPtr &_model,
453  const ignition::math::Pose3d &_offset);
454 
457  public: void DetachStaticModel(const std::string &_modelName);
458 
460  public: void DetachAllStaticModels();
461 
464  public: virtual void OnPoseChange();
465 
468  public: void SetState(const LinkState &_state);
469 
471  public: virtual void UpdateMass() {}
472 
474  public: virtual void UpdateSurface() {}
475 
478  public: virtual void SetAutoDisable(bool _disable) = 0;
479 
482  public: Link_V GetChildJointsLinks() const;
483 
486  public: Link_V GetParentJointsLinks() const;
487 
490  public: void SetPublishData(bool _enable);
491 
493  public: Joint_V GetParentJoints() const;
494 
496  public: Joint_V GetChildJoints() const;
497 
500  public: void RemoveCollision(const std::string &_name);
501 
505  public: double GetWorldEnergyPotential() const;
506 
510  public: double GetWorldEnergyKinetic() const;
511 
516  public: double GetWorldEnergy() const;
517 
521  public: msgs::Visual GetVisualMessage(const std::string &_name) const;
522 
526  public: virtual void SetLinkStatic(bool _static) = 0;
527 
528  // Documentation inherited
529  public: virtual void SetStatic(const bool &_static);
530  using Entity::SetStatic;
531 
542  public: void MoveFrame(
543  const ignition::math::Pose3d &_worldReferenceFrameSrc,
544  const ignition::math::Pose3d &_worldReferenceFrameDst,
545  const bool _preserveWorldVelocity = false);
546 
561  public: bool FindAllConnectedLinksHelper(
562  const LinkPtr &_originalParentLink,
563  Link_V &_connectedLinks, bool _fistLink = false);
564 
567  public: void SetWindEnabled(const bool _enable);
568 
572  public: const ignition::math::Vector3d WorldWindLinearVel() const;
573 
576  public: const ignition::math::Vector3d RelativeWindLinearVel() const;
577 
580  public: void UpdateWind(const common::UpdateInfo &_info);
581 
585  public: common::BatteryPtr Battery(const std::string &_name) const;
586 
589  public: common::BatteryPtr Battery(const size_t _index) const;
590 
594  public: size_t BatteryCount() const;
595 
600  public: bool VisualId(const std::string &_visName, uint32_t &_visualId)
601  const;
602 
607  public: bool VisualPose(const uint32_t _id,
608  ignition::math::Pose3d &_pose) const;
609 
614  public: bool SetVisualPose(const uint32_t _id,
615  const ignition::math::Pose3d &_pose);
616 
619  typedef std::map<uint32_t, msgs::Visual> Visuals_M;
620 
623  public: const Visuals_M &Visuals() const;
624 
626  private: void PublishData();
627 
630  private: void LoadCollision(sdf::ElementPtr _sdf);
631 
634  private: void LoadLight(sdf::ElementPtr _sdf);
635 
638  private: void SetInertialFromCollisions();
639 
642  private: void OnCollision(ConstContactsPtr &_msg);
643 
645  private: void ParseVisuals();
646 
651  private: bool ContainsLink(const Link_V &_vector, const LinkPtr &_value);
652 
655  private: void UpdateVisualGeomSDF(const ignition::math::Vector3d &_scale);
656 
658  private: void UpdateVisualMsg();
659 
663  private: void OnWrenchMsg(ConstWrenchPtr &_msg);
664 
667  private: void ProcessWrenchMsg(const msgs::Wrench &_msg);
668 
671  private: void LoadBattery(const sdf::ElementPtr _sdf);
672 
674  protected: virtual void RegisterIntrospectionItems();
675 
677  protected: InertialPtr inertial;
678 
680  protected: Visuals_M visuals;
681 
683  protected: std::vector<ignition::math::Pose3d> attachedModelsOffset;
684 
686  protected: bool initialized = false;
687 
689  private: std::unique_ptr<LinkPrivate> dataPtr;
690  };
692  }
693 }
694 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
Forward declarations for the common classes.
Definition: Animation.hh:26
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
virtual void Update()
Update the object.
Definition: Base.hh:171
virtual void RemoveChild(unsigned int _id)
Remove a child from this entity.
Information for use in an update event.
Definition: UpdateInfo.hh:30
void SetStatic(const bool &_static)
Set whether this entity is static: immovable.
std::vector< JointPtr > Joint_V
Definition: PhysicsTypes.hh:213
std::vector< CollisionPtr > Collision_V
Definition: PhysicsTypes.hh:229
std::shared_ptr< Battery > BatteryPtr
Definition: CommonTypes.hh:125
boost::shared_ptr< Inertial > InertialPtr
Definition: PhysicsTypes.hh:157
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:85
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
virtual void Reset()
Reset the entity.
std::vector< LinkPtr > Link_V
Definition: PhysicsTypes.hh:225
Store state information of a physics::Link object.
Definition: LinkState.hh:47
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113