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 (C) 2012-2014 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 #include "gazebo/util/system.hh"
41 
42 namespace boost
43 {
44  class recursive_mutex;
45 }
46 
47 namespace gazebo
48 {
49  namespace physics
50  {
53 
56  class GAZEBO_VISIBLE Entity : public Base
57  {
60  public: explicit Entity(BasePtr _parent);
61 
63  public: virtual ~Entity();
64 
67  public: virtual void Load(sdf::ElementPtr _sdf);
68 
70  public: virtual void Fini();
71 
73  public: virtual void Reset();
74 
77  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
78 
81  public: virtual void SetName(const std::string &_name);
82 
85  public: void SetStatic(const bool &_static);
86 
89  public: bool IsStatic() const;
90 
93  public: void SetInitialRelativePose(const math::Pose &_pose);
94 
97  public: math::Pose GetInitialRelativePose() const;
98 
101  public: virtual math::Box GetBoundingBox() const;
102 
105  public: inline const math::Pose &GetWorldPose() const
106  {return this->worldPose;}
107 
110  public: math::Pose GetRelativePose() const;
111 
116  public: void SetRelativePose(const math::Pose &_pose,
117  bool _notify = true,
118  bool _publish = true);
119 
124  public: void SetWorldPose(const math::Pose &_pose,
125  bool _notify = true,
126  bool _publish = true);
127 
130  public: virtual math::Vector3 GetRelativeLinearVel() const
131  {return math::Vector3();}
132 
135  public: virtual math::Vector3 GetWorldLinearVel() const
136  {return math::Vector3();}
137 
140  public: virtual math::Vector3 GetRelativeAngularVel() const
141  {return math::Vector3();}
142 
145  public: virtual math::Vector3 GetWorldAngularVel() const
146  {return math::Vector3();}
147 
150  public: virtual math::Vector3 GetRelativeLinearAccel() const
151  {return math::Vector3();}
152 
155  public: virtual math::Vector3 GetWorldLinearAccel() const
156  {return math::Vector3();}
157 
160  public: virtual math::Vector3 GetRelativeAngularAccel() const
161  {return math::Vector3();}
162 
165  public: virtual math::Vector3 GetWorldAngularAccel() const
166  {return math::Vector3();}
167 
170  public: void SetCanonicalLink(bool _value);
171 
174  public: inline bool IsCanonicalLink() const
175  {return this->isCanonicalLink;}
176 
180  public: void SetAnimation(const common::PoseAnimationPtr &_anim,
181  boost::function<void()> _onComplete);
182 
185  public: void SetAnimation(common::PoseAnimationPtr _anim);
186 
188  public: virtual void StopAnimation();
189 
192  public: ModelPtr GetParentModel();
193 
197  public: CollisionPtr GetChildCollision(const std::string &_name);
198 
202  public: LinkPtr GetChildLink(const std::string &_name);
203 
208  public: void GetNearestEntityBelow(double &_distBelow,
209  std::string &_entityName);
210 
212  public: void PlaceOnNearestEntityBelow();
213 
217  public: void PlaceOnEntity(const std::string &_entityName);
218 
221  public: math::Box GetCollisionBoundingBox() const;
222 
228  public: void SetWorldTwist(const math::Vector3 &_linear,
229  const math::Vector3 &_angular,
230  bool _updateChildren = true);
231 
237  public: const math::Pose &GetDirtyPose() const;
238 
240  private: void PublishPose();
241 
245  private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const;
246 
251  private: void SetWorldPoseModel(const math::Pose &_pose,
252  bool _notify,
253  bool _publish);
254 
259  private: void SetWorldPoseCanonicalLink(const math::Pose &_pose,
260  bool _notify, bool _publish);
261 
266  private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify,
267  bool _publish);
268 
271  private: void OnPoseMsg(ConstPosePtr &_msg);
272 
275  protected: virtual void OnPoseChange() = 0;
276 
282  private: void UpdatePhysicsPose(bool update_children = true);
283 
286  private: void UpdateAnimation(const common::UpdateInfo &_info);
287 
290 
292  private: bool isStatic;
293 
295  private: bool isCanonicalLink;
296 
298  private: math::Pose initialRelativePose;
299 
301  private: math::Pose worldPose;
302 
305 
307  private: transport::PublisherPtr posePub;
308 
310  private: transport::SubscriberPtr poseSub;
311 
314 
317 
319  protected: msgs::Visual *visualMsg;
320 
323 
326 
329 
331  protected: std::vector<event::ConnectionPtr> connections;
332 
335 
337  protected: math::Pose dirtyPose;
338 
340  protected: math::Vector3 scale;
341 
343  private: boost::function<void()> onAnimationComplete;
344 
346  private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool, bool);
347  };
349  }
350 }
351 #endif