Entity.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 #include <ignition/math/Vector3.hh>
28 
29 #include <boost/function.hpp>
30 #include "gazebo/msgs/msgs.hh"
31 
35 
36 #include "gazebo/math/MathTypes.hh"
37 #include "gazebo/math/Box.hh"
38 #include "gazebo/math/Pose.hh"
39 
41 #include "gazebo/physics/Base.hh"
42 #include "gazebo/util/system.hh"
43 
44 namespace boost
45 {
46  class recursive_mutex;
47 }
48 
49 namespace gazebo
50 {
51  namespace physics
52  {
55 
58  class GZ_PHYSICS_VISIBLE Entity : public Base
59  {
62  public: explicit Entity(BasePtr _parent);
63 
65  public: virtual ~Entity();
66 
69  public: virtual void Load(sdf::ElementPtr _sdf);
70 
72  public: virtual void Fini();
73 
75  public: virtual void Reset();
76 
79  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
80 
83  public: virtual void SetName(const std::string &_name);
84 
87  public: void SetStatic(const bool &_static);
88 
91  public: bool IsStatic() const;
92 
95  public: void SetInitialRelativePose(const math::Pose &_pose);
96 
99  public: math::Pose GetInitialRelativePose() const;
100 
103  public: virtual math::Box GetBoundingBox() const;
104 
107  public: inline virtual const math::Pose &GetWorldPose() const
108  {return this->worldPose;}
109 
112  public: math::Pose GetRelativePose() const;
113 
118  public: void SetRelativePose(const math::Pose &_pose,
119  bool _notify = true,
120  bool _publish = true);
121 
126  public: void SetWorldPose(const math::Pose &_pose,
127  bool _notify = true,
128  bool _publish = true);
129 
132  public: virtual math::Vector3 GetRelativeLinearVel() const
133  {return math::Vector3();}
134 
137  public: virtual math::Vector3 GetWorldLinearVel() const
138  {return math::Vector3();}
139 
142  public: virtual math::Vector3 GetRelativeAngularVel() const
143  {return math::Vector3();}
144 
147  public: virtual math::Vector3 GetWorldAngularVel() const
148  {return math::Vector3();}
149 
152  public: virtual math::Vector3 GetRelativeLinearAccel() const
153  {return math::Vector3();}
154 
157  public: virtual math::Vector3 GetWorldLinearAccel() const
158  {return math::Vector3();}
159 
162  public: virtual math::Vector3 GetRelativeAngularAccel() const
163  {return math::Vector3();}
164 
167  public: virtual math::Vector3 GetWorldAngularAccel() const
168  {return math::Vector3();}
169 
172  public: void SetCanonicalLink(bool _value);
173 
176  public: inline bool IsCanonicalLink() const
177  {return this->isCanonicalLink;}
178 
182  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
183  boost::function<void()> _onComplete);
184 
187  public: void SetAnimation(common::PoseAnimationPtr _anim);
188 
190  public: virtual void StopAnimation();
191 
194  public: ModelPtr GetParentModel();
195 
199  public: CollisionPtr GetChildCollision(const std::string &_name);
200 
204  public: LinkPtr GetChildLink(const std::string &_name);
205 
210  public: void GetNearestEntityBelow(double &_distBelow,
211  std::string &_entityName);
212 
214  public: void PlaceOnNearestEntityBelow();
215 
219  public: void PlaceOnEntity(const std::string &_entityName);
220 
223  public: math::Box GetCollisionBoundingBox() const;
224 
230  public: void SetWorldTwist(const math::Vector3 &_linear,
231  const math::Vector3 &_angular,
232  bool _updateChildren = true);
233 
239  public: const math::Pose &GetDirtyPose() const;
240 
243  protected: virtual void OnPoseChange() = 0;
244 
246  private: virtual void PublishPose();
247 
251  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
252 
257  private: void SetWorldPoseModel(const math::Pose &_pose,
258  bool _notify,
259  bool _publish);
260 
265  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
266  bool _notify, bool _publish);
267 
272  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
273  bool _publish);
274 
277  private: void OnPoseMsg(ConstPosePtr &_msg);
278 
284  private: void UpdatePhysicsPose(bool update_children = true);
285 
288  private: void UpdateAnimation(const common::UpdateInfo &_info);
289 
292 
294  protected: mutable math::Pose worldPose;
295 
298 
301 
304 
306  protected: msgs::Visual *visualMsg;
307 
310 
313 
316 
318  protected: std::vector<event::ConnectionPtr> connections;
319 
322 
324  protected: math::Pose dirtyPose;
325 
327  protected: ignition::math::Vector3d scale;
328 
330  private: bool isStatic;
331 
333  private: bool isCanonicalLink;
334 
336  private: math::Pose initialRelativePose;
337 
339  private: transport::PublisherPtr posePub;
340 
342  private: transport::SubscriberPtr poseSub;
343 
345  private: boost::function<void()> onAnimationComplete;
346 
348  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
349  };
351  }
352 }
353 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:100
boost::shared_ptr< PoseAnimation > PoseAnimationPtr
Definition: CommonTypes.hh:128
Definition: JointMaker.hh:46
Forward declarations for the common classes.
Definition: Animation.hh:33
math::Pose dirtyPose
The pose set by a physics engine.
Definition: Entity.hh:324
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
virtual math::Vector3 GetRelativeAngularAccel() const
Get the angular acceleration of the entity.
Definition: Entity.hh:162
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
math::Pose animationStartPose
Start pose of an animation.
Definition: Entity.hh:315
ignition::math::Vector3d scale
Scale of the entity.
Definition: Entity.hh:327
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
bool IsCanonicalLink() const
A helper function that checks if this is a canonical body.
Definition: Entity.hh:176
virtual math::Vector3 GetRelativeLinearVel() const
Get the linear velocity of the entity.
Definition: Entity.hh:132
Information for use in an update event.
Definition: UpdateInfo.hh:30
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
default namespace for gazebo
virtual math::Vector3 GetWorldAngularAccel() const
Get the angular acceleration of the entity in the world frame.
Definition: Entity.hh:167
virtual math::Vector3 GetWorldLinearAccel() const
Get the linear acceleration of the entity in the world frame.
Definition: Entity.hh:157
virtual const math::Pose & GetWorldPose() const
Get the absolute pose of the entity.
Definition: Entity.hh:107
common::Time prevAnimationTime
Previous time an animation was updated.
Definition: Entity.hh:312
transport::PublisherPtr requestPub
Request publisher.
Definition: Entity.hh:303
Base class for most physics classes.
Definition: Base.hh:81
virtual math::Vector3 GetRelativeAngularVel() const
Get the angular velocity of the entity.
Definition: Entity.hh:142
event::ConnectionPtr animationConnection
Connection used to update an animation.
Definition: Entity.hh:321
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:153
Forward declarations for the math classes.
Base class for all physics objects in Gazebo.
Definition: Entity.hh:58
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:80
transport::PublisherPtr visPub
Visual publisher.
Definition: Entity.hh:300
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:88
msgs::Visual * visualMsg
Visual message container.
Definition: Entity.hh:306
common::PoseAnimationPtr animation
Current pose animation.
Definition: Entity.hh:309
virtual math::Vector3 GetRelativeLinearAccel() const
Get the linear acceleration of the entity.
Definition: Entity.hh:152
virtual math::Vector3 GetWorldAngularVel() const
Get the angular velocity of the entity in the world frame.
Definition: Entity.hh:147
EntityPtr parentEntity
A helper that prevents numerous dynamic_casts.
Definition: Entity.hh:291
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:104
math::Pose worldPose
World pose of the entity.
Definition: Entity.hh:294
transport::NodePtr node
Communication node.
Definition: Entity.hh:297
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:72
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
std::vector< event::ConnectionPtr > connections
All our event connections.
Definition: Entity.hh:318
virtual math::Vector3 GetWorldLinearVel() const
Get the linear velocity of the entity in the world frame.
Definition: Entity.hh:137