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 Nate Koenig
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 JointController;
45  class Gripper;
46 
49 
52  class Model : public Entity
53  {
56  public: explicit Model(BasePtr _parent);
57 
59  public: virtual ~Model();
60 
63  public: void Load(sdf::ElementPtr _sdf);
64 
66  public: virtual void Init();
67 
69  public: void Update();
70 
72  public: virtual void Fini();
73 
76  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
77 
80  public: virtual const sdf::ElementPtr GetSDF();
81 
84  public: virtual void RemoveChild(EntityPtr _child);
85 
87  public: void Reset();
88 
91  public: void SetLinearVel(const math::Vector3 &_vel);
92 
95  public: void SetAngularVel(const math::Vector3 &_vel);
96 
100  public: void SetLinearAccel(const math::Vector3 &_vel);
101 
105  public: void SetAngularAccel(const math::Vector3 &_vel);
106 
109  public: virtual math::Vector3 GetRelativeLinearVel() const;
110 
113  public: virtual math::Vector3 GetWorldLinearVel() const;
114 
117  public: virtual math::Vector3 GetRelativeAngularVel() const;
118 
121  public: virtual math::Vector3 GetWorldAngularVel() const;
122 
125  public: virtual math::Vector3 GetRelativeLinearAccel() const;
126 
129  public: virtual math::Vector3 GetWorldLinearAccel() const;
130 
133  public: virtual math::Vector3 GetRelativeAngularAccel() const;
134 
137  public: virtual math::Vector3 GetWorldAngularAccel() const;
138 
141  public: virtual math::Box GetBoundingBox() const;
142 
145  public: unsigned int GetJointCount() const;
146 
148  public: Link_V GetAllLinks() const GAZEBO_DEPRECATED;
149 
153  public: Link_V GetLinks() const;
154 
158  public: JointPtr GetJoint(unsigned int index) const GAZEBO_DEPRECATED;
159 
162  public: const Joint_V &GetJoints() const;
163 
167  public: JointPtr GetJoint(const std::string &name);
168 
171  public: LinkPtr GetLinkById(unsigned int _id) const;
172 
176  public: LinkPtr GetLink(const std::string &_name ="canonical") const;
177 
179  public: LinkPtr GetLink(unsigned int _index) const GAZEBO_DEPRECATED;
180 
183  public: void SetGravityMode(const bool &_value);
184 
189  public: void SetCollideMode(const std::string &_mode);
190 
193  public: void SetLaserRetro(const float _retro);
194 
196  public: void FillModelMsg(msgs::Model &_msg) GAZEBO_DEPRECATED;
197 
200  public: void FillMsg(msgs::Model &_msg);
201 
204  public: void ProcessMsg(const msgs::Model &_msg);
205 
210  public: void SetJointPosition(const std::string &_jointName,
211  double _position);
212 
216  public: void SetJointPositions(
217  const std::map<std::string, double> &_jointPositions);
218 
223  public: void SetJointAnimation(
224  const std::map<std::string, common::NumericAnimationPtr> _anim,
225  boost::function<void()> _onComplete = NULL);
226 
228  public: virtual void StopAnimation();
229 
244  public: void AttachStaticModel(ModelPtr &_model, math::Pose _offset);
245 
249  public: void DetachStaticModel(const std::string &_model);
250 
251 
254  public: void SetState(const ModelState &_state);
255 
258  public: void SetEnabled(bool _enabled);
259 
266  public: void SetLinkWorldPose(const math::Pose &_pose,
267  std::string _linkName);
268 
275  public: void SetLinkWorldPose(const math::Pose &_pose,
276  const LinkPtr &_link);
277 
281  public: void SetAutoDisable(bool _disable);
282 
286  public: void LoadPlugins();
287 
290  public: unsigned int GetPluginCount() const;
291 
295  public: unsigned int GetSensorCount() const;
296 
298  protected: virtual void OnPoseChange();
299 
302  private: void LoadJoint(sdf::ElementPtr _sdf);
303 
306  private: void LoadPlugin(sdf::ElementPtr _sdf);
307 
310  private: void LoadGripper(sdf::ElementPtr _sdf);
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: JointController *jointController;
347 
348  private: bool pluginsLoaded;
349  };
351  }
352 }
353 #endif