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 
169  public: void SetLinearAccel(const ignition::math::Vector3d &_accel)
170  GAZEBO_DEPRECATED(9.0);
171 
176  public: void SetAngularAccel(const ignition::math::Vector3d &_accel)
177  GAZEBO_DEPRECATED(9.0);
178 
181  public: virtual void SetForce(
182  const ignition::math::Vector3d &_force) = 0;
183 
186  public: virtual void SetTorque(
187  const ignition::math::Vector3d &_torque) = 0;
188 
191  public: virtual void AddForce(const ignition::math::Vector3d &_force) = 0;
192 
196  public: virtual void AddRelativeForce(
197  const ignition::math::Vector3d &_force) = 0;
198 
202  public: virtual void AddForceAtWorldPosition(
203  const ignition::math::Vector3d &_force,
204  const ignition::math::Vector3d &_pos) = 0;
205 
214  public: virtual void AddForceAtRelativePosition(
215  const ignition::math::Vector3d &_force,
216  const ignition::math::Vector3d &_relPos) = 0;
217 
224  public: virtual void AddLinkForce(
225  const ignition::math::Vector3d &_force,
226  const ignition::math::Vector3d &_offset =
227  ignition::math::Vector3d::Zero) = 0;
228 
231  public: virtual void AddTorque(
232  const ignition::math::Vector3d &_torque) = 0;
233 
237  public: virtual void AddRelativeTorque(
238  const ignition::math::Vector3d &_torque) = 0;
239 
244  public: ignition::math::Pose3d WorldCoGPose() const;
245 
249  public: virtual ignition::math::Vector3d WorldLinearVel() const;
250 
258  public: virtual ignition::math::Vector3d WorldLinearVel(
259  const ignition::math::Vector3d &_offset) const = 0;
260 
268  public: virtual ignition::math::Vector3d WorldLinearVel(
269  const ignition::math::Vector3d &_offset,
270  const ignition::math::Quaterniond &_q) const = 0;
271 
276  public: virtual ignition::math::Vector3d WorldCoGLinearVel() const = 0;
277 
280  public: ignition::math::Vector3d RelativeLinearVel() const;
281 
284  public: ignition::math::Vector3d RelativeAngularVel() const;
285 
288  public: ignition::math::Vector3d RelativeLinearAccel() const;
289 
292  public: ignition::math::Vector3d WorldLinearAccel() const;
293 
296  public: ignition::math::Vector3d RelativeAngularAccel() const;
297 
303  public: ignition::math::Vector3d WorldAngularMomentum() const;
304 
312  public: ignition::math::Vector3d WorldAngularAccel() const;
313 
316  public: ignition::math::Vector3d RelativeForce() const;
317 
320  public: virtual ignition::math::Vector3d WorldForce() const = 0;
321 
324  public: ignition::math::Vector3d RelativeTorque() const;
325 
329  public: virtual ignition::math::Vector3d WorldTorque() const = 0;
330 
333  public: ModelPtr GetModel() const;
334 
337  public: InertialPtr GetInertial() const {return this->inertial;}
338 
341  public: void SetInertial(const InertialPtr &_inertial);
342 
348  public: ignition::math::Pose3d WorldInertialPose() const;
349 
353  public: ignition::math::Matrix3d WorldInertiaMatrix() const;
354 
360  public: CollisionPtr GetCollisionById(unsigned int _id) const;
362 
366  public: CollisionPtr GetCollision(const std::string &_name);
367 
371  public: CollisionPtr GetCollision(unsigned int _index) const;
372 
375  public: Collision_V GetCollisions() const;
376 
380  public: virtual ignition::math::Box BoundingBox() const;
381 
384  public: virtual void SetLinearDamping(double _damping) = 0;
385 
388  public: virtual void SetAngularDamping(double _damping) = 0;
389 
392  public: double GetLinearDamping() const;
393 
396  public: double GetAngularDamping() const;
397 
401  public: virtual void SetKinematic(const bool &_kinematic);
402 
406  public: virtual bool GetKinematic() const {return false;}
407 
414  public: unsigned int GetSensorCount() const;
415 
427  public: std::string GetSensorName(unsigned int _index) const;
428 
432  public: event::ConnectionPtr ConnectEnabled(
433  std::function<void (bool)> _subscriber);
434 
437  public: void FillMsg(msgs::Link &_msg);
438 
441  public: void ProcessMsg(const msgs::Link &_msg);
442 
445  public: void AddChildJoint(JointPtr _joint);
446 
449  public: void AddParentJoint(JointPtr _joint);
450 
453  public: void RemoveParentJoint(const std::string &_jointName);
454 
457  public: void RemoveChildJoint(const std::string &_jointName);
458 
459  // Documentation inherited.
460  public: virtual void RemoveChild(EntityPtr _child);
461  using Base::RemoveChild;
462 
466  public: void AttachStaticModel(ModelPtr &_model,
467  const ignition::math::Pose3d &_offset);
468 
471  public: void DetachStaticModel(const std::string &_modelName);
472 
474  public: void DetachAllStaticModels();
475 
478  public: virtual void OnPoseChange();
479 
482  public: void SetState(const LinkState &_state);
483 
485  public: virtual void UpdateMass() {}
486 
488  public: virtual void UpdateSurface() {}
489 
492  public: virtual void SetAutoDisable(bool _disable) = 0;
493 
496  public: Link_V GetChildJointsLinks() const;
497 
500  public: Link_V GetParentJointsLinks() const;
501 
504  public: void SetPublishData(bool _enable);
505 
507  public: Joint_V GetParentJoints() const;
508 
510  public: Joint_V GetChildJoints() const;
511 
514  public: void RemoveCollision(const std::string &_name);
515 
519  public: double GetWorldEnergyPotential() const;
520 
524  public: double GetWorldEnergyKinetic() const;
525 
530  public: double GetWorldEnergy() const;
531 
535  public: msgs::Visual GetVisualMessage(const std::string &_name) const;
536 
540  public: virtual void SetLinkStatic(bool _static) = 0;
541 
542  // Documentation inherited
543  public: virtual void SetStatic(const bool &_static);
544  using Entity::SetStatic;
545 
556  public: void MoveFrame(
557  const ignition::math::Pose3d &_worldReferenceFrameSrc,
558  const ignition::math::Pose3d &_worldReferenceFrameDst,
559  const bool _preserveWorldVelocity = false);
560 
575  public: bool FindAllConnectedLinksHelper(
576  const LinkPtr &_originalParentLink,
577  Link_V &_connectedLinks, bool _fistLink = false);
578 
581  public: void SetWindEnabled(const bool _enable);
582 
586  public: const ignition::math::Vector3d WorldWindLinearVel() const;
587 
590  public: const ignition::math::Vector3d RelativeWindLinearVel() const;
591 
594  public: void UpdateWind(const common::UpdateInfo &_info);
595 
599  public: common::BatteryPtr Battery(const std::string &_name) const;
600 
603  public: common::BatteryPtr Battery(const size_t _index) const;
604 
608  public: size_t BatteryCount() const;
609 
614  public: bool VisualId(const std::string &_visName, uint32_t &_visualId)
615  const;
616 
621  public: bool VisualPose(const uint32_t _id,
622  ignition::math::Pose3d &_pose) const;
623 
628  public: bool SetVisualPose(const uint32_t _id,
629  const ignition::math::Pose3d &_pose);
630 
632  private: void PublishData();
633 
636  private: void LoadCollision(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();
677 
679  protected: InertialPtr inertial;
680 
683  typedef std::map<uint32_t, msgs::Visual> Visuals_M;
684 
686  protected: Visuals_M visuals;
687 
690  protected: ignition::math::Vector3d linearAccel;
691 
694  protected: ignition::math::Vector3d angularAccel;
695 
697  protected: std::vector<ignition::math::Pose3d> attachedModelsOffset;
698 
700  protected: bool initialized = false;
701 
703  private: std::unique_ptr<LinkPrivate> dataPtr;
704  };
706  }
707 }
708 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
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
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
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