Model.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 #ifndef GAZEBO_PHYSICS_MODEL_HH_
18 #define GAZEBO_PHYSICS_MODEL_HH_
19 
20 #include <string>
21 #include <map>
22 #include <mutex>
23 #include <vector>
24 #include <boost/function.hpp>
25 #include <boost/thread/recursive_mutex.hpp>
26 
30 #include "gazebo/physics/Entity.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace boost
35 {
36  class recursive_mutex;
37 }
38 
39 // Forward declare reference and pointer parameters
40 namespace ignition
41 {
42  namespace msgs
43  {
44  class Plugin_V;
45  }
46 }
47 
48 namespace gazebo
49 {
50  namespace physics
51  {
52  class Gripper;
53 
56 
59  class GZ_PHYSICS_VISIBLE Model : public Entity
60  {
63  public: explicit Model(BasePtr _parent);
64 
66  public: virtual ~Model();
67 
70  public: void Load(sdf::ElementPtr _sdf);
71 
73  public: void LoadJoints();
74 
76  public: virtual void Init();
77 
79  public: void Update();
80 
82  public: virtual void Fini();
83 
86  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
87 
90  public: virtual const sdf::ElementPtr GetSDF();
91 
97  public: virtual const sdf::ElementPtr UnscaledSDF();
98 
101  public: virtual void RemoveChild(EntityPtr _child);
102  using Base::RemoveChild;
103 
105  public: void Reset();
106  using Entity::Reset;
107 
110  public: void ResetPhysicsStates();
111 
114  public: void SetLinearVel(const ignition::math::Vector3d &_vel);
115 
118  public: void SetAngularVel(const ignition::math::Vector3d &_vel);
119 
124  public: void SetLinearAccel(const ignition::math::Vector3d &_vel)
125  GAZEBO_DEPRECATED(9.0);
126 
131  public: void SetAngularAccel(const ignition::math::Vector3d &_vel)
132  GAZEBO_DEPRECATED(9.0);
133 
137  public: virtual ignition::math::Vector3d RelativeLinearVel() const;
138 
142  public: virtual ignition::math::Vector3d WorldLinearVel() const;
143 
147  public: virtual ignition::math::Vector3d RelativeAngularVel() const;
148 
152  public: virtual ignition::math::Vector3d WorldAngularVel() const;
153 
157  public: virtual ignition::math::Vector3d RelativeLinearAccel() const;
158 
162  public: virtual ignition::math::Vector3d WorldLinearAccel() const;
163 
167  public: virtual ignition::math::Vector3d RelativeAngularAccel() const;
168 
172  public: virtual ignition::math::Vector3d WorldAngularAccel() const;
173 
176  public: virtual ignition::math::Box BoundingBox() const;
177 
180  public: unsigned int GetJointCount() const;
181 
185  public: ModelPtr NestedModel(const std::string &_name) const;
186 
189  public: const Model_V &NestedModels() const;
190 
194  public: const Link_V &GetLinks() const;
195 
198  public: const Joint_V &GetJoints() const;
199 
203  public: JointPtr GetJoint(const std::string &name);
204 
209  public: LinkPtr GetLinkById(unsigned int _id) const;
211 
215  public: LinkPtr GetLink(const std::string &_name ="canonical") const;
216 
224  public: virtual bool GetSelfCollide() const;
225 
229  public: virtual void SetSelfCollide(bool _self_collide);
230 
233  public: void SetGravityMode(const bool &_value);
234 
239  public: void SetCollideMode(const std::string &_mode);
240 
243  public: void SetLaserRetro(const float _retro);
244 
247  public: virtual void FillMsg(msgs::Model &_msg);
248 
251  public: void ProcessMsg(const msgs::Model &_msg);
252 
257  public: void SetJointPosition(const std::string &_jointName,
258  double _position, int _index = 0);
259 
263  public: void SetJointPositions(
264  const std::map<std::string, double> &_jointPositions);
265 
270  public: void SetJointAnimation(
271  const std::map<std::string, common::NumericAnimationPtr> &_anims,
272  boost::function<void()> _onComplete = NULL);
273 
275  public: virtual void StopAnimation();
276 
291  public: void AttachStaticModel(ModelPtr &_model,
292  ignition::math::Pose3d _offset);
293 
297  public: void DetachStaticModel(const std::string &_model);
298 
301  public: void SetState(const ModelState &_state);
302 
308  public: void SetScale(const ignition::math::Vector3d &_scale,
309  const bool _publish = false);
310 
315  public: ignition::math::Vector3d Scale() const;
316 
319  public: void SetEnabled(bool _enabled);
320 
327  public: void SetLinkWorldPose(const ignition::math::Pose3d &_pose,
328  std::string _linkName);
329 
336  public: void SetLinkWorldPose(const ignition::math::Pose3d &_pose,
337  const LinkPtr &_link);
338 
342  public: void SetAutoDisable(bool _disable);
343 
346  public: bool GetAutoDisable() const;
347 
351  public: void LoadPlugins();
352 
355  public: unsigned int GetPluginCount() const;
356 
360  public: unsigned int GetSensorCount() const;
361 
374  public: std::vector<std::string> SensorScopedName(
375  const std::string &_name) const;
376 
379  public: JointControllerPtr GetJointController();
380 
383  public: GripperPtr GetGripper(size_t _index) const;
384 
388  public: size_t GetGripperCount() const;
389 
393  public: double GetWorldEnergyPotential() const;
394 
399  public: double GetWorldEnergyKinetic() const;
400 
405  public: double GetWorldEnergy() const;
406 
416  public: gazebo::physics::JointPtr CreateJoint(
417  const std::string &_name, const std::string &_type,
418  physics::LinkPtr _parent, physics::LinkPtr _child);
419 
426  public: gazebo::physics::JointPtr CreateJoint(sdf::ElementPtr _sdf);
427 
431  public: bool RemoveJoint(const std::string &_name);
432 
435  public: virtual void SetWindMode(const bool _mode);
436 
439  public: virtual bool WindMode() const;
440 
443  public: boost::shared_ptr<Model> shared_from_this();
444 
449  public: LinkPtr CreateLink(const std::string &_name);
450 
468  public: void PluginInfo(const common::URI &_pluginUri,
469  ignition::msgs::Plugin_V &_plugins, bool &_success);
470 
472  protected: virtual void OnPoseChange();
473 
475  protected: virtual void RegisterIntrospectionItems();
476 
478  private: void LoadLinks();
479 
481  private: void LoadModels();
482 
485  private: void LoadJoint(sdf::ElementPtr _sdf);
486 
489  private: void LoadPlugin(sdf::ElementPtr _sdf);
490 
493  private: void LoadGripper(sdf::ElementPtr _sdf);
494 
498  private: void RemoveLink(const std::string &_name);
499 
501  private: virtual void PublishScale();
502 
504  protected: std::vector<ModelPtr> attachedModels;
505 
507  protected: std::vector<ignition::math::Pose3d> attachedModelsOffset;
508 
511 
513  private: LinkPtr canonicalLink;
514 
516  private: Joint_V joints;
517 
519  private: Link_V links;
520 
522  private: Model_V models;
523 
525  private: std::vector<GripperPtr> grippers;
526 
528  private: std::vector<ModelPluginPtr> plugins;
529 
531  private: std::map<std::string, common::NumericAnimationPtr>
532  jointAnimations;
533 
535  private: boost::function<void()> onJointAnimationComplete;
536 
538  private: JointControllerPtr jointController;
539 
541  private: mutable boost::recursive_mutex updateMutex;
542 
544  private: std::mutex receiveMutex;
545  };
547  }
548 }
549 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:205
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
std::vector< ignition::math::Pose3d > attachedModelsOffset
used by Model::AttachStaticModel
Definition: Model.hh:507
virtual void RemoveChild(unsigned int _id)
Remove a child from this entity.
std::vector< ModelPtr > attachedModels
used by Model::AttachStaticModel
Definition: Model.hh:504
default namespace for gazebo
A complete URI.
Definition: URI.hh:176
A model is a collection of links, joints, and plugins.
Definition: Model.hh:59
transport::PublisherPtr jointPub
Publisher for joint info.
Definition: Model.hh:510
boost::shared_ptr< Gripper > GripperPtr
Definition: PhysicsTypes.hh:197
std::vector< JointPtr > Joint_V
Definition: PhysicsTypes.hh:213
#define NULL
Definition: CommonTypes.hh:31
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:85
boost::shared_ptr< JointController > JointControllerPtr
Definition: PhysicsTypes.hh:121
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
virtual void Reset()
Reset the entity.
Store state information of a physics::Model object.
Definition: ModelState.hh:48
std::vector< LinkPtr > Link_V
Definition: PhysicsTypes.hh:225
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77