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 
167  public: LinkPtr GetLinkById(unsigned int _id) const;
169 
173  public: LinkPtr GetLink(const std::string &_name ="canonical") const;
174 
177  public: void SetGravityMode(const bool &_value);
178 
183  public: void SetCollideMode(const std::string &_mode);
184 
187  public: void SetLaserRetro(const float _retro);
188 
191  public: void FillMsg(msgs::Model &_msg);
192 
195  public: void ProcessMsg(const msgs::Model &_msg);
196 
201  public: void SetJointPosition(const std::string &_jointName,
202  double _position);
203 
207  public: void SetJointPositions(
208  const std::map<std::string, double> &_jointPositions);
209 
214  public: void SetJointAnimation(
215  const std::map<std::string, common::NumericAnimationPtr> _anim,
216  boost::function<void()> _onComplete = NULL);
217 
219  public: virtual void StopAnimation();
220 
235  public: void AttachStaticModel(ModelPtr &_model, math::Pose _offset);
236 
240  public: void DetachStaticModel(const std::string &_model);
241 
242 
245  public: void SetState(const ModelState &_state);
246 
249  public: void SetEnabled(bool _enabled);
250 
257  public: void SetLinkWorldPose(const math::Pose &_pose,
258  std::string _linkName);
259 
266  public: void SetLinkWorldPose(const math::Pose &_pose,
267  const LinkPtr &_link);
268 
272  public: void SetAutoDisable(bool _disable);
273 
276  public: bool GetAutoDisable() const;
277 
281  public: void LoadPlugins();
282 
285  public: unsigned int GetPluginCount() const;
286 
290  public: unsigned int GetSensorCount() const;
291 
293  protected: virtual void OnPoseChange();
294 
296  private: void LoadLinks();
297 
300  private: void LoadJoint(sdf::ElementPtr _sdf);
301 
304  private: void LoadPlugin(sdf::ElementPtr _sdf);
305 
308  private: void LoadGripper(sdf::ElementPtr _sdf);
309 
313  { return this->jointController; }
314 
316  protected: std::vector<ModelPtr> attachedModels;
317 
319  protected: std::vector<math::Pose> attachedModelsOffset;
321  private: LinkPtr canonicalLink;
322 
324  private: Joint_V joints;
325 
327  private: std::vector<Gripper*> grippers;
328 
330  private: std::vector<ModelPluginPtr> plugins;
331 
333  private: transport::PublisherPtr jointPub;
334 
336  private: std::map<std::string, common::NumericAnimationPtr>
337  jointAnimations;
338 
340  private: boost::function<void()> onJointAnimationComplete;
341 
343  private: common::Time prevAnimationTime;
344 
346  private: boost::recursive_mutex *updateMutex;
347 
349  private: JointControllerPtr jointController;
350 
351  private: bool pluginsLoaded;
352  };
354  }
355 }
356 #endif