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 2011 Nate Koenig
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: virtual math::Box GetBoundingBox() const;
96 
99  public: inline const math::Pose &GetWorldPose() const
100  {return this->worldPose;}
101 
104  public: math::Pose GetRelativePose() const;
105 
110  public: void SetRelativePose(const math::Pose &_pose,
111  bool _notify = true,
112  bool _publish = true);
113 
118  public: void SetWorldPose(const math::Pose &_pose,
119  bool _notify = true,
120  bool _publish = true);
121 
124  public: virtual math::Vector3 GetRelativeLinearVel() const
125  {return math::Vector3();}
126 
129  public: virtual math::Vector3 GetWorldLinearVel() const
130  {return math::Vector3();}
131 
134  public: virtual math::Vector3 GetRelativeAngularVel() const
135  {return math::Vector3();}
136 
139  public: virtual math::Vector3 GetWorldAngularVel() const
140  {return math::Vector3();}
141 
144  public: virtual math::Vector3 GetRelativeLinearAccel() const
145  {return math::Vector3();}
146 
149  public: virtual math::Vector3 GetWorldLinearAccel() const
150  {return math::Vector3();}
151 
154  public: virtual math::Vector3 GetRelativeAngularAccel() const
155  {return math::Vector3();}
156 
159  public: virtual math::Vector3 GetWorldAngularAccel() const
160  {return math::Vector3();}
161 
164  public: void SetCanonicalLink(bool _value);
165 
168  public: inline bool IsCanonicalLink() const
169  {return this->isCanonicalLink;}
170 
174  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
175  boost::function<void()> _onComplete);
176 
179  public: void SetAnimation(common::PoseAnimationPtr _anim);
180 
182  public: virtual void StopAnimation();
183 
186  public: ModelPtr GetParentModel();
187 
191  public: CollisionPtr GetChildCollision(const std::string &_name);
192 
196  public: LinkPtr GetChildLink(const std::string &_name);
197 
202  public: void GetNearestEntityBelow(double &_distBelow,
203  std::string &_entityName);
204 
206  public: void PlaceOnNearestEntityBelow();
207 
211  public: void PlaceOnEntity(const std::string &_entityName);
212 
215  public: math::Box GetCollisionBoundingBox() const;
216 
222  public: void SetWorldTwist(const math::Vector3 &_linear,
223  const math::Vector3 &_angular,
224  bool _updateChildren = true);
225 
231  public: const math::Pose &GetDirtyPose() const;
232 
234  private: void PublishPose();
235 
239  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
240 
245  private: void SetWorldPoseModel(const math::Pose &_pose,
246  bool _notify,
247  bool _publish);
248 
253  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
254  bool _notify, bool _publish);
255 
260  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
261  bool _publish);
262 
265  private: void OnPoseMsg(ConstPosePtr &_msg);
266 
269  protected: virtual void OnPoseChange() = 0;
270 
276  private: void UpdatePhysicsPose(bool update_children = true);
277 
279  private: void UpdateAnimation();
280 
283 
285  private: bool isStatic;
286 
288  private: bool isCanonicalLink;
289 
291  private: math::Pose initialRelativePose;
292 
294  private: math::Pose worldPose;
295 
298 
300  private: transport::PublisherPtr posePub;
301 
303  private: transport::SubscriberPtr poseSub;
304 
307 
310 
312  protected: msgs::Visual *visualMsg;
313 
315  protected: msgs::Pose *poseMsg;
316 
319 
322 
325 
327  protected: std::vector<event::ConnectionPtr> connections;
328 
331 
333  protected: math::Pose dirtyPose;
334 
336  private: boost::function<void()> onAnimationComplete;
337 
339  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
340  };
341 
343  }
344 }
345 #endif