Go to the documentation of this file.
17 #ifndef GAZEBO_PHYSICS_LINK_HH_
18 #define GAZEBO_PHYSICS_LINK_HH_
23 #include <ignition/math/Matrix3.hh>
59 public:
virtual ~
Link();
63 public:
virtual void Load(sdf::ElementPtr _sdf);
66 public:
virtual void Init();
76 public:
void ResetPhysicsStates();
80 public:
virtual void UpdateParameters(sdf::ElementPtr _sdf);
89 public:
void SetScale(
const ignition::math::Vector3d &_scale);
93 public:
virtual void SetEnabled(
bool _enable)
const = 0;
97 public:
virtual bool GetEnabled()
const = 0;
102 public:
virtual bool SetSelected(
bool _set);
106 public:
virtual void SetGravityMode(
bool _mode) = 0;
110 public:
virtual bool GetGravityMode()
const = 0;
114 public:
virtual void SetWindMode(
const bool _mode);
118 public:
virtual bool WindMode()
const;
124 public:
virtual void SetSelfCollide(
bool _collide) = 0;
134 public:
void SetCollideMode(
const std::string &_mode);
143 public:
bool GetSelfCollide()
const;
147 public:
void SetLaserRetro(
float _retro);
151 public:
virtual void SetLinearVel(
152 const ignition::math::Vector3d &_vel) = 0;
156 public:
virtual void SetAngularVel(
157 const ignition::math::Vector3d &_vel) = 0;
163 public:
void SetLinearAccel(
const ignition::math::Vector3d &_accel)
170 public:
void SetAngularAccel(
const ignition::math::Vector3d &_accel)
175 public:
virtual void SetForce(
176 const ignition::math::Vector3d &_force) = 0;
180 public:
virtual void SetTorque(
181 const ignition::math::Vector3d &_torque) = 0;
185 public:
virtual void AddForce(
const ignition::math::Vector3d &_force) = 0;
190 public:
virtual void AddRelativeForce(
191 const ignition::math::Vector3d &_force) = 0;
196 public:
virtual void AddForceAtWorldPosition(
197 const ignition::math::Vector3d &_force,
198 const ignition::math::Vector3d &_pos) = 0;
208 public:
virtual void AddForceAtRelativePosition(
209 const ignition::math::Vector3d &_force,
210 const ignition::math::Vector3d &_relPos) = 0;
218 public:
virtual void AddLinkForce(
219 const ignition::math::Vector3d &_force,
220 const ignition::math::Vector3d &_offset =
221 ignition::math::Vector3d::Zero) = 0;
225 public:
virtual void AddTorque(
226 const ignition::math::Vector3d &_torque) = 0;
231 public:
virtual void AddRelativeTorque(
232 const ignition::math::Vector3d &_torque) = 0;
238 public: ignition::math::Pose3d WorldCoGPose()
const;
243 public:
virtual ignition::math::Vector3d WorldLinearVel()
const;
252 public:
virtual ignition::math::Vector3d WorldLinearVel(
253 const ignition::math::Vector3d &_offset)
const = 0;
262 public:
virtual ignition::math::Vector3d WorldLinearVel(
263 const ignition::math::Vector3d &_offset,
264 const ignition::math::Quaterniond &_q)
const = 0;
270 public:
virtual ignition::math::Vector3d WorldCoGLinearVel()
const = 0;
274 public: ignition::math::Vector3d RelativeLinearVel()
const;
278 public: ignition::math::Vector3d RelativeAngularVel()
const;
282 public: ignition::math::Vector3d RelativeLinearAccel()
const;
286 public: ignition::math::Vector3d WorldLinearAccel()
const;
290 public: ignition::math::Vector3d RelativeAngularAccel()
const;
297 public: ignition::math::Vector3d WorldAngularMomentum()
const;
306 public: ignition::math::Vector3d WorldAngularAccel()
const;
310 public: ignition::math::Vector3d RelativeForce()
const;
314 public:
virtual ignition::math::Vector3d WorldForce()
const = 0;
318 public: ignition::math::Vector3d RelativeTorque()
const;
323 public:
virtual ignition::math::Vector3d WorldTorque()
const = 0;
335 public:
void SetInertial(
const InertialPtr &_inertial);
342 public: ignition::math::Pose3d WorldInertialPose()
const;
347 public: ignition::math::Matrix3d WorldInertiaMatrix()
const;
354 public:
CollisionPtr GetCollisionById(
unsigned int _id)
const;
360 public:
CollisionPtr GetCollision(
const std::string &_name);
365 public:
CollisionPtr GetCollision(
unsigned int _index)
const;
374 public:
virtual ignition::math::Box BoundingBox()
const;
378 public:
virtual void SetLinearDamping(
double _damping) = 0;
382 public:
virtual void SetAngularDamping(
double _damping) = 0;
386 public:
double GetLinearDamping()
const;
390 public:
double GetAngularDamping()
const;
395 public:
virtual void SetKinematic(
const bool &_kinematic);
408 public:
unsigned int GetSensorCount()
const;
421 public: std::string GetSensorName(
unsigned int _index)
const;
427 std::function<
void (
bool)> _subscriber);
431 public:
void FillMsg(msgs::Link &_msg);
435 public:
void ProcessMsg(
const msgs::Link &_msg);
439 public:
void AddChildJoint(
JointPtr _joint);
443 public:
void AddParentJoint(
JointPtr _joint);
447 public:
void RemoveParentJoint(
const std::string &_jointName);
451 public:
void RemoveChildJoint(
const std::string &_jointName);
454 public:
virtual void RemoveChild(
EntityPtr _child);
460 public:
void AttachStaticModel(
ModelPtr &_model,
461 const ignition::math::Pose3d &_offset);
465 public:
void DetachStaticModel(
const std::string &_modelName);
468 public:
void DetachAllStaticModels();
472 public:
virtual void OnPoseChange();
476 public:
void SetState(
const LinkState &_state);
486 public:
virtual void SetAutoDisable(
bool _disable) = 0;
490 public:
Link_V GetChildJointsLinks()
const;
494 public:
Link_V GetParentJointsLinks()
const;
498 public:
void SetPublishData(
bool _enable);
501 public:
Joint_V GetParentJoints()
const;
504 public:
Joint_V GetChildJoints()
const;
508 public:
void RemoveCollision(
const std::string &_name);
513 public:
double GetWorldEnergyPotential()
const;
518 public:
double GetWorldEnergyKinetic()
const;
524 public:
double GetWorldEnergy()
const;
529 public: msgs::Visual GetVisualMessage(
const std::string &_name)
const;
534 public:
virtual void SetLinkStatic(
bool _static) = 0;
537 public:
virtual void SetStatic(
const bool &_static);
550 public:
void MoveFrame(
551 const ignition::math::Pose3d &_worldReferenceFrameSrc,
552 const ignition::math::Pose3d &_worldReferenceFrameDst,
553 const bool _preserveWorldVelocity =
false);
569 public:
bool FindAllConnectedLinksHelper(
570 const LinkPtr &_originalParentLink,
571 Link_V &_connectedLinks,
bool _fistLink =
false);
575 public:
void SetWindEnabled(
const bool _enable);
580 public:
const ignition::math::Vector3d WorldWindLinearVel()
const;
584 public:
const ignition::math::Vector3d RelativeWindLinearVel()
const;
602 public:
size_t BatteryCount()
const;
608 public:
bool VisualId(
const std::string &_visName, uint32_t &_visualId)
615 public:
bool VisualPose(
const uint32_t _id,
616 ignition::math::Pose3d &_pose)
const;
622 public:
bool SetVisualPose(
const uint32_t _id,
623 const ignition::math::Pose3d &_pose);
631 public:
const Visuals_M &Visuals()
const;
634 private:
void PublishData();
638 private:
void LoadCollision(sdf::ElementPtr _sdf);
642 private:
void LoadLight(sdf::ElementPtr _sdf);
646 private:
void SetInertialFromCollisions();
650 private:
void OnCollision(ConstContactsPtr &_msg);
653 private:
void ParseVisuals();
659 private:
bool ContainsLink(
const Link_V &_vector,
const LinkPtr &_value);
663 private:
void UpdateVisualGeomSDF(
const ignition::math::Vector3d &_scale);
666 private:
void UpdateVisualMsg();
671 private:
void OnWrenchMsg(ConstWrenchPtr &_msg);
675 private:
void ProcessWrenchMsg(
const msgs::Wrench &_msg);
679 private:
void LoadBattery(
const sdf::ElementPtr _sdf);
682 protected:
virtual void RegisterIntrospectionItems();
702 protected:
bool initialized =
false;
705 private: std::unique_ptr<LinkPrivate> dataPtr;
std::string GetSensorName(unsigned int _index) const
Get sensor name.
virtual void SetStatic(const bool &_static)
void SetWindEnabled(const bool _enable)
Enable/disable wind for this link.
InertialPtr GetInertial() const
Get the inertia of the link.
Definition: Link.hh:331
bool VisualId(const std::string &_visName, uint32_t &_visualId) const
Get the unique ID of a visual.
std::vector< JointPtr > Joint_V
Definition: PhysicsTypes.hh:213
virtual void Update()
Update the object.
Definition: Base.hh:165
const ignition::math::Vector3d RelativeWindLinearVel() const
Returns this link's wind velocity.
virtual void Init()
Initialize the body.
Visuals_M visuals
Link visual elements.
Definition: Link.hh:688
bool VisualPose(const uint32_t _id, ignition::math::Pose3d &_pose) const
Get the pose of a visual.
Collision_V GetCollisions() const
Get all the child collisions.
virtual ignition::math::Vector3d WorldLinearVel() const
Get the linear velocity of the origin of the link frame, expressed in the world frame.
Forward declarations for the common classes.
Definition: Animation.hh:26
virtual void AddLinkForce(const ignition::math::Vector3d &_force, const ignition::math::Vector3d &_offset=ignition::math::Vector3d::Zero)=0
Add a force expressed in the link frame.
unsigned int GetSensorCount() const
Get sensor count.
Joint_V GetParentJoints() const
Get the parent joints.
virtual void SetLinearVel(const ignition::math::Vector3d &_vel)=0
Set the linear velocity of the body.
virtual ~Link()
Destructor.
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
virtual void SetLinkStatic(bool _static)=0
Freeze link to ground (inertial frame).
void MoveFrame(const ignition::math::Pose3d &_worldReferenceFrameSrc, const ignition::math::Pose3d &_worldReferenceFrameDst, const bool _preserveWorldVelocity=false)
Move Link given source and target frames specified in world coordinates.
ignition::math::Vector3d WorldLinearAccel() const
Get the linear acceleration of the body in the world frame.
double GetWorldEnergyPotential() const
Returns this link's potential energy, based on position in world frame and gravity.
void RemoveCollision(const std::string &_name)
Remove a collision from the link.
double GetAngularDamping() const
Get the angular damping factor.
virtual void SetWindMode(const bool _mode)
Set whether wind affects this body.
virtual void AddForceAtWorldPosition(const ignition::math::Vector3d &_force, const ignition::math::Vector3d &_pos)=0
Add a force to the body using a global position.
virtual void SetGravityMode(bool _mode)=0
Set whether gravity affects this body.
virtual void RegisterIntrospectionItems()
Register items in the introspection service.
virtual void SetAutoDisable(bool _disable)=0
Allow the link to auto disable.
void FillMsg(msgs::Link &_msg)
Fill a link message.
ignition::math::Vector3d RelativeForce() const
Get the force applied to the body.
ignition::math::Vector3d WorldAngularAccel() const
Get the angular acceleration of the body in the world frame, which is computed as (I^-1 * (T - w x L)...
void SetLinearAccel(const ignition::math::Vector3d &_accel) GAZEBO_DEPRECATED(9.0)
Set the linear acceleration of the body.
ignition::math::Pose3d WorldCoGPose() const
Get the pose of the body's center of gravity in the world coordinate frame.
ignition::math::Vector3d RelativeLinearAccel() const
Get the linear acceleration of the body.
Store state information of a physics::Link object.
Definition: LinkState.hh:47
virtual void Reset()
Reset the entity.
ignition::math::Vector3d linearAccel
Linear acceleration.
Definition: Link.hh:692
virtual bool GetKinematic() const
\TODO Implement this function.
Definition: Link.hh:400
void SetState(const LinkState &_state)
Set the current link state.
virtual void SetAngularVel(const ignition::math::Vector3d &_vel)=0
Set the angular velocity of the body.
void RemoveParentJoint(const std::string &_jointName)
Remove Joints that have this Link as a child Link.
const ignition::math::Vector3d WorldWindLinearVel() const
Returns this link's wind velocity in the world coordinate frame.
virtual bool WindMode() const
Get the wind mode.
CollisionPtr GetCollision(const std::string &_name)
Get a child collision by name.
virtual void SetForce(const ignition::math::Vector3d &_force)=0
Set the force applied to the body.
bool SetVisualPose(const uint32_t _id, const ignition::math::Pose3d &_pose)
Set the pose of a visual.
void SetLaserRetro(float _retro)
Set the laser retro reflectiveness.
event::ConnectionPtr ConnectEnabled(std::function< void(bool)> _subscriber)
Connect to the add entity signal.
double GetLinearDamping() const
Get the linear damping factor.
void SetPublishData(bool _enable)
Enable/Disable link data publishing.
InertialPtr inertial
Inertial properties.
Definition: Link.hh:685
virtual void UpdateSurface()
Update surface parameters.
Definition: Link.hh:482
Link_V GetParentJointsLinks() const
Returns a vector of parent Links connected by joints.
ignition::math::Matrix3d WorldInertiaMatrix() const
Get the inertia matrix in the world frame.
virtual ignition::math::Vector3d WorldForce() const =0
Get the force applied to the body in the world frame.
void SetAngularAccel(const ignition::math::Vector3d &_accel) GAZEBO_DEPRECATED(9.0)
Set the angular acceleration of the body.
ignition::math::Vector3d RelativeAngularAccel() const
Get the angular acceleration of the body.
bool GetSelfCollide() const
Get Self-Collision Flag.
Link class defines a rigid body entity, containing information on inertia, visual and collision prope...
Definition: Link.hh:52
void ProcessMsg(const msgs::Link &_msg)
Update parameters from a message.
double GetWorldEnergy() const
Returns this link's total energy, or sum of Link::GetWorldEnergyPotential() and Link::GetWorldEnergyK...
Link(EntityPtr _parent)
Constructor.
void UpdateWind(const common::UpdateInfo &_info)
Update the wind.
ignition::math::Pose3d WorldInertialPose() const
Get the world pose of the link inertia (cog position and Moment of Inertia frame).
virtual void AddTorque(const ignition::math::Vector3d &_torque)=0
Add a torque to the body.
bool initialized
This flag is set to true when the link is initialized.
Definition: Link.hh:702
void ResetPhysicsStates()
Reset the velocity, acceleration, force and torque of link.
virtual bool GetEnabled() const =0
Get whether this body is enabled in the physics engine.
void SetScale(const ignition::math::Vector3d &_scale)
Set the scale of the link.
virtual void Load(sdf::ElementPtr _sdf)
Load the body based on an SDF element.
virtual void SetAngularDamping(double _damping)=0
Set the angular damping factor.
Link_V GetChildJointsLinks() const
Returns a vector of children Links connected by joints.
std::map< uint32_t, msgs::Visual > Visuals_M
Definition: Link.hh:627
void AttachStaticModel(ModelPtr &_model, const ignition::math::Pose3d &_offset)
Attach a static model to this link.
virtual void RemoveChild(unsigned int _id)
Remove a child from this entity.
virtual void UpdateParameters(sdf::ElementPtr _sdf)
Update the parameters using new sdf values.
Joint_V GetChildJoints() const
Get the child joints.
virtual void AddRelativeForce(const ignition::math::Vector3d &_force)=0
Add a force to the body, components are relative to the body's own frame of reference.
void AddChildJoint(JointPtr _joint)
Joints that have this Link as a parent Link.
virtual ignition::math::Vector3d WorldTorque() const =0
Get the torque applied to the body about the center of mass in world frame coordinates.
ignition::math::Vector3d RelativeAngularVel() const
Get the angular velocity of the body.
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
msgs::Visual GetVisualMessage(const std::string &_name) const
Returns the visual message specified by its name.
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
virtual void SetSelfCollide(bool _collide)=0
Set whether this body will collide with others in the model.
virtual void OnPoseChange()
This function is called when the entity's (or one of its parents) pose of the parent has changed.
void RemoveChildJoint(const std::string &_jointName)
Remove Joints that have this Link as a parent Link.
virtual bool GetGravityMode() const =0
Get the gravity mode.
virtual void AddForce(const ignition::math::Vector3d &_force)=0
Add a force to the body.
virtual ignition::math::Box BoundingBox() const
Get the bounding box for the link and all the child elements.
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:85
ignition::math::Vector3d WorldAngularMomentum() const
Get the angular momentum of the body CoG in the world frame, which is computed as (I * w),...
virtual void AddRelativeTorque(const ignition::math::Vector3d &_torque)=0
Add a torque to the body, components are relative to the body's own frame of reference.
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
std::vector< ignition::math::Pose3d > attachedModelsOffset
Offsets for the attached models.
Definition: Link.hh:699
ignition::math::Vector3d RelativeTorque() const
Get the torque applied to the body.
size_t BatteryCount() const
Get the number of batteries in this link.
bool FindAllConnectedLinksHelper(const LinkPtr &_originalParentLink, Link_V &_connectedLinks, bool _fistLink=false)
Helper function to find all connected links of a link based on parent/child relations of joints.
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
std::shared_ptr< Battery > BatteryPtr
Definition: CommonTypes.hh:125
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
std::vector< LinkPtr > Link_V
Definition: PhysicsTypes.hh:225
virtual void AddForceAtRelativePosition(const ignition::math::Vector3d &_force, const ignition::math::Vector3d &_relPos)=0
Add a force (in world frame coordinates) to the body at a position relative to the center of mass whi...
ModelPtr GetModel() const
Get the model that this body belongs to.
std::vector< CollisionPtr > Collision_V
Definition: PhysicsTypes.hh:229
virtual ignition::math::Vector3d WorldCoGLinearVel() const =0
Get the linear velocity at the body's center of gravity in the world frame.
virtual bool SetSelected(bool _set)
Set whether this entity has been selected by the user through the gui.
void SetCollideMode(const std::string &_mode)
Set the collide mode of the body.
void Reset()
Reset the link.
ignition::math::Vector3d angularAccel
Angular acceleration.
Definition: Link.hh:696
void Fini()
Finalize the body.
void AddParentJoint(JointPtr _joint)
Joints that have this Link as a child Link.
virtual void SetTorque(const ignition::math::Vector3d &_torque)=0
Set the torque applied to the body.
const Visuals_M & Visuals() const
Return the link visual elements.
double GetWorldEnergyKinetic() const
Returns this link's kinetic energy computed using link's CoG velocity in the inertial (world) frame.
virtual void UpdateMass()
Update the mass matrix.
Definition: Link.hh:479
Information for use in an update event.
Definition: UpdateInfo.hh:30
virtual void RemoveChild(EntityPtr _child)
boost::shared_ptr< Inertial > InertialPtr
Definition: PhysicsTypes.hh:157
void SetStatic(const bool &_static)
Set whether this entity is static: immovable.
virtual void SetKinematic(const bool &_kinematic)
\TODO Implement this function.
void SetInertial(const InertialPtr &_inertial)
Set the mass of the link.
void DetachAllStaticModels()
Detach all static models from this link.
ignition::math::Vector3d RelativeLinearVel() const
Get the linear velocity of the body.
virtual void SetEnabled(bool _enable) const =0
Set whether this body is enabled.
virtual void SetLinearDamping(double _damping)=0
Set the linear damping factor.
common::BatteryPtr Battery(const std::string &_name) const
Get a battery by name.
void DetachStaticModel(const std::string &_modelName)
Detach a static model from this link.