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 #include <map>
21 #include <vector>
22 #include <string>
23 #include <ignition/math/Matrix3.hh>
24 
25 #include "gazebo/msgs/msgs.hh"
26 
27 #include "gazebo/common/Event.hh"
29 
31 #include "gazebo/physics/Entity.hh"
33 #include "gazebo/physics/Joint.hh"
34 #include "gazebo/util/system.hh"
35 
36 namespace gazebo
37 {
38  namespace physics
39  {
40  class Model;
41  class Collision;
42  class Battery;
43  class LinkPrivate;
44 
47 
52  class GZ_PHYSICS_VISIBLE Link : public Entity
53  {
56  public: explicit Link(EntityPtr _parent);
57 
59  public: virtual ~Link();
60 
63  public: virtual void Load(sdf::ElementPtr _sdf) override;
64 
66  public: virtual void Init() override;
67 
69  public: void Fini() override;
70 
72  public: void Reset() override;
73  using Entity::Reset;
74 
76  public: void ResetPhysicsStates();
77 
80  public: virtual void UpdateParameters(sdf::ElementPtr _sdf) override;
81 
84  public: void Update(const common::UpdateInfo &_info);
85  using Base::Update;
86 
89  public: void SetScale(const ignition::math::Vector3d &_scale);
90 
93  public: virtual void SetEnabled(bool _enable) const = 0;
94 
97  public: virtual bool GetEnabled() const = 0;
98 
102  public: virtual bool SetSelected(bool _set) override;
103 
106  public: virtual void SetGravityMode(bool _mode) = 0;
107 
110  public: virtual bool GetGravityMode() const = 0;
111 
114  public: virtual void SetWindMode(const bool _mode);
115 
118  public: virtual bool WindMode() const;
119 
124  public: virtual void SetSelfCollide(bool _collide) = 0;
125 
134  public: void SetCollideMode(const std::string &_mode);
135 
143  public: bool GetSelfCollide() const;
144 
147  public: void SetLaserRetro(float _retro);
148 
151  public: virtual void SetLinearVel(
152  const ignition::math::Vector3d &_vel) = 0;
153 
156  public: virtual void SetAngularVel(
157  const ignition::math::Vector3d &_vel) = 0;
158 
161  public: virtual void SetForce(
162  const ignition::math::Vector3d &_force) = 0;
163 
166  public: virtual void SetTorque(
167  const ignition::math::Vector3d &_torque) = 0;
168 
171  public: virtual void AddForce(const ignition::math::Vector3d &_force) = 0;
172 
176  public: virtual void AddRelativeForce(
177  const ignition::math::Vector3d &_force) = 0;
178 
182  public: virtual void AddForceAtWorldPosition(
183  const ignition::math::Vector3d &_force,
184  const ignition::math::Vector3d &_pos) = 0;
185 
194  public: virtual void AddForceAtRelativePosition(
195  const ignition::math::Vector3d &_force,
196  const ignition::math::Vector3d &_relPos) = 0;
197 
204  public: virtual void AddLinkForce(
205  const ignition::math::Vector3d &_force,
206  const ignition::math::Vector3d &_offset =
207  ignition::math::Vector3d::Zero) = 0;
208 
211  public: virtual void AddTorque(
212  const ignition::math::Vector3d &_torque) = 0;
213 
217  public: virtual void AddRelativeTorque(
218  const ignition::math::Vector3d &_torque) = 0;
219 
224  public: ignition::math::Pose3d WorldCoGPose() const;
225 
229  public: virtual ignition::math::Vector3d WorldLinearVel() const override;
230 
238  public: virtual ignition::math::Vector3d WorldLinearVel(
239  const ignition::math::Vector3d &_offset) const = 0;
240 
248  public: virtual ignition::math::Vector3d WorldLinearVel(
249  const ignition::math::Vector3d &_offset,
250  const ignition::math::Quaterniond &_q) const = 0;
251 
256  public: virtual ignition::math::Vector3d WorldCoGLinearVel() const = 0;
257 
260  public: ignition::math::Vector3d RelativeLinearVel() const override;
261 
264  public: ignition::math::Vector3d RelativeAngularVel() const override;
265 
268  public: ignition::math::Vector3d RelativeLinearAccel() const override;
269 
272  public: ignition::math::Vector3d WorldLinearAccel() const override;
273 
276  public: ignition::math::Vector3d RelativeAngularAccel() const override;
277 
283  public: ignition::math::Vector3d WorldAngularMomentum() const;
284 
292  public: ignition::math::Vector3d WorldAngularAccel() const override;
293 
296  public: ignition::math::Vector3d RelativeForce() const;
297 
300  public: virtual ignition::math::Vector3d WorldForce() const = 0;
301 
304  public: ignition::math::Vector3d RelativeTorque() const;
305 
309  public: virtual ignition::math::Vector3d WorldTorque() const = 0;
310 
313  public: ModelPtr GetModel() const;
314 
317  public: InertialPtr GetInertial() const {return this->inertial;}
318 
321  public: void SetInertial(const InertialPtr &_inertial);
322 
328  public: ignition::math::Pose3d WorldInertialPose() const;
329 
333  public: ignition::math::Matrix3d WorldInertiaMatrix() const;
334 
340  public: CollisionPtr GetCollisionById(unsigned int _id) const;
342 
346  public: CollisionPtr GetCollision(const std::string &_name);
347 
351  public: CollisionPtr GetCollision(unsigned int _index) const;
352 
355  public: Collision_V GetCollisions() const;
356 
360  public: virtual ignition::math::AxisAlignedBox BoundingBox() const
361  override;
362 
365  public: virtual void SetLinearDamping(double _damping) = 0;
366 
369  public: virtual void SetAngularDamping(double _damping) = 0;
370 
373  public: double GetLinearDamping() const;
374 
377  public: double GetAngularDamping() const;
378 
382  public: virtual void SetKinematic(const bool &_kinematic);
383 
387  public: virtual bool GetKinematic() const {return false;}
388 
395  public: unsigned int GetSensorCount() const;
396 
408  public: std::string GetSensorName(unsigned int _index) const;
409 
413  public: event::ConnectionPtr ConnectEnabled(
414  std::function<void (bool)> _subscriber);
415 
418  public: void FillMsg(msgs::Link &_msg);
419 
422  public: void ProcessMsg(const msgs::Link &_msg);
423 
426  public: void AddChildJoint(JointPtr _joint);
427 
430  public: void AddParentJoint(JointPtr _joint);
431 
434  public: void RemoveParentJoint(const std::string &_jointName);
435 
438  public: void RemoveChildJoint(const std::string &_jointName);
439 
440  // Documentation inherited.
441  public: virtual void RemoveChild(EntityPtr _child);
442  using Base::RemoveChild;
443 
447  public: void AttachStaticModel(ModelPtr &_model,
448  const ignition::math::Pose3d &_offset);
449 
452  public: void DetachStaticModel(const std::string &_modelName);
453 
455  public: void DetachAllStaticModels();
456 
459  public: virtual void OnPoseChange() override;
460 
463  public: void SetState(const LinkState &_state);
464 
466  public: virtual void UpdateMass() {}
467 
469  public: virtual void UpdateSurface() {}
470 
473  public: virtual void SetAutoDisable(bool _disable) = 0;
474 
477  public: Link_V GetChildJointsLinks() const;
478 
481  public: Link_V GetParentJointsLinks() const;
482 
485  public: void SetPublishData(bool _enable);
486 
488  public: Joint_V GetParentJoints() const;
489 
491  public: Joint_V GetChildJoints() const;
492 
495  public: void RemoveCollision(const std::string &_name);
496 
500  public: double GetWorldEnergyPotential() const;
501 
505  public: double GetWorldEnergyKinetic() const;
506 
511  public: double GetWorldEnergy() const;
512 
516  public: msgs::Visual GetVisualMessage(const std::string &_name) const;
517 
521  public: virtual void SetLinkStatic(bool _static) = 0;
522 
523  // Documentation inherited
524  public: virtual void SetStatic(const bool &_static);
525  using Entity::SetStatic;
526 
537  public: void MoveFrame(
538  const ignition::math::Pose3d &_worldReferenceFrameSrc,
539  const ignition::math::Pose3d &_worldReferenceFrameDst,
540  const bool _preserveWorldVelocity = false);
541 
556  public: bool FindAllConnectedLinksHelper(
557  const LinkPtr &_originalParentLink,
558  Link_V &_connectedLinks, bool _fistLink = false);
559 
562  public: void SetWindEnabled(const bool _enable);
563 
567  public: const ignition::math::Vector3d WorldWindLinearVel() const;
568 
571  public: const ignition::math::Vector3d RelativeWindLinearVel() const;
572 
575  public: void UpdateWind(const common::UpdateInfo &_info);
576 
580  public: common::BatteryPtr Battery(const std::string &_name) const;
581 
584  public: common::BatteryPtr Battery(const size_t _index) const;
585 
589  public: size_t BatteryCount() const;
590 
595  public: bool VisualId(const std::string &_visName, uint32_t &_visualId)
596  const;
597 
602  public: bool VisualPose(const uint32_t _id,
603  ignition::math::Pose3d &_pose) const;
604 
609  public: bool SetVisualPose(const uint32_t _id,
610  const ignition::math::Pose3d &_pose);
611 
614  public: const sdf::Link *GetSDFDom() const;
615 
616  // Documentation inherited.
617  public: std::optional<sdf::SemanticPose> SDFSemanticPose() const override;
618 
621  typedef std::map<uint32_t, msgs::Visual> Visuals_M;
622 
625  public: const Visuals_M &Visuals() const;
626 
628  private: void PublishData();
629 
632  private: void LoadCollision(sdf::ElementPtr _sdf);
633 
636  private: void LoadLight(sdf::ElementPtr _sdf);
637 
640  private: void SetInertialFromCollisions();
641 
644  private: void OnCollision(ConstContactsPtr &_msg);
645 
647  private: void ParseVisuals();
648 
653  private: bool ContainsLink(const Link_V &_vector, const LinkPtr &_value);
654 
657  private: void UpdateVisualGeomSDF(const ignition::math::Vector3d &_scale);
658 
660  private: void UpdateVisualMsg();
661 
665  private: void OnWrenchMsg(ConstWrenchPtr &_msg);
666 
669  private: void ProcessWrenchMsg(const msgs::Wrench &_msg);
670 
673  private: void LoadBattery(const sdf::ElementPtr _sdf);
674 
676  protected: virtual void RegisterIntrospectionItems() override;
677 
679  protected: InertialPtr inertial;
680 
682  protected: Visuals_M visuals;
683 
685  protected: std::vector<ignition::math::Pose3d> attachedModelsOffset;
686 
688  protected: bool initialized = false;
689 
691  private: std::unique_ptr<LinkPrivate> dataPtr;
692  };
694  }
695 }
696 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:110
Forward declarations for the common classes.
Definition: Animation.hh:26
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:118
virtual void Update()
Update the object.
Definition: Base.hh:166
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:214
std::vector< CollisionPtr > Collision_V
Definition: PhysicsTypes.hh:230
std::shared_ptr< Battery > BatteryPtr
Definition: CommonTypes.hh:125
boost::shared_ptr< Inertial > InertialPtr
Definition: PhysicsTypes.hh:158
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:86
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:94
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:226
Store state information of a physics::Link object.
Definition: LinkState.hh:47
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:114