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 "gazebo/msgs/msgs.hh"
29 
33 
34 #include "gazebo/math/MathTypes.hh"
35 #include "gazebo/math/Box.hh"
36 #include "gazebo/math/Pose.hh"
37 
39 #include "gazebo/physics/Base.hh"
40 #include "gazebo/util/system.hh"
41 
42 namespace boost
43 {
44  class recursive_mutex;
45 }
46 
47 namespace gazebo
48 {
49  namespace physics
50  {
53 
56  class GAZEBO_VISIBLE Entity : public Base
57  {
60  public: explicit Entity(BasePtr _parent);
61 
63  public: virtual ~Entity();
64 
67  public: virtual void Load(sdf::ElementPtr _sdf);
68 
70  public: virtual void Fini();
71 
73  public: virtual void Reset();
74 
77  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
78 
81  public: virtual void SetName(const std::string &_name);
82 
85  public: void SetStatic(const bool &_static);
86 
89  public: bool IsStatic() const;
90 
93  public: void SetInitialRelativePose(const math::Pose &_pose);
94 
97  public: math::Pose GetInitialRelativePose() const;
98 
101  public: virtual math::Box GetBoundingBox() const;
102 
105  public: inline virtual const math::Pose &GetWorldPose() const
106  {return this->worldPose;}
107 
110  public: math::Pose GetRelativePose() const;
111 
116  public: void SetRelativePose(const math::Pose &_pose,
117  bool _notify = true,
118  bool _publish = true);
119 
124  public: void SetWorldPose(const math::Pose &_pose,
125  bool _notify = true,
126  bool _publish = true);
127 
130  public: virtual math::Vector3 GetRelativeLinearVel() const
131  {return math::Vector3();}
132 
135  public: virtual math::Vector3 GetWorldLinearVel() const
136  {return math::Vector3();}
137 
140  public: virtual math::Vector3 GetRelativeAngularVel() const
141  {return math::Vector3();}
142 
145  public: virtual math::Vector3 GetWorldAngularVel() const
146  {return math::Vector3();}
147 
150  public: virtual math::Vector3 GetRelativeLinearAccel() const
151  {return math::Vector3();}
152 
155  public: virtual math::Vector3 GetWorldLinearAccel() const
156  {return math::Vector3();}
157 
160  public: virtual math::Vector3 GetRelativeAngularAccel() const
161  {return math::Vector3();}
162 
165  public: virtual math::Vector3 GetWorldAngularAccel() const
166  {return math::Vector3();}
167 
170  public: void SetCanonicalLink(bool _value);
171 
174  public: inline bool IsCanonicalLink() const
175  {return this->isCanonicalLink;}
176 
180  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
181  boost::function<void()> _onComplete);
182 
185  public: void SetAnimation(common::PoseAnimationPtr _anim);
186 
188  public: virtual void StopAnimation();
189 
192  public: ModelPtr GetParentModel();
193 
197  public: CollisionPtr GetChildCollision(const std::string &_name);
198 
202  public: LinkPtr GetChildLink(const std::string &_name);
203 
208  public: void GetNearestEntityBelow(double &_distBelow,
209  std::string &_entityName);
210 
212  public: void PlaceOnNearestEntityBelow();
213 
217  public: void PlaceOnEntity(const std::string &_entityName);
218 
221  public: math::Box GetCollisionBoundingBox() const;
222 
228  public: void SetWorldTwist(const math::Vector3 &_linear,
229  const math::Vector3 &_angular,
230  bool _updateChildren = true);
231 
237  public: const math::Pose &GetDirtyPose() const;
238 
241  protected: virtual void OnPoseChange() = 0;
242 
244  private: void PublishPose();
245 
249  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
250 
255  private: void SetWorldPoseModel(const math::Pose &_pose,
256  bool _notify,
257  bool _publish);
258 
263  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
264  bool _notify, bool _publish);
265 
270  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
271  bool _publish);
272 
275  private: void OnPoseMsg(ConstPosePtr &_msg);
276 
282  private: void UpdatePhysicsPose(bool update_children = true);
283 
286  private: void UpdateAnimation(const common::UpdateInfo &_info);
287 
290 
292  protected: mutable math::Pose worldPose;
293 
296 
299 
302 
304  protected: msgs::Visual *visualMsg;
305 
308 
311 
314 
316  protected: std::vector<event::ConnectionPtr> connections;
317 
320 
322  protected: math::Pose dirtyPose;
323 
325  protected: math::Vector3 scale;
326 
328  private: bool isStatic;
329 
331  private: bool isCanonicalLink;
332 
334  private: math::Pose initialRelativePose;
335 
337  private: transport::PublisherPtr posePub;
338 
340  private: transport::SubscriberPtr poseSub;
341 
343  private: boost::function<void()> onAnimationComplete;
344 
346  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
347  };
349  }
350 }
351 #endif
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:144
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:66
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:82
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
event::ConnectionPtr animationConnection
Connection used to update an animation.
Definition: Entity.hh:319
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
Mathematical representation of a box and related functions.
Definition: Box.hh:33
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:145
transport::PublisherPtr visPub
Visual publisher.
Definition: Entity.hh:298
Information for use in an update event.
Definition: UpdateInfo.hh:30
math::Pose dirtyPose
The pose set by a physics engine.
Definition: Entity.hh:322
default namespace for gazebo
virtual math::Vector3 GetWorldLinearAccel() const
Get the linear acceleration of the entity in the world frame.
Definition: Entity.hh:155
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:94
math::Pose animationStartPose
Start pose of an animation.
Definition: Entity.hh:313
virtual math::Vector3 GetRelativeAngularVel() const
Get the angular velocity of the entity.
Definition: Entity.hh:140
virtual math::Vector3 GetWorldLinearVel() const
Get the linear velocity of the entity in the world frame.
Definition: Entity.hh:135
common::PoseAnimationPtr animation
Current pose animation.
Definition: Entity.hh:307
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:74
bool IsCanonicalLink() const
A helper function that checks if this is a canonical body.
Definition: Entity.hh:174
Base class for most physics classes.
Definition: Base.hh:74
virtual const math::Pose & GetWorldPose() const
Get the absolute pose of the entity.
Definition: Entity.hh:105
transport::NodePtr node
Communication node.
Definition: Entity.hh:295
Forward declarations for the math classes.
math::Pose worldPose
World pose of the entity.
Definition: Entity.hh:292
Base class for all physics objects in Gazebo.
Definition: Entity.hh:56
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
common::Time prevAnimationTime
Previous time an animation was updated.
Definition: Entity.hh:310
std::vector< event::ConnectionPtr > connections
All our event connections.
Definition: Entity.hh:316
math::Vector3 scale
Scale of the entity.
Definition: Entity.hh:325
virtual math::Vector3 GetRelativeAngularAccel() const
Get the angular acceleration of the entity.
Definition: Entity.hh:160
virtual math::Vector3 GetRelativeLinearAccel() const
Get the linear acceleration of the entity.
Definition: Entity.hh:150
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< PoseAnimation > PoseAnimationPtr
Definition: CommonTypes.hh:123
msgs::Visual * visualMsg
Visual message container.
Definition: Entity.hh:304
transport::PublisherPtr requestPub
Request publisher.
Definition: Entity.hh:301
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
virtual math::Vector3 GetWorldAngularAccel() const
Get the angular acceleration of the entity in the world frame.
Definition: Entity.hh:165
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:90
EntityPtr parentEntity
A helper that prevents numerous dynamic_casts.
Definition: Entity.hh:289
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
virtual math::Vector3 GetRelativeLinearVel() const
Get the linear velocity of the entity.
Definition: Entity.hh:130