Model.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 #include <boost/function.hpp>
29 #include <boost/thread/recursive_mutex.hpp>
30 
34 #include "gazebo/physics/Entity.hh"
35 #include "gazebo/util/system.hh"
36 
37 namespace boost
38 {
39  class recursive_mutex;
40 }
41 
42 namespace gazebo
43 {
44  namespace physics
45  {
46  class Gripper;
47 
50 
53  class GZ_PHYSICS_VISIBLE Model : public Entity
54  {
57  public: explicit Model(BasePtr _parent);
58 
60  public: virtual ~Model();
61 
64  public: void Load(sdf::ElementPtr _sdf);
65 
67  public: void LoadJoints();
68 
70  public: virtual void Init();
71 
73  public: void Update();
74 
76  public: virtual void Fini();
77 
80  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
81 
84  public: virtual const sdf::ElementPtr GetSDF();
85 
91  public: virtual const sdf::ElementPtr UnscaledSDF();
92 
95  public: virtual void RemoveChild(EntityPtr _child);
96  using Base::RemoveChild;
97 
99  public: void Reset();
100 
103  public: void ResetPhysicsStates();
104 
107  public: void SetLinearVel(const math::Vector3 &_vel);
108 
111  public: void SetAngularVel(const math::Vector3 &_vel);
112 
116  public: void SetLinearAccel(const math::Vector3 &_vel);
117 
121  public: void SetAngularAccel(const math::Vector3 &_vel);
122 
125  public: virtual math::Vector3 GetRelativeLinearVel() const;
126 
129  public: virtual math::Vector3 GetWorldLinearVel() const;
130 
133  public: virtual math::Vector3 GetRelativeAngularVel() const;
134 
137  public: virtual math::Vector3 GetWorldAngularVel() const;
138 
141  public: virtual math::Vector3 GetRelativeLinearAccel() const;
142 
145  public: virtual math::Vector3 GetWorldLinearAccel() const;
146 
149  public: virtual math::Vector3 GetRelativeAngularAccel() const;
150 
153  public: virtual math::Vector3 GetWorldAngularAccel() const;
154 
157  public: virtual math::Box GetBoundingBox() const;
158 
161  public: unsigned int GetJointCount() const;
162 
166  public: ModelPtr NestedModel(const std::string &_name) const;
167 
170  public: const Model_V &NestedModels() const;
171 
175  public: const Link_V &GetLinks() const;
176 
179  public: const Joint_V &GetJoints() const;
180 
184  public: JointPtr GetJoint(const std::string &name);
185 
190  public: LinkPtr GetLinkById(unsigned int _id) const;
192 
196  public: LinkPtr GetLink(const std::string &_name ="canonical") const;
197 
205  public: bool GetSelfCollide() const;
206 
210  public: void SetSelfCollide(bool _self_collide);
211 
214  public: void SetGravityMode(const bool &_value);
215 
220  public: void SetCollideMode(const std::string &_mode);
221 
224  public: void SetLaserRetro(const float _retro);
225 
228  public: virtual void FillMsg(msgs::Model &_msg);
229 
232  public: void ProcessMsg(const msgs::Model &_msg);
233 
238  public: void SetJointPosition(const std::string &_jointName,
239  double _position, int _index = 0);
240 
244  public: void SetJointPositions(
245  const std::map<std::string, double> &_jointPositions);
246 
251  public: void SetJointAnimation(
252  const std::map<std::string, common::NumericAnimationPtr> &_anims,
253  boost::function<void()> _onComplete = NULL);
254 
256  public: virtual void StopAnimation();
257 
272  public: void AttachStaticModel(ModelPtr &_model, math::Pose _offset);
273 
277  public: void DetachStaticModel(const std::string &_model);
278 
281  public: void SetState(const ModelState &_state);
282 
286  public: void SetScale(const math::Vector3 &_scale)
287  GAZEBO_DEPRECATED(7.0);
288 
294  public: void SetScale(const ignition::math::Vector3d &_scale,
295  const bool _publish = false);
296 
301  public: ignition::math::Vector3d Scale() const;
302 
305  public: void SetEnabled(bool _enabled);
306 
313  public: void SetLinkWorldPose(const math::Pose &_pose,
314  std::string _linkName);
315 
322  public: void SetLinkWorldPose(const math::Pose &_pose,
323  const LinkPtr &_link);
324 
328  public: void SetAutoDisable(bool _disable);
329 
332  public: bool GetAutoDisable() const;
333 
337  public: void LoadPlugins();
338 
341  public: unsigned int GetPluginCount() const;
342 
346  public: unsigned int GetSensorCount() const;
347 
350  public: JointControllerPtr GetJointController();
351 
354  public: GripperPtr GetGripper(size_t _index) const;
355 
359  public: size_t GetGripperCount() const;
360 
364  public: double GetWorldEnergyPotential() const;
365 
370  public: double GetWorldEnergyKinetic() const;
371 
376  public: double GetWorldEnergy() const;
377 
387  public: gazebo::physics::JointPtr CreateJoint(
388  const std::string &_name, const std::string &_type,
389  physics::LinkPtr _parent, physics::LinkPtr _child);
390 
394  public: bool RemoveJoint(const std::string &_name);
395 
398  public: boost::shared_ptr<Model> shared_from_this();
399 
404  public: LinkPtr CreateLink(const std::string &_name);
405 
407  protected: virtual void OnPoseChange();
408 
410  private: void LoadLinks();
411 
413  private: void LoadModels();
414 
417  private: void LoadJoint(sdf::ElementPtr _sdf);
418 
421  private: void LoadPlugin(sdf::ElementPtr _sdf);
422 
425  private: void LoadGripper(sdf::ElementPtr _sdf);
426 
430  private: void RemoveLink(const std::string &_name);
431 
433  private: virtual void PublishScale();
434 
436  protected: std::vector<ModelPtr> attachedModels;
437 
439  protected: std::vector<math::Pose> attachedModelsOffset;
440 
443 
445  private: LinkPtr canonicalLink;
446 
448  private: Joint_V joints;
449 
451  private: Link_V links;
452 
454  private: Model_V models;
455 
457  private: std::vector<GripperPtr> grippers;
458 
460  private: std::vector<ModelPluginPtr> plugins;
461 
463  private: std::map<std::string, common::NumericAnimationPtr>
464  jointAnimations;
465 
467  private: boost::function<void()> onJointAnimationComplete;
468 
470  private: mutable boost::recursive_mutex updateMutex;
471 
473  private: JointControllerPtr jointController;
474  };
476  }
477 }
478 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:100
Definition: JointMaker.hh:46
Forward declarations for the common classes.
Definition: Animation.hh:33
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:196
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
Mathematical representation of a box and related functions.
Definition: Box.hh:35
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:108
std::vector< math::Pose > attachedModelsOffset
used by Model::AttachStaticModel
Definition: Model.hh:439
std::vector< ModelPtr > attachedModels
used by Model::AttachStaticModel
Definition: Model.hh:436
default namespace for gazebo
A model is a collection of links, joints, and plugins.
Definition: Model.hh:53
transport::PublisherPtr jointPub
Publisher for joint info.
Definition: Model.hh:442
boost::shared_ptr< Gripper > GripperPtr
Definition: PhysicsTypes.hh:188
std::vector< JointPtr > Joint_V
Definition: PhysicsTypes.hh:204
#define NULL
Definition: CommonTypes.hh:31
Base class for all physics objects in Gazebo.
Definition: Entity.hh:58
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:80
boost::shared_ptr< JointController > JointControllerPtr
Definition: PhysicsTypes.hh:112
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:88
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Store state information of a physics::Model object.
Definition: ModelState.hh:48
std::vector< LinkPtr > Link_V
Definition: PhysicsTypes.hh:216
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:72