##

Model.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_PHYSICS_MODEL_HH_
#define GAZEBO_PHYSICS_MODEL_HH_
#include <string>
#include <map>
#include <mutex>
#include <vector>
#include <boost/function.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include "gazebo/common/CommonTypes.hh"
#include "gazebo/physics/PhysicsTypes.hh"
#include "gazebo/physics/ModelState.hh"
#include "gazebo/physics/Entity.hh"
#include "gazebo/transport/TransportTypes.hh"
#include "gazebo/util/system.hh"
namespace boost
{
class recursive_mutex;
}
// Forward declare reference and pointer parameters
namespace ignition
{
namespace msgs
{
class Plugin_V;
}
}
namespace gazebo
{
namespace physics
{
class Gripper;
class GZ_PHYSICS_VISIBLE Model : public Entity
{
public: explicit Model(BasePtr _parent);
public: virtual ~Model();
public: void Load(sdf::ElementPtr _sdf);
public: void LoadJoints();
public: virtual void Init();
public: void Update();
public: virtual void Fini();
public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
public: virtual const sdf::ElementPtr GetSDF();
public: virtual const sdf::ElementPtr UnscaledSDF();
public: virtual void RemoveChild(EntityPtr _child);
using Base::RemoveChild;
public: void Reset();
using Entity::Reset;
public: void ResetPhysicsStates();
public: void SetLinearVel(const ignition::math::Vector3d &_vel);
public: void SetAngularVel(const ignition::math::Vector3d &_vel);
public: void SetLinearAccel(const ignition::math::Vector3d &_vel)
GAZEBO_DEPRECATED(9.0);
public: void SetAngularAccel(const ignition::math::Vector3d &_vel)
GAZEBO_DEPRECATED(9.0);
public: virtual ignition::math::Vector3d RelativeLinearVel() const;
public: virtual ignition::math::Vector3d WorldLinearVel() const;
public: virtual ignition::math::Vector3d RelativeAngularVel() const;
public: virtual ignition::math::Vector3d WorldAngularVel() const;
public: virtual ignition::math::Vector3d RelativeLinearAccel() const;
public: virtual ignition::math::Vector3d WorldLinearAccel() const;
public: virtual ignition::math::Vector3d RelativeAngularAccel() const;
public: virtual ignition::math::Vector3d WorldAngularAccel() const;
public: virtual ignition::math::Box BoundingBox() const;
public: unsigned int GetJointCount() const;
public: ModelPtr NestedModel(const std::string &_name) const;
public: const Model_V &NestedModels() const;
public: const Link_V &GetLinks() const;
public: const Joint_V &GetJoints() const;
public: JointPtr GetJoint(const std::string &name);
public: LinkPtr GetLinkById(unsigned int _id) const;
public: LinkPtr GetLink(const std::string &_name ="canonical") const;
public: virtual bool GetSelfCollide() const;
public: virtual void SetSelfCollide(bool _self_collide);
public: void SetGravityMode(const bool &_value);
public: void SetCollideMode(const std::string &_mode);
public: void SetLaserRetro(const float _retro);
public: virtual void FillMsg(msgs::Model &_msg);
public: void ProcessMsg(const msgs::Model &_msg);
public: void SetJointPosition(const std::string &_jointName,
double _position, int _index = 0);
public: void SetJointPositions(
const std::map<std::string, double> &_jointPositions);
public: void SetJointAnimation(
const std::map<std::string, common::NumericAnimationPtr> &_anims,
boost::function<void()> _onComplete = NULL);
public: virtual void StopAnimation();
public: void AttachStaticModel(ModelPtr &_model,
ignition::math::Pose3d _offset);
public: void DetachStaticModel(const std::string &_model);
public: void SetState(const ModelState &_state);
public: void SetScale(const ignition::math::Vector3d &_scale,
const bool _publish = false);
public: ignition::math::Vector3d Scale() const;
public: void SetEnabled(bool _enabled);
public: void SetLinkWorldPose(const ignition::math::Pose3d &_pose,
std::string _linkName);
public: void SetLinkWorldPose(const ignition::math::Pose3d &_pose,
const LinkPtr &_link);
public: void SetAutoDisable(bool _disable);
public: bool GetAutoDisable() const;
public: void LoadPlugins();
public: unsigned int GetPluginCount() const;
public: unsigned int GetSensorCount() const;
public: std::vector<std::string> SensorScopedName(
const std::string &_name) const;
public: JointControllerPtr GetJointController();
public: GripperPtr GetGripper(size_t _index) const;
public: size_t GetGripperCount() const;
public: double GetWorldEnergyPotential() const;
public: double GetWorldEnergyKinetic() const;
public: double GetWorldEnergy() const;
public: gazebo::physics::JointPtr CreateJoint(
const std::string &_name, const std::string &_type,
physics::LinkPtr _parent, physics::LinkPtr _child);
public: gazebo::physics::JointPtr CreateJoint(sdf::ElementPtr _sdf);
public: bool RemoveJoint(const std::string &_name);
public: virtual void SetWindMode(const bool _mode);
public: virtual bool WindMode() const;
public: boost::shared_ptr<Model> shared_from_this();
public: LinkPtr CreateLink(const std::string &_name);
public: void PluginInfo(const common::URI &_pluginUri,
ignition::msgs::Plugin_V &_plugins, bool &_success);
protected: virtual void OnPoseChange();
protected: virtual void RegisterIntrospectionItems();
private: void LoadLinks();
private: void LoadModels();
private: void LoadJoint(sdf::ElementPtr _sdf);
private: void LoadPlugin(sdf::ElementPtr _sdf);
private: void LoadGripper(sdf::ElementPtr _sdf);
private: void RemoveLink(const std::string &_name);
private: virtual void PublishScale();
protected: std::vector<ModelPtr> attachedModels;
protected: std::vector<ignition::math::Pose3d> attachedModelsOffset;
protected: transport::PublisherPtr jointPub;
private: LinkPtr canonicalLink;
private: Joint_V joints;
private: Link_V links;
private: Model_V models;
private: std::vector<GripperPtr> grippers;
private: std::vector<ModelPluginPtr> plugins;
private: std::map<std::string, common::NumericAnimationPtr>
jointAnimations;
private: boost::function<void()> onJointAnimationComplete;
private: JointControllerPtr jointController;
private: mutable boost::recursive_mutex updateMutex;
private: std::mutex receiveMutex;
};
}
}
#endif
gazebo::physics::Joint_V
std::vector< JointPtr > Joint_V
Definition: PhysicsTypes.hh:213
gazebo::physics::Model::Load
void Load(sdf::ElementPtr _sdf)
Load the model.
gazebo::common::URI
A complete URI.
Definition: URI.hh:176
gazebo::physics::Model::LoadJoints
void LoadJoints()
Load all the joints.
gazebo::physics::Model::GetWorldEnergyPotential
double GetWorldEnergyPotential() const
Returns the potential energy of all links and joint springs in the model.
gazebo::physics::Model::SetLinkWorldPose
void SetLinkWorldPose(const ignition::math::Pose3d &_pose, std::string _linkName)
Set the Pose of the entire Model by specifying desired Pose of a Link within the Model.
ignition
Definition: Model.hh:40
gazebo::physics::Model::RelativeAngularAccel
virtual ignition::math::Vector3d RelativeAngularAccel() const
Get the angular acceleration of the entity.
gazebo::physics::Model::AttachStaticModel
void AttachStaticModel(ModelPtr &_model, ignition::math::Pose3d _offset)
Attach a static model to this model.
gazebo::physics::Model::~Model
virtual ~Model()
Destructor.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::physics::JointControllerPtr
boost::shared_ptr< JointController > JointControllerPtr
Definition: PhysicsTypes.hh:121
gazebo::physics::Model::GetSelfCollide
virtual bool GetSelfCollide() const
If true, all links within the model will collide by default.
gazebo::physics::Model::Model
Model(BasePtr _parent)
Constructor.
gazebo::physics::Model::SetLinearAccel
void SetLinearAccel(const ignition::math::Vector3d &_vel) GAZEBO_DEPRECATED(9.0)
Set the linear acceleration of the model, and all its links.
gazebo::physics::ModelPtr
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
NULL
#define NULL
Definition: CommonTypes.hh:31
gazebo::physics::Model_V
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:205
gazebo::physics::Model::RelativeAngularVel
virtual ignition::math::Vector3d RelativeAngularVel() const
Get the angular velocity of the entity.
gazebo::physics::Model::GetSDF
virtual const sdf::ElementPtr GetSDF()
Get the SDF values for the model.
gazebo::physics::Model::SetCollideMode
void SetCollideMode(const std::string &_mode)
\TODO This is not implemented in Link, which means this function doesn't do anything.
gazebo::physics::Model::StopAnimation
virtual void StopAnimation()
Stop the current animations.
gazebo::physics::Model::CreateJoint
gazebo::physics::JointPtr CreateJoint(const std::string &_name, const std::string &_type, physics::LinkPtr _parent, physics::LinkPtr _child)
Create a joint for this model.
gazebo::transport::PublisherPtr
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
gazebo::physics::Model::Fini
virtual void Fini()
Finalize the model.
gazebo::physics::Model::WorldLinearVel
virtual ignition::math::Vector3d WorldLinearVel() const
Get the linear velocity of the entity in the world frame.
gazebo::physics::Model::WindMode
virtual bool WindMode() const
Get the wind mode.
ModelState.hh
TransportTypes.hh
Forward declarations for transport.
gazebo::physics::Model::SetJointAnimation
void SetJointAnimation(const std::map< std::string, common::NumericAnimationPtr > &_anims, boost::function< void()> _onComplete=NULL)
Joint Animation.
boost
Definition: JointMaker.hh:44
system.hh
gazebo::physics::Model::GetGripperCount
size_t GetGripperCount() const
Get the number of grippers in this model.
gazebo::physics::Model::SetWindMode
virtual void SetWindMode(const bool _mode)
Set whether wind affects this body.
gazebo::physics::Model::SetLaserRetro
void SetLaserRetro(const float _retro)
Set the laser retro reflectiveness of the model.
gazebo::physics::Model::GetWorldEnergyKinetic
double GetWorldEnergyKinetic() const
Returns sum of the kinetic energies of all links in this model.
gazebo::physics::Model::GetPluginCount
unsigned int GetPluginCount() const
Get the number of plugins this model has.
CommonTypes.hh
gazebo::physics::Model::WorldAngularVel
virtual ignition::math::Vector3d WorldAngularVel() const
Get the angular velocity of the entity in the world frame.
gazebo::physics::Model::UpdateParameters
virtual void UpdateParameters(sdf::ElementPtr _sdf)
Update the parameters using new sdf values.
gazebo::physics::Entity::Reset
virtual void Reset()
Reset the entity.
PhysicsTypes.hh
default namespace for gazebo
gazebo::physics::Model::GetSensorCount
unsigned int GetSensorCount() const
Get the number of sensors attached to this model.
gazebo::physics::Model::Init
virtual void Init()
Initialize the model.
gazebo::physics::Model::Update
void Update()
Update the model.
gazebo::physics::Model::GetLink
LinkPtr GetLink(const std::string &_name="canonical") const
Get a link by name.
gazebo::physics::Model::GetJoint
JointPtr GetJoint(const std::string &name)
Get a joint.
gazebo::physics::Model::GetWorldEnergy
double GetWorldEnergy() const
Returns this model's total energy, or sum of Model::GetWorldEnergyPotential() and Model::GetWorldEner...
gazebo::physics::Model::SetJointPositions
void SetJointPositions(const std::map< std::string, double > &_jointPositions)
Set the positions of a set of joints.
gazebo::physics::Model::SetAngularAccel
void SetAngularAccel(const ignition::math::Vector3d &_vel) GAZEBO_DEPRECATED(9.0)
Set the angular acceleration of the model, and all its links.
gazebo::physics::Model::SetAngularVel
void SetAngularVel(const ignition::math::Vector3d &_vel)
Set the angular velocity of the model, and all its links.
gazebo::physics::Model::SensorScopedName
std::vector< std::string > SensorScopedName(const std::string &_name) const
Get scoped sensor name(s) in the model that matches sensor name.
gazebo::physics::Model::GetGripper
GripperPtr GetGripper(size_t _index) const
Get a gripper based on an index.
gazebo::physics::Model::OnPoseChange
virtual void OnPoseChange()
Callback when the pose of the model has been changed.
Entity.hh
gazebo::physics::Model::RelativeLinearVel
virtual ignition::math::Vector3d RelativeLinearVel() const
Get the linear velocity of the entity.
gazebo::physics::Model::shared_from_this
boost::shared_ptr< Model > shared_from_this()
Allow Model class to share itself as a boost shared_ptr.
gazebo::physics::Model::Reset
void Reset()
Reset the model.
gazebo::physics::Model::GetJointController
JointControllerPtr GetJointController()
Get a handle to the Controller for the joints in this model.
gazebo::physics::Base::RemoveChild
virtual void RemoveChild(unsigned int _id)
Remove a child from this entity.
gazebo::physics::Model::FillMsg
virtual void FillMsg(msgs::Model &_msg)
Fill a model message.
gazebo::physics::Model::RelativeLinearAccel
virtual ignition::math::Vector3d RelativeLinearAccel() const
Get the linear acceleration of the entity.
gazebo::physics::Model::ResetPhysicsStates
void ResetPhysicsStates()
Reset the velocity, acceleration, force and torque of all child links.
gazebo::physics::Model
A model is a collection of links, joints, and plugins.
Definition: Model.hh:59
gazebo::physics::ModelState
Store state information of a physics::Model object.
Definition: ModelState.hh:48
gazebo::physics::Model::GetJointCount
unsigned int GetJointCount() const
Get the number of joints.
gazebo::physics::BasePtr
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
gazebo::physics::Model::CreateLink
LinkPtr CreateLink(const std::string &_name)
Create a new link for this model.
gazebo::physics::Model::SetGravityMode
void SetGravityMode(const bool &_value)
Set the gravity mode of the model.
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::physics::Model::BoundingBox
virtual ignition::math::Box BoundingBox() const
Get the size of the bounding box.
gazebo::physics::LinkPtr
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
gazebo::physics::Model::SetAutoDisable
void SetAutoDisable(bool _disable)
Allow the model the auto disable.
gazebo::physics::Model::Scale
ignition::math::Vector3d Scale() const
Get the scale of model.
gazebo::physics::Model::attachedModels
std::vector< ModelPtr > attachedModels
used by Model::AttachStaticModel
Definition: Model.hh:510
gazebo::physics::Model::NestedModel
ModelPtr NestedModel(const std::string &_name) const
Get a nested model that is a direct child of this model.
gazebo::physics::Model::LoadPlugins
void LoadPlugins()
Load all plugins.
gazebo::physics::Model::SetJointPosition
void SetJointPosition(const std::string &_jointName, double _position, int _index=0)
Set the positions of a Joint by name.
gazebo::physics::EntityPtr
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:85
gazebo::physics::JointPtr
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
gazebo::physics::Entity
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
gazebo::physics::Model::GetAutoDisable
bool GetAutoDisable() const
Return the value of the SDF <allow_auto_disable> element.
gazebo::physics::Model::SetState
void SetState(const ModelState &_state)
Set the current model state.
GAZEBO_DEPRECATED
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
gazebo::physics::Model::attachedModelsOffset
std::vector< ignition::math::Pose3d > attachedModelsOffset
used by Model::AttachStaticModel
Definition: Model.hh:513
gazebo::physics::Link_V
std::vector< LinkPtr > Link_V
Definition: PhysicsTypes.hh:225
gazebo::physics::Model::WorldAngularAccel
virtual ignition::math::Vector3d WorldAngularAccel() const
Get the angular acceleration of the entity in the world frame.
gazebo::physics::Model::UnscaledSDF
virtual const sdf::ElementPtr UnscaledSDF()
gazebo::physics::Model::WorldLinearAccel
virtual ignition::math::Vector3d WorldLinearAccel() const
Get the linear acceleration of the entity in the world frame.
gazebo::physics::Model::SetEnabled
void SetEnabled(bool _enabled)
Enable all the links in all the models.
gazebo::physics::Model::SetSelfCollide
virtual void SetSelfCollide(bool _self_collide)
Set this model's self_collide property.
gazebo::physics::GripperPtr
boost::shared_ptr< Gripper > GripperPtr
Definition: PhysicsTypes.hh:197
gazebo::physics::Model::RemoveChild
virtual void RemoveChild(EntityPtr _child)
Remove a child.
gazebo::physics::Model::GetLinks
const Link_V & GetLinks() const
Construct and return a vector of Link's in this model Note this constructs the vector of Link's on th...
gazebo::physics::Model::GetJoints
const Joint_V & GetJoints() const
Get the joints.
gazebo::physics::Model::SetLinearVel
void SetLinearVel(const ignition::math::Vector3d &_vel)
Set the linear velocity of the model, and all its links.
gazebo::physics::Model::RemoveJoint
bool RemoveJoint(const std::string &_name)
Remove a joint for this model.
gazebo::physics::Model::RegisterIntrospectionItems
virtual void RegisterIntrospectionItems()
Register items in the introspection service.
gazebo::physics::Model::SetScale
void SetScale(const ignition::math::Vector3d &_scale, const bool _publish=false)
Set the scale of model.
gazebo::physics::Model::DetachStaticModel
void DetachStaticModel(const std::string &_model)
Detach a static model from this model.
gazebo::physics::Model::jointPub
transport::PublisherPtr jointPub
Publisher for joint info.
Definition: Model.hh:516
gazebo::physics::Model::PluginInfo
void PluginInfo(const common::URI &_pluginUri, ignition::msgs::Plugin_V &_plugins, bool &_success)
Get information about plugins in this model or one of its children, according to the given _pluginUri...
gazebo::physics::Model::NestedModels
const Model_V & NestedModels() const
Get all the nested models.
gazebo::physics::Model::ProcessMsg
void ProcessMsg(const msgs::Model &_msg)
Update parameters from a model message.