Entity.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 /* Desc: Base class for all physical entities
18  * Author: Nate Koenig
19  * Date: 03 Apr 2007
20  */
21 
22 #ifndef _ENTITY_HH_
23 #define _ENTITY_HH_
24 
25 #include <string>
26 #include <vector>
27 
28 #include <boost/function.hpp>
29 #include "gazebo/msgs/msgs.hh"
30 
34 
35 #include "gazebo/math/MathTypes.hh"
36 #include "gazebo/math/Box.hh"
37 #include "gazebo/math/Pose.hh"
38 
40 #include "gazebo/physics/Base.hh"
41 #include "gazebo/util/system.hh"
42 
43 namespace boost
44 {
45  class recursive_mutex;
46 }
47 
48 namespace gazebo
49 {
50  namespace physics
51  {
54 
58  {
61  public: explicit Entity(BasePtr _parent);
62 
64  public: virtual ~Entity();
65 
68  public: virtual void Load(sdf::ElementPtr _sdf);
69 
71  public: virtual void Fini();
72 
74  public: virtual void Reset();
75 
78  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
79 
82  public: virtual void SetName(const std::string &_name);
83 
86  public: void SetStatic(const bool &_static);
87 
90  public: bool IsStatic() const;
91 
94  public: void SetInitialRelativePose(const math::Pose &_pose);
95 
98  public: math::Pose GetInitialRelativePose() const;
99 
102  public: virtual math::Box GetBoundingBox() const;
103 
106  public: inline virtual const math::Pose &GetWorldPose() const
107  {return this->worldPose;}
108 
111  public: math::Pose GetRelativePose() const;
112 
117  public: void SetRelativePose(const math::Pose &_pose,
118  bool _notify = true,
119  bool _publish = true);
120 
125  public: void SetWorldPose(const math::Pose &_pose,
126  bool _notify = true,
127  bool _publish = true);
128 
131  public: virtual math::Vector3 GetRelativeLinearVel() const
132  {return math::Vector3();}
133 
136  public: virtual math::Vector3 GetWorldLinearVel() const
137  {return math::Vector3();}
138 
141  public: virtual math::Vector3 GetRelativeAngularVel() const
142  {return math::Vector3();}
143 
146  public: virtual math::Vector3 GetWorldAngularVel() const
147  {return math::Vector3();}
148 
151  public: virtual math::Vector3 GetRelativeLinearAccel() const
152  {return math::Vector3();}
153 
156  public: virtual math::Vector3 GetWorldLinearAccel() const
157  {return math::Vector3();}
158 
161  public: virtual math::Vector3 GetRelativeAngularAccel() const
162  {return math::Vector3();}
163 
166  public: virtual math::Vector3 GetWorldAngularAccel() const
167  {return math::Vector3();}
168 
171  public: void SetCanonicalLink(bool _value);
172 
175  public: inline bool IsCanonicalLink() const
176  {return this->isCanonicalLink;}
177 
181  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
182  boost::function<void()> _onComplete);
183 
186  public: void SetAnimation(common::PoseAnimationPtr _anim);
187 
189  public: virtual void StopAnimation();
190 
193  public: ModelPtr GetParentModel();
194 
198  public: CollisionPtr GetChildCollision(const std::string &_name);
199 
203  public: LinkPtr GetChildLink(const std::string &_name);
204 
209  public: void GetNearestEntityBelow(double &_distBelow,
210  std::string &_entityName);
211 
213  public: void PlaceOnNearestEntityBelow();
214 
218  public: void PlaceOnEntity(const std::string &_entityName);
219 
222  public: math::Box GetCollisionBoundingBox() const;
223 
229  public: void SetWorldTwist(const math::Vector3 &_linear,
230  const math::Vector3 &_angular,
231  bool _updateChildren = true);
232 
238  public: const math::Pose &GetDirtyPose() const;
239 
242  protected: virtual void OnPoseChange() = 0;
243 
245  private: void PublishPose();
246 
250  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
251 
256  private: void SetWorldPoseModel(const math::Pose &_pose,
257  bool _notify,
258  bool _publish);
259 
264  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
265  bool _notify, bool _publish);
266 
271  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
272  bool _publish);
273 
276  private: void OnPoseMsg(ConstPosePtr &_msg);
277 
283  private: void UpdatePhysicsPose(bool update_children = true);
284 
287  private: void UpdateAnimation(const common::UpdateInfo &_info);
288 
291 
293  protected: mutable math::Pose worldPose;
294 
297 
300 
303 
305  protected: msgs::Visual *visualMsg;
306 
309 
312 
315 
317  protected: std::vector<event::ConnectionPtr> connections;
318 
321 
323  protected: math::Pose dirtyPose;
324 
326  protected: math::Vector3 scale;
327 
329  private: bool isStatic;
330 
332  private: bool isCanonicalLink;
333 
335  private: math::Pose initialRelativePose;
336 
338  private: transport::PublisherPtr posePub;
339 
341  private: transport::SubscriberPtr poseSub;
342 
344  private: boost::function<void()> onAnimationComplete;
345 
347  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
348  };
350  }
351 }
352 #endif
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:147
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:68
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:84
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:318
Definition: JointMaker.hh:41
Forward declarations for the common classes.
Definition: Animation.hh:33
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
event::ConnectionPtr animationConnection
Connection used to update an animation.
Definition: Entity.hh:320
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
Mathematical representation of a box and related functions.
Definition: Box.hh:35
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Forward declarations for transport.
virtual math::Vector3 GetWorldAngularVel() const
Get the angular velocity of the entity in the world frame.
Definition: Entity.hh:146
transport::PublisherPtr visPub
Visual publisher.
Definition: Entity.hh:299
Information for use in an update event.
Definition: UpdateInfo.hh:30
math::Pose dirtyPose
The pose set by a physics engine.
Definition: Entity.hh:323
default namespace for gazebo
virtual math::Vector3 GetWorldLinearAccel() const
Get the linear acceleration of the entity in the world frame.
Definition: Entity.hh:156
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:96
math::Pose animationStartPose
Start pose of an animation.
Definition: Entity.hh:314
virtual math::Vector3 GetRelativeAngularVel() const
Get the angular velocity of the entity.
Definition: Entity.hh:141
virtual math::Vector3 GetWorldLinearVel() const
Get the linear velocity of the entity in the world frame.
Definition: Entity.hh:136
common::PoseAnimationPtr animation
Current pose animation.
Definition: Entity.hh:308
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:76
bool IsCanonicalLink() const
A helper function that checks if this is a canonical body.
Definition: Entity.hh:175
Base class for most physics classes.
Definition: Base.hh:80
virtual const math::Pose & GetWorldPose() const
Get the absolute pose of the entity.
Definition: Entity.hh:106
transport::NodePtr node
Communication node.
Definition: Entity.hh:296
Forward declarations for the math classes.
math::Pose worldPose
World pose of the entity.
Definition: Entity.hh:293
Base class for all physics objects in Gazebo.
Definition: Entity.hh:57
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
common::Time prevAnimationTime
Previous time an animation was updated.
Definition: Entity.hh:311
std::vector< event::ConnectionPtr > connections
All our event connections.
Definition: Entity.hh:317
math::Vector3 scale
Scale of the entity.
Definition: Entity.hh:326
virtual math::Vector3 GetRelativeAngularAccel() const
Get the angular acceleration of the entity.
Definition: Entity.hh:161
virtual math::Vector3 GetRelativeLinearAccel() const
Get the linear acceleration of the entity.
Definition: Entity.hh:151
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< PoseAnimation > PoseAnimationPtr
Definition: CommonTypes.hh:126
msgs::Visual * visualMsg
Visual message container.
Definition: Entity.hh:305
transport::PublisherPtr requestPub
Request publisher.
Definition: Entity.hh:302
virtual math::Vector3 GetWorldAngularAccel() const
Get the angular acceleration of the entity in the world frame.
Definition: Entity.hh:166
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:92
EntityPtr parentEntity
A helper that prevents numerous dynamic_casts.
Definition: Entity.hh:290
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39
virtual math::Vector3 GetRelativeLinearVel() const
Get the linear velocity of the entity.
Definition: Entity.hh:131