Entity.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* Desc: Base class for all physical entities 00018 * Author: Nate Koenig 00019 * Date: 03 Apr 2007 00020 */ 00021 00022 #ifndef ENTITY_HH 00023 #define ENTITY_HH 00024 00025 #include <string> 00026 00027 #include "msgs/msgs.h" 00028 00029 #include "transport/TransportTypes.hh" 00030 #include "common/CommonTypes.hh" 00031 #include "math/MathTypes.hh" 00032 #include "math/Box.hh" 00033 00034 #include "math/Pose.hh" 00035 #include "physics/PhysicsTypes.hh" 00036 00037 #include "physics/Base.hh" 00038 00039 namespace boost 00040 { 00041 class recursive_mutex; 00042 } 00043 00044 namespace gazebo 00045 { 00046 namespace physics 00047 { 00050 00052 class Entity : public Base 00053 { 00056 public: Entity(BasePtr parent); 00057 00059 public: virtual ~Entity(); 00060 00063 public: virtual void Load( sdf::ElementPtr &_sdf ); 00064 00066 public: virtual void Fini(); 00067 00068 public: virtual void Reset(); 00069 00071 public: virtual void UpdateParameters( sdf::ElementPtr &_sdf ); 00072 00075 public: virtual void SetName(const std::string &name); 00076 00079 public: void SetStatic(const bool &s); 00080 00083 public: bool IsStatic() const; 00084 00087 public: void SetInitialRelativePose( const math::Pose &p ); 00088 00090 public: virtual math::Box GetBoundingBox() const; 00091 00093 public: inline const math::Pose &GetWorldPose() const 00094 {return this->worldPose;} 00095 00097 public: math::Pose GetRelativePose() const; 00098 00102 public: void SetRelativePose(const math::Pose &pose, bool notify = true); 00103 00107 public: void SetWorldPose(const math::Pose &pose, bool notify=true); 00108 00111 public: virtual math::Vector3 GetRelativeLinearVel() const 00112 {return math::Vector3();} 00113 00116 public: virtual math::Vector3 GetWorldLinearVel() const 00117 {return math::Vector3();} 00118 00121 public: virtual math::Vector3 GetRelativeAngularVel() const 00122 {return math::Vector3();} 00123 00126 public: virtual math::Vector3 GetWorldAngularVel() const 00127 {return math::Vector3();} 00128 00131 public: virtual math::Vector3 GetRelativeLinearAccel() const 00132 {return math::Vector3();} 00133 00136 public: virtual math::Vector3 GetWorldLinearAccel() const 00137 {return math::Vector3();} 00138 00139 00142 public: virtual math::Vector3 GetRelativeAngularAccel() const 00143 {return math::Vector3();} 00144 00147 public: virtual math::Vector3 GetWorldAngularAccel() const 00148 {return math::Vector3();} 00149 00152 public: void SetCanonicalLink(bool _value); 00153 00155 public: inline bool IsCanonicalLink() const 00156 { return this->isCanonicalLink; } 00157 00159 public: void SetAnimation(const common::PoseAnimationPtr &_anim, 00160 boost::function<void()> _onComplete); 00161 public: void SetAnimation(const common::PoseAnimationPtr &_anim); 00162 00163 private: void PublishPose(); 00164 00167 public: ModelPtr GetParentModel(); 00168 00170 public: CollisionPtr GetChildCollision(const std::string &_name); 00171 00173 public: LinkPtr GetChildLink(const std::string &_name); 00174 00179 public: void GetNearestEntityBelow(double &_distBelow, 00180 std::string &_entityName); 00181 00183 public: void PlaceOnNearestEntityBelow(); 00184 00185 public: math::Box GetCollisionBoundingBox() const; 00186 00187 public: void SetWorldTwist(const math::Vector3 &linear, 00188 const math::Vector3 &angular, 00189 bool updateChildren=true); 00190 00191 public: const math::Pose &GetDirtyPose() const; 00192 00193 private: math::Box GetCollisionBoundingBoxHelper(BasePtr _base) const; 00194 00195 private: void SetWorldPoseModel(const math::Pose &_pose, bool _notify); 00196 00197 private: void SetWorldPoseCanonicalLink(const math::Pose &_pose, 00198 bool _notify); 00199 00200 private: void SetWorldPoseDefault(const math::Pose &_pose, bool _notify); 00201 00203 private: void OnPoseMsg(ConstPosePtr &_msg); 00204 00207 protected: virtual void OnPoseChange() = 0; 00208 00210 private: void UpdatePhysicsPose(bool update_children = true); 00211 00213 private: void UpdateAnimation(); 00214 00216 protected: EntityPtr parentEntity; 00217 00218 private: bool isStatic; 00219 00221 private: bool isCanonicalLink; 00222 00224 private: math::Pose initialRelativePose; 00225 private: math::Pose worldPose; 00226 00227 protected: transport::NodePtr node; 00228 private: transport::PublisherPtr posePub; 00229 private: transport::SubscriberPtr poseSub; 00230 protected: transport::PublisherPtr visPub; 00231 protected: transport::PublisherPtr requestPub; 00232 00233 protected: msgs::Visual *visualMsg; 00234 protected: msgs::Pose *poseMsg; 00235 00236 protected: common::PoseAnimationPtr animation; 00237 protected: common::Time prevAnimationTime; 00238 protected: math::Pose animationStartPose; 00239 00240 protected: std::vector<event::ConnectionPtr> connections; 00241 protected: event::ConnectionPtr animationConnection; 00242 00243 protected: math::Pose dirtyPose; 00244 private: boost::function<void()> onAnimationComplete; 00245 00246 private: void (Entity::*setWorldPoseFunc)(const math::Pose &, bool); 00247 }; 00248 00250 } 00251 } 00252 #endif

1.7.5.1