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  using Base::Reset;
77 
80  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
81 
84  public: virtual void SetName(const std::string &_name);
85 
88  public: void SetStatic(const bool &_static);
89 
92  public: bool IsStatic() const;
93 
96  public: void SetInitialRelativePose(const math::Pose &_pose);
97 
100  public: math::Pose GetInitialRelativePose() const;
101 
104  public: virtual math::Box GetBoundingBox() const;
105 
108  public: inline virtual const math::Pose &GetWorldPose() const
109  {return this->worldPose;}
110 
113  public: math::Pose GetRelativePose() const;
114 
119  public: void SetRelativePose(const math::Pose &_pose,
120  bool _notify = true,
121  bool _publish = true);
122 
127  public: void SetWorldPose(const math::Pose &_pose,
128  bool _notify = true,
129  bool _publish = true);
130 
133  public: virtual math::Vector3 GetRelativeLinearVel() const
134  {return math::Vector3();}
135 
138  public: virtual math::Vector3 GetWorldLinearVel() const
139  {return math::Vector3();}
140 
143  public: virtual math::Vector3 GetRelativeAngularVel() const
144  {return math::Vector3();}
145 
148  public: virtual math::Vector3 GetWorldAngularVel() const
149  {return math::Vector3();}
150 
153  public: virtual math::Vector3 GetRelativeLinearAccel() const
154  {return math::Vector3();}
155 
158  public: virtual math::Vector3 GetWorldLinearAccel() const
159  {return math::Vector3();}
160 
163  public: virtual math::Vector3 GetRelativeAngularAccel() const
164  {return math::Vector3();}
165 
168  public: virtual math::Vector3 GetWorldAngularAccel() const
169  {return math::Vector3();}
170 
173  public: void SetCanonicalLink(bool _value);
174 
177  public: inline bool IsCanonicalLink() const
178  {return this->isCanonicalLink;}
179 
183  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
184  boost::function<void()> _onComplete);
185 
188  public: void SetAnimation(common::PoseAnimationPtr _anim);
189 
191  public: virtual void StopAnimation();
192 
195  public: ModelPtr GetParentModel();
196 
200  public: CollisionPtr GetChildCollision(const std::string &_name);
201 
205  public: LinkPtr GetChildLink(const std::string &_name);
206 
211  public: void GetNearestEntityBelow(double &_distBelow,
212  std::string &_entityName);
213 
215  public: void PlaceOnNearestEntityBelow();
216 
220  public: void PlaceOnEntity(const std::string &_entityName);
221 
224  public: math::Box GetCollisionBoundingBox() const;
225 
231  public: void SetWorldTwist(const math::Vector3 &_linear,
232  const math::Vector3 &_angular,
233  bool _updateChildren = true);
234 
240  public: const math::Pose &GetDirtyPose() const;
241 
244  protected: virtual void OnPoseChange() = 0;
245 
247  private: virtual void PublishPose();
248 
252  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
253 
258  private: void SetWorldPoseModel(const math::Pose &_pose,
259  bool _notify,
260  bool _publish);
261 
266  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
267  bool _notify, bool _publish);
268 
273  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
274  bool _publish);
275 
278  private: void OnPoseMsg(ConstPosePtr &_msg);
279 
285  private: void UpdatePhysicsPose(bool update_children = true);
286 
289  private: void UpdateAnimation(const common::UpdateInfo &_info);
290 
293 
295  protected: mutable math::Pose worldPose;
296 
299 
302 
305 
307  protected: msgs::Visual *visualMsg;
308 
311 
314 
317 
319  protected: std::vector<event::ConnectionPtr> connections;
320 
323 
325  protected: math::Pose dirtyPose;
326 
328  protected: ignition::math::Vector3d scale;
329 
331  private: bool isStatic;
332 
334  private: bool isCanonicalLink;
335 
337  private: math::Pose initialRelativePose;
338 
340  private: transport::PublisherPtr posePub;
341 
343  private: transport::SubscriberPtr poseSub;
344 
346  private: boost::function<void()> onAnimationComplete;
347 
349  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
350  };
352  }
353 }
354 #endif
virtual math::Vector3 GetWorldAngularVel() const
Get the angular velocity of the entity in the world frame.
Definition: Entity.hh:148
virtual math::Vector3 GetWorldLinearVel() const
Get the linear velocity of the entity in the world frame.
Definition: Entity.hh:138
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
boost::shared_ptr< PoseAnimation > PoseAnimationPtr
Definition: CommonTypes.hh:128
math::Pose dirtyPose
The pose set by a physics engine.
Definition: Entity.hh:325
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
virtual math::Vector3 GetRelativeLinearAccel() const
Get the linear acceleration of the entity.
Definition: Entity.hh:153
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:316
ignition::math::Vector3d scale
Scale of the entity.
Definition: Entity.hh:328
virtual void Reset()
Reset the object.
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
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 GetRelativeAngularVel() const
Get the angular velocity of the entity.
Definition: Entity.hh:143
virtual math::Vector3 GetWorldLinearAccel() const
Get the linear acceleration of the entity in the world frame.
Definition: Entity.hh:158
virtual math::Vector3 GetWorldAngularAccel() const
Get the angular acceleration of the entity in the world frame.
Definition: Entity.hh:168
bool IsCanonicalLink() const
A helper function that checks if this is a canonical body.
Definition: Entity.hh:177
common::Time prevAnimationTime
Previous time an animation was updated.
Definition: Entity.hh:313
transport::PublisherPtr requestPub
Request publisher.
Definition: Entity.hh:304
Base class for most physics classes.
Definition: Base.hh:77
event::ConnectionPtr animationConnection
Connection used to update an animation.
Definition: Entity.hh:322
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:85
transport::PublisherPtr visPub
Visual publisher.
Definition: Entity.hh:301
virtual const math::Pose & GetWorldPose() const
Get the absolute pose of the entity.
Definition: Entity.hh:108
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
virtual math::Vector3 GetRelativeLinearVel() const
Get the linear velocity of the entity.
Definition: Entity.hh:133
msgs::Visual * visualMsg
Visual message container.
Definition: Entity.hh:307
common::PoseAnimationPtr animation
Current pose animation.
Definition: Entity.hh:310
virtual math::Vector3 GetRelativeAngularAccel() const
Get the angular acceleration of the entity.
Definition: Entity.hh:163
EntityPtr parentEntity
A helper that prevents numerous dynamic_casts.
Definition: Entity.hh:292
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
math::Pose worldPose
World pose of the entity.
Definition: Entity.hh:295
transport::NodePtr node
Communication node.
Definition: Entity.hh:298
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
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:319