All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Entity.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 /* 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 
32 
33 #include "gazebo/math/MathTypes.hh"
34 #include "gazebo/math/Box.hh"
35 #include "gazebo/math/Pose.hh"
36 
38 #include "gazebo/physics/Base.hh"
39 
40 namespace boost
41 {
42  class recursive_mutex;
43 }
44 
45 namespace gazebo
46 {
47  namespace physics
48  {
51 
54  class Entity : public Base
55  {
58  public: explicit Entity(BasePtr _parent);
59 
61  public: virtual ~Entity();
62 
65  public: virtual void Load(sdf::ElementPtr _sdf);
66 
68  public: virtual void Fini();
69 
71  public: virtual void Reset();
72 
75  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
76 
79  public: virtual void SetName(const std::string &_name);
80 
83  public: void SetStatic(const bool &_static);
84 
87  public: bool IsStatic() const;
88 
91  public: void SetInitialRelativePose(const math::Pose &_pose);
92 
95  public: math::Pose GetInitialRelativePose() const;
96 
99  public: virtual math::Box GetBoundingBox() const;
100 
103  public: inline const math::Pose &GetWorldPose() const
104  {return this->worldPose;}
105 
108  public: math::Pose GetRelativePose() const;
109 
114  public: void SetRelativePose(const math::Pose &_pose,
115  bool _notify = true,
116  bool _publish = true);
117 
122  public: void SetWorldPose(const math::Pose &_pose,
123  bool _notify = true,
124  bool _publish = true);
125 
128  public: virtual math::Vector3 GetRelativeLinearVel() const
129  {return math::Vector3();}
130 
133  public: virtual math::Vector3 GetWorldLinearVel() const
134  {return math::Vector3();}
135 
138  public: virtual math::Vector3 GetRelativeAngularVel() const
139  {return math::Vector3();}
140 
143  public: virtual math::Vector3 GetWorldAngularVel() const
144  {return math::Vector3();}
145 
148  public: virtual math::Vector3 GetRelativeLinearAccel() const
149  {return math::Vector3();}
150 
153  public: virtual math::Vector3 GetWorldLinearAccel() const
154  {return math::Vector3();}
155 
158  public: virtual math::Vector3 GetRelativeAngularAccel() const
159  {return math::Vector3();}
160 
163  public: virtual math::Vector3 GetWorldAngularAccel() const
164  {return math::Vector3();}
165 
168  public: void SetCanonicalLink(bool _value);
169 
172  public: inline bool IsCanonicalLink() const
173  {return this->isCanonicalLink;}
174 
178  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
179  boost::function<void()> _onComplete);
180 
183  public: void SetAnimation(common::PoseAnimationPtr _anim);
184 
186  public: virtual void StopAnimation();
187 
190  public: ModelPtr GetParentModel();
191 
195  public: CollisionPtr GetChildCollision(const std::string &_name);
196 
200  public: LinkPtr GetChildLink(const std::string &_name);
201 
206  public: void GetNearestEntityBelow(double &_distBelow,
207  std::string &_entityName);
208 
210  public: void PlaceOnNearestEntityBelow();
211 
215  public: void PlaceOnEntity(const std::string &_entityName);
216 
219  public: math::Box GetCollisionBoundingBox() const;
220 
226  public: void SetWorldTwist(const math::Vector3 &_linear,
227  const math::Vector3 &_angular,
228  bool _updateChildren = true);
229 
235  public: const math::Pose &GetDirtyPose() const;
236 
238  private: void PublishPose();
239 
243  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
244 
249  private: void SetWorldPoseModel(const math::Pose &_pose,
250  bool _notify,
251  bool _publish);
252 
257  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
258  bool _notify, bool _publish);
259 
264  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
265  bool _publish);
266 
269  private: void OnPoseMsg(ConstPosePtr &_msg);
270 
273  protected: virtual void OnPoseChange() = 0;
274 
280  private: void UpdatePhysicsPose(bool update_children = true);
281 
283  private: void UpdateAnimation();
284 
287 
289  private: bool isStatic;
290 
292  private: bool isCanonicalLink;
293 
295  private: math::Pose initialRelativePose;
296 
298  private: math::Pose worldPose;
299 
302 
304  private: transport::PublisherPtr posePub;
305 
307  private: transport::SubscriberPtr poseSub;
308 
311 
314 
316  protected: msgs::Visual *visualMsg;
317 
319  protected: msgs::Pose *poseMsg;
320 
323 
326 
329 
331  protected: std::vector<event::ConnectionPtr> connections;
332 
335 
337  protected: math::Pose dirtyPose;
338 
340  private: boost::function<void()> onAnimationComplete;
341 
343  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
344  };
346  }
347 }
348 #endif