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 
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 
41 namespace boost
42 {
43  class recursive_mutex;
44 }
45 
46 namespace gazebo
47 {
48  namespace physics
49  {
52 
55  class Entity : public Base
56  {
59  public: explicit Entity(BasePtr _parent);
60 
62  public: virtual ~Entity();
63 
66  public: virtual void Load(sdf::ElementPtr _sdf);
67 
69  public: virtual void Fini();
70 
72  public: virtual void Reset();
73 
76  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
77 
80  public: virtual void SetName(const std::string &_name);
81 
84  public: void SetStatic(const bool &_static);
85 
88  public: bool IsStatic() const;
89 
92  public: void SetInitialRelativePose(const math::Pose &_pose);
93 
96  public: math::Pose GetInitialRelativePose() const;
97 
100  public: virtual math::Box GetBoundingBox() const;
101 
104  public: inline const math::Pose &GetWorldPose() const
105  {return this->worldPose;}
106 
109  public: math::Pose GetRelativePose() const;
110 
115  public: void SetRelativePose(const math::Pose &_pose,
116  bool _notify = true,
117  bool _publish = true);
118 
123  public: void SetWorldPose(const math::Pose &_pose,
124  bool _notify = true,
125  bool _publish = true);
126 
129  public: virtual math::Vector3 GetRelativeLinearVel() const
130  {return math::Vector3();}
131 
134  public: virtual math::Vector3 GetWorldLinearVel() const
135  {return math::Vector3();}
136 
139  public: virtual math::Vector3 GetRelativeAngularVel() const
140  {return math::Vector3();}
141 
144  public: virtual math::Vector3 GetWorldAngularVel() const
145  {return math::Vector3();}
146 
149  public: virtual math::Vector3 GetRelativeLinearAccel() const
150  {return math::Vector3();}
151 
154  public: virtual math::Vector3 GetWorldLinearAccel() const
155  {return math::Vector3();}
156 
159  public: virtual math::Vector3 GetRelativeAngularAccel() const
160  {return math::Vector3();}
161 
164  public: virtual math::Vector3 GetWorldAngularAccel() const
165  {return math::Vector3();}
166 
169  public: void SetCanonicalLink(bool _value);
170 
173  public: inline bool IsCanonicalLink() const
174  {return this->isCanonicalLink;}
175 
179  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
180  boost::function<void()> _onComplete);
181 
184  public: void SetAnimation(common::PoseAnimationPtr _anim);
185 
187  public: virtual void StopAnimation();
188 
191  public: ModelPtr GetParentModel();
192 
196  public: CollisionPtr GetChildCollision(const std::string &_name);
197 
201  public: LinkPtr GetChildLink(const std::string &_name);
202 
207  public: void GetNearestEntityBelow(double &_distBelow,
208  std::string &_entityName);
209 
211  public: void PlaceOnNearestEntityBelow();
212 
216  public: void PlaceOnEntity(const std::string &_entityName);
217 
220  public: math::Box GetCollisionBoundingBox() const;
221 
227  public: void SetWorldTwist(const math::Vector3 &_linear,
228  const math::Vector3 &_angular,
229  bool _updateChildren = true);
230 
236  public: const math::Pose &GetDirtyPose() const;
237 
239  private: void PublishPose();
240 
244  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
245 
250  private: void SetWorldPoseModel(const math::Pose &_pose,
251  bool _notify,
252  bool _publish);
253 
258  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
259  bool _notify, bool _publish);
260 
265  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
266  bool _publish);
267 
270  private: void OnPoseMsg(ConstPosePtr &_msg);
271 
274  protected: virtual void OnPoseChange() = 0;
275 
281  private: void UpdatePhysicsPose(bool update_children = true);
282 
285  private: void UpdateAnimation(const common::UpdateInfo &_info);
286 
289 
291  private: bool isStatic;
292 
294  private: bool isCanonicalLink;
295 
297  private: math::Pose initialRelativePose;
298 
300  private: math::Pose worldPose;
301 
304 
306  private: transport::PublisherPtr posePub;
307 
309  private: transport::SubscriberPtr poseSub;
310 
313 
316 
318  protected: msgs::Visual *visualMsg;
319 
321  protected: msgs::Pose *poseMsg;
322 
325 
328 
331 
333  protected: std::vector<event::ConnectionPtr> connections;
334 
337 
339  protected: math::Pose dirtyPose;
340 
342  private: boost::function<void()> onAnimationComplete;
343 
345  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
346  };
348  }
349 }
350 #endif