Entity.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 #ifndef GAZEBO_PHYSICS_ENTITY_HH_
18 #define GAZEBO_PHYSICS_ENTITY_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <ignition/math/Box.hh>
23 #include <ignition/math/Pose3.hh>
24 #include <ignition/math/Vector3.hh>
25 #include <ignition/transport/Node.hh>
26 
27 #include <boost/function.hpp>
28 #include "gazebo/msgs/msgs.hh"
29 
33 
35 #include "gazebo/physics/Base.hh"
36 #include "gazebo/util/system.hh"
37 
38 namespace boost
39 {
40  class recursive_mutex;
41 }
42 
43 namespace gazebo
44 {
45  namespace physics
46  {
49 
52  class GZ_PHYSICS_VISIBLE Entity : public Base
53  {
56  public: explicit Entity(BasePtr _parent);
57 
59  public: virtual ~Entity();
60 
63  public: virtual void Load(sdf::ElementPtr _sdf);
64 
66  public: virtual void Fini();
67 
69  public: virtual void Reset();
70  using Base::Reset;
71 
74  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
75 
78  public: virtual void SetName(const std::string &_name);
79 
82  public: void SetStatic(const bool &_static);
83 
86  public: bool IsStatic() const;
87 
90  public: void SetInitialRelativePose(const ignition::math::Pose3d &_pose);
91 
94  public: ignition::math::Pose3d InitialRelativePose() const;
95 
98  public: virtual ignition::math::Box BoundingBox() const;
99 
102  public: inline virtual const ignition::math::Pose3d &WorldPose() const
103  {
104  return this->worldPose;
105  }
106 
109  public: ignition::math::Pose3d RelativePose() const;
110 
115  public: void SetRelativePose(const ignition::math::Pose3d &_pose,
116  const bool _notify = true,
117  const bool _publish = true);
118 
123  public: void SetWorldPose(const ignition::math::Pose3d &_pose,
124  const bool _notify = true,
125  const bool _publish = true);
126 
129  public: virtual ignition::math::Vector3d RelativeLinearVel() const;
130 
133  public: virtual ignition::math::Vector3d WorldLinearVel() const;
134 
137  public: virtual ignition::math::Vector3d RelativeAngularVel() const;
138 
141  public: virtual ignition::math::Vector3d WorldAngularVel() const;
142 
145  public: virtual ignition::math::Vector3d RelativeLinearAccel() const;
146 
149  public: virtual ignition::math::Vector3d WorldLinearAccel() const;
150 
153  public: virtual ignition::math::Vector3d RelativeAngularAccel() const;
154 
157  public: virtual ignition::math::Vector3d WorldAngularAccel() const;
158 
161  public: void SetCanonicalLink(bool _value);
162 
165  public: inline bool IsCanonicalLink() const
166  {return this->isCanonicalLink;}
167 
171  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
172  boost::function<void()> _onComplete);
173 
176  public: void SetAnimation(common::PoseAnimationPtr _anim);
177 
179  public: virtual void StopAnimation();
180 
183  public: ModelPtr GetParentModel();
184 
188  public: CollisionPtr GetChildCollision(const std::string &_name);
189 
193  public: LinkPtr GetChildLink(const std::string &_name);
194 
199  public: void GetNearestEntityBelow(double &_distBelow,
200  std::string &_entityName);
201 
203  public: void PlaceOnNearestEntityBelow();
204 
208  public: void PlaceOnEntity(const std::string &_entityName);
209 
212  public: ignition::math::Box CollisionBoundingBox() const;
213 
219  public: void SetWorldTwist(const ignition::math::Vector3d &_linear,
220  const ignition::math::Vector3d &_angular,
221  const bool _updateChildren = true);
222 
228  public: const ignition::math::Pose3d &DirtyPose() const;
229 
232  protected: virtual void OnPoseChange() = 0;
233 
235  private: virtual void PublishPose();
236 
240  private: ignition::math::Box CollisionBoundingBoxHelper(
241  BasePtr _base) const;
242 
247  private: void SetWorldPoseModel(const ignition::math::Pose3d &_pose,
248  const bool _notify,
249  const bool _publish);
250 
255  private: void SetWorldPoseCanonicalLink(
256  const ignition::math::Pose3d &_pose,
257  const bool _notify, const bool _publish);
258 
263  private: void SetWorldPoseDefault(const ignition::math::Pose3d &_pose,
264  const bool _notify, const bool _publish);
265 
268  private: void OnPoseMsg(ConstPosePtr &_msg);
269 
275  private: void UpdatePhysicsPose(bool update_children = true);
276 
279  private: void UpdateAnimation(const common::UpdateInfo &_info);
280 
283 
285  protected: mutable ignition::math::Pose3d worldPose;
286 
289 
292 
295 
297  protected: msgs::Visual *visualMsg;
298 
301 
304 
306  protected: ignition::math::Pose3d animationStartPose;
307 
309  protected: std::vector<event::ConnectionPtr> connections;
310 
313 
315  protected: ignition::math::Pose3d dirtyPose;
316 
318  protected: ignition::math::Vector3d scale;
319 
321  private: bool isStatic;
322 
324  private: bool isCanonicalLink;
325 
327  private: ignition::math::Pose3d initialRelativePose;
328 
330  private: transport::PublisherPtr posePub;
331 
333  private: transport::SubscriberPtr poseSub;
334 
336  private: boost::function<void()> onAnimationComplete;
337 
339  private: void (Entity::*setWorldPoseFunc)(const ignition::math::Pose3d &,
340  const bool, const bool);
341 
342  // Place ignition::transport objects at the end of this file to
343  // guarantee they are destructed first.
344 
346  protected: ignition::transport::Node nodeIgn;
347 
349  protected: ignition::transport::Node::Publisher visPubIgn;
350 
352  protected: ignition::transport::Node::Publisher requestPubIgn;
353 
355  private: ignition::transport::Node::Publisher posePubIgn;
356  };
358  }
359 }
360 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
boost::shared_ptr< PoseAnimation > PoseAnimationPtr
Definition: CommonTypes.hh:109
Definition: JointMaker.hh:44
Forward declarations for the common classes.
Definition: Animation.hh:26
ignition::transport::Node nodeIgn
Ignition communication node.
Definition: Entity.hh:346
ignition::math::Vector3d scale
Scale of the entity.
Definition: Entity.hh:318
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:165
Information for use in an update event.
Definition: UpdateInfo.hh:30
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
ignition::math::Pose3d worldPose
World pose of the entity.
Definition: Entity.hh:285
default namespace for gazebo
common::Time prevAnimationTime
Previous time an animation was updated.
Definition: Entity.hh:303
transport::PublisherPtr requestPub
Request publisher.
Definition: Entity.hh:294
ignition::transport::Node::Publisher requestPubIgn
Request publisher.
Definition: Entity.hh:352
Base class for most physics classes.
Definition: Base.hh:77
ignition::transport::Node::Publisher visPubIgn
Visual publisher.
Definition: Entity.hh:349
virtual const ignition::math::Pose3d & WorldPose() const
Get the absolute pose of the entity.
Definition: Entity.hh:102
event::ConnectionPtr animationConnection
Connection used to update an animation.
Definition: Entity.hh:312
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:85
transport::PublisherPtr visPub
Visual publisher.
Definition: Entity.hh:291
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
ignition::math::Pose3d animationStartPose
Start pose of an animation.
Definition: Entity.hh:306
msgs::Visual * visualMsg
Visual message container.
Definition: Entity.hh:297
common::PoseAnimationPtr animation
Current pose animation.
Definition: Entity.hh:300
EntityPtr parentEntity
A helper that prevents numerous dynamic_casts.
Definition: Entity.hh:282
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
transport::NodePtr node
Communication node.
Definition: Entity.hh:288
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
ignition::math::Pose3d dirtyPose
The pose set by a physics engine.
Definition: Entity.hh:315
std::vector< event::ConnectionPtr > connections
All our event connections.
Definition: Entity.hh:309