All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Model.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 models
18  * Author: Nathan Koenig and Andrew Howard
19  * Date: 8 May 2003
20  */
21 
22 #ifndef _MODEL_HH_
23 #define _MODEL_HH_
24 
25 #include <string>
26 #include <map>
27 #include <vector>
28 
31 
33 #include "gazebo/physics/Entity.hh"
34 
35 namespace boost
36 {
37  class recursive_mutex;
38 }
39 
40 namespace gazebo
41 {
42  namespace physics
43  {
44  class Gripper;
45 
48 
51  class Model : public Entity
52  {
55  public: explicit Model(BasePtr _parent);
56 
58  public: virtual ~Model();
59 
62  public: void Load(sdf::ElementPtr _sdf);
63 
65  public: void LoadJoints();
66 
68  public: virtual void Init();
69 
71  public: void Update();
72 
74  public: virtual void Fini();
75 
78  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
79 
82  public: virtual const sdf::ElementPtr GetSDF();
83 
86  public: virtual void RemoveChild(EntityPtr _child);
87 
89  public: void Reset();
90 
93  public: void SetLinearVel(const math::Vector3 &_vel);
94 
97  public: void SetAngularVel(const math::Vector3 &_vel);
98 
102  public: void SetLinearAccel(const math::Vector3 &_vel);
103 
107  public: void SetAngularAccel(const math::Vector3 &_vel);
108 
111  public: virtual math::Vector3 GetRelativeLinearVel() const;
112 
115  public: virtual math::Vector3 GetWorldLinearVel() const;
116 
119  public: virtual math::Vector3 GetRelativeAngularVel() const;
120 
123  public: virtual math::Vector3 GetWorldAngularVel() const;
124 
127  public: virtual math::Vector3 GetRelativeLinearAccel() const;
128 
131  public: virtual math::Vector3 GetWorldLinearAccel() const;
132 
135  public: virtual math::Vector3 GetRelativeAngularAccel() const;
136 
139  public: virtual math::Vector3 GetWorldAngularAccel() const;
140 
143  public: virtual math::Box GetBoundingBox() const;
144 
147  public: unsigned int GetJointCount() const;
148 
152  public: Link_V GetLinks() const;
153 
156  public: const Joint_V &GetJoints() const;
157 
161  public: JointPtr GetJoint(const std::string &name);
162 
165  public: LinkPtr GetLinkById(unsigned int _id) const;
166 
170  public: LinkPtr GetLink(const std::string &_name ="canonical") const;
171 
174  public: void SetGravityMode(const bool &_value);
175 
180  public: void SetCollideMode(const std::string &_mode);
181 
184  public: void SetLaserRetro(const float _retro);
185 
188  public: void FillMsg(msgs::Model &_msg);
189 
192  public: void ProcessMsg(const msgs::Model &_msg);
193 
198  public: void SetJointPosition(const std::string &_jointName,
199  double _position);
200 
204  public: void SetJointPositions(
205  const std::map<std::string, double> &_jointPositions);
206 
211  public: void SetJointAnimation(
212  const std::map<std::string, common::NumericAnimationPtr> _anim,
213  boost::function<void()> _onComplete = NULL);
214 
216  public: virtual void StopAnimation();
217 
232  public: void AttachStaticModel(ModelPtr &_model, math::Pose _offset);
233 
237  public: void DetachStaticModel(const std::string &_model);
238 
239 
242  public: void SetState(const ModelState &_state);
243 
246  public: void SetEnabled(bool _enabled);
247 
254  public: void SetLinkWorldPose(const math::Pose &_pose,
255  std::string _linkName);
256 
263  public: void SetLinkWorldPose(const math::Pose &_pose,
264  const LinkPtr &_link);
265 
269  public: void SetAutoDisable(bool _disable);
270 
273  public: bool GetAutoDisable() const;
274 
278  public: void LoadPlugins();
279 
282  public: unsigned int GetPluginCount() const;
283 
287  public: unsigned int GetSensorCount() const;
288 
290  protected: virtual void OnPoseChange();
291 
293  private: void LoadLinks();
294 
297  private: void LoadJoint(sdf::ElementPtr _sdf);
298 
301  private: void LoadPlugin(sdf::ElementPtr _sdf);
302 
305  private: void LoadGripper(sdf::ElementPtr _sdf);
306 
310  { return this->jointController; }
311 
313  protected: std::vector<ModelPtr> attachedModels;
314 
316  protected: std::vector<math::Pose> attachedModelsOffset;
318  private: LinkPtr canonicalLink;
319 
321  private: Joint_V joints;
322 
324  private: std::vector<Gripper*> grippers;
325 
327  private: std::vector<ModelPluginPtr> plugins;
328 
330  private: transport::PublisherPtr jointPub;
331 
333  private: std::map<std::string, common::NumericAnimationPtr>
334  jointAnimations;
335 
337  private: boost::function<void()> onJointAnimationComplete;
338 
340  private: common::Time prevAnimationTime;
341 
343  private: boost::recursive_mutex *updateMutex;
344 
346  private: JointControllerPtr jointController;
347 
348  private: bool pluginsLoaded;
349  };
351  }
352 }
353 #endif