##

PhysicsEngine.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 _PHYSICSENGINE_HH_
#define _PHYSICSENGINE_HH_
#include <boost/thread/recursive_mutex.hpp>
#include <string>
#include <ignition/transport/Node.hh>
#include "gazebo/transport/TransportTypes.hh"
#include "gazebo/msgs/msgs.hh"
#include "gazebo/physics/PhysicsTypes.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace physics
{
class ContactManager;
class GZ_PHYSICS_VISIBLE PhysicsEngine
{
public: explicit PhysicsEngine(WorldPtr _world);
public: virtual ~PhysicsEngine();
public: virtual void Load(sdf::ElementPtr _sdf);
public: virtual void Init() = 0;
public: virtual void Fini();
public: virtual void Reset() {}
public: virtual void InitForThread() = 0;
public: virtual void UpdateCollision() = 0;
public: virtual std::string GetType() const = 0;
public: virtual void SetSeed(uint32_t _seed) = 0;
public: double GetUpdatePeriod();
public: double GetTargetRealTimeFactor() const;
public: double GetRealTimeUpdateRate() const;
public: double GetMaxStepSize() const;
public: void SetTargetRealTimeFactor(double _factor);
public: void SetRealTimeUpdateRate(double _rate);
public: void SetMaxStepSize(double _stepSize);
public: virtual void UpdatePhysics() {}
public: virtual ModelPtr CreateModel(BasePtr _base);
public: virtual LinkPtr CreateLink(ModelPtr _parent) = 0;
public: virtual CollisionPtr CreateCollision(
const std::string &_shapeType, LinkPtr _link) = 0;
public: CollisionPtr CreateCollision(const std::string &_shapeType,
const std::string &_linkName);
public: virtual ShapePtr CreateShape(const std::string &_shapeType,
CollisionPtr _collision) = 0;
public: virtual JointPtr CreateJoint(const std::string &_type,
ModelPtr _parent = ModelPtr()) = 0;
public: virtual void SetGravity(
const ignition::math::Vector3d &_gravity) = 0;
public: virtual void SetAutoDisableFlag(bool _autoDisable);
public: virtual void SetMaxContacts(unsigned int _maxContacts);
public: virtual bool GetAutoDisableFlag() {return 0;}
public: virtual bool SetParam(const std::string &_key,
const boost::any &_value);
public: virtual boost::any GetParam(const std::string &_key) const;
public: virtual bool GetParam(const std::string &_key,
boost::any &_value) const;
public: virtual void DebugPrint() const = 0;
public: WorldPtr World() const;
public: ContactManager *GetContactManager() const;
public: boost::recursive_mutex *GetPhysicsUpdateMutex() const
{return this->physicsUpdateMutex;}
public: sdf::ElementPtr GetSDF() const;
protected: virtual void OnRequest(ConstRequestPtr &_msg);
protected: virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg);
protected: WorldPtr world;
protected: sdf::ElementPtr sdf;
protected: transport::NodePtr node;
protected: transport::PublisherPtr responsePub;
protected: transport::SubscriberPtr physicsSub;
protected: transport::SubscriberPtr requestSub;
protected: boost::recursive_mutex *physicsUpdateMutex;
protected: ContactManager *contactManager;
protected: double realTimeUpdateRate;
protected: double targetRealTimeFactor;
protected: double maxStepSize;
// Place ignition::transport objects at the end of this file to
// guarantee they are destructed first.
protected: ignition::transport::Node nodeIgn;
protected: ignition::transport::Node::Publisher responsePubIgn;
};
}
}
#endif
gazebo::physics::PhysicsEngine::UpdatePhysics
virtual void UpdatePhysics()
Update the physics engine.
Definition: PhysicsEngine.hh:131
gazebo::physics::PhysicsEngine::SetGravity
virtual void SetGravity(const ignition::math::Vector3d &_gravity)=0
Set the gravity vector.
gazebo::physics::PhysicsEngine::GetType
virtual std::string GetType() const =0
Return the physics engine type (ode|bullet|dart|simbody).
gazebo::physics::PhysicsEngine::SetSeed
virtual void SetSeed(uint32_t _seed)=0
Set the random number seed for the physics engine.
gazebo::physics::PhysicsEngine::GetAutoDisableFlag
virtual bool GetAutoDisableFlag()
\TODO: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:187
gazebo::physics::PhysicsEngine::SetRealTimeUpdateRate
void SetRealTimeUpdateRate(double _rate)
Set real time update rate.
gazebo::physics::PhysicsEngine
Base class for a physics engine.
Definition: PhysicsEngine.hh:41
gazebo::physics::PhysicsEngine::Init
virtual void Init()=0
Initialize the physics engine.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::physics::PhysicsEngine::Fini
virtual void Fini()
Finilize the physics engine.
gazebo::physics::ModelPtr
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
gazebo::transport::PublisherPtr
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
gazebo::physics::PhysicsEngine::UpdateCollision
virtual void UpdateCollision()=0
Update the physics engine collision.
gazebo::physics::PhysicsEngine::CreateShape
virtual ShapePtr CreateShape(const std::string &_shapeType, CollisionPtr _collision)=0
Create a physics::Shape object.
TransportTypes.hh
Forward declarations for transport.
gazebo::physics::PhysicsEngine::GetUpdatePeriod
double GetUpdatePeriod()
Get the simulation update period.
gazebo::physics::PhysicsEngine::CreateJoint
virtual JointPtr CreateJoint(const std::string &_type, ModelPtr _parent=ModelPtr())=0
Create a new joint.
gazebo::physics::PhysicsEngine::SetTargetRealTimeFactor
void SetTargetRealTimeFactor(double _factor)
Set target real time factor.
system.hh
gazebo::physics::PhysicsEngine::GetSDF
sdf::ElementPtr GetSDF() const
Get a pointer to the SDF element for this physics engine.
gazebo::physics::PhysicsEngine::OnPhysicsMsg
virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg)
virtual callback for gztopic "~/physics".
gazebo::physics::PhysicsEngine::nodeIgn
ignition::transport::Node nodeIgn
Ignition node for communication.
Definition: PhysicsEngine.hh:303
msgs.hh
gazebo::physics::PhysicsEngine::SetMaxStepSize
void SetMaxStepSize(double _stepSize)
Set max step size.
gazebo::transport::SubscriberPtr
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
PhysicsTypes.hh
default namespace for gazebo
gazebo::transport::NodePtr
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
gazebo::physics::PhysicsEngine::GetParam
virtual boost::any GetParam(const std::string &_key) const
Get an parameter of the physics engine.
gazebo::physics::PhysicsEngine::PhysicsEngine
PhysicsEngine(WorldPtr _world)
Default constructor.
gazebo::physics::PhysicsEngine::sdf
sdf::ElementPtr sdf
Our SDF values.
Definition: PhysicsEngine.hh:269
gazebo::physics::PhysicsEngine::InitForThread
virtual void InitForThread()=0
Init the engine for threads.
gazebo::physics::PhysicsEngine::responsePub
transport::PublisherPtr responsePub
Response publisher.
Definition: PhysicsEngine.hh:275
gazebo::physics::PhysicsEngine::DebugPrint
virtual void DebugPrint() const =0
Debug print out of the physic engine state.
gazebo::physics::PhysicsEngine::responsePubIgn
ignition::transport::Node::Publisher responsePubIgn
Response publisher.
Definition: PhysicsEngine.hh:306
gazebo::physics::PhysicsEngine::CreateLink
virtual LinkPtr CreateLink(ModelPtr _parent)=0
Create a new body.
gazebo::physics::PhysicsEngine::world
WorldPtr world
Pointer to the world.
Definition: PhysicsEngine.hh:266
gazebo::physics::PhysicsEngine::maxStepSize
double maxStepSize
Real time update rate.
Definition: PhysicsEngine.hh:297
gazebo::physics::World
The world provides access to all other object within a simulated environment.
Definition: World.hh:74
gazebo::physics::PhysicsEngine::SetAutoDisableFlag
virtual void SetAutoDisableFlag(bool _autoDisable)
\TODO: Remove this function, and replace it with a more generic property map
gazebo::physics::PhysicsEngine::GetContactManager
ContactManager * GetContactManager() const
Get a pointer to the contact manger.
gazebo::physics::PhysicsEngine::physicsSub
transport::SubscriberPtr physicsSub
Subscribe to the physics topic.
Definition: PhysicsEngine.hh:278
gazebo::physics::ShapePtr
boost::shared_ptr< Shape > ShapePtr
Definition: PhysicsTypes.hh:141
gazebo::physics::BasePtr
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
gazebo::physics::PhysicsEngine::requestSub
transport::SubscriberPtr requestSub
Subscribe to the request topic.
Definition: PhysicsEngine.hh:281
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::physics::ContactManager
Aggregates all the contact information generated by the collision detection engine.
Definition: ContactManager.hh:72
gazebo::physics::LinkPtr
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
gazebo::physics::PhysicsEngine::GetRealTimeUpdateRate
double GetRealTimeUpdateRate() const
Get real time update rate.
gazebo::physics::PhysicsEngine::World
WorldPtr World() const
Get a pointer to the world.
gazebo::physics::PhysicsEngine::Reset
virtual void Reset()
Rest the physics engine.
Definition: PhysicsEngine.hh:61
gazebo::physics::JointPtr
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
gazebo::physics::PhysicsEngine::OnRequest
virtual void OnRequest(ConstRequestPtr &_msg)
virtual callback for gztopic "~/request".
gazebo::physics::PhysicsEngine::SetParam
virtual bool SetParam(const std::string &_key, const boost::any &_value)
Set a parameter of the physics engine.
gazebo::physics::PhysicsEngine::GetMaxStepSize
double GetMaxStepSize() const
Get max step size.
gazebo::physics::CollisionPtr
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
gazebo::physics::PhysicsEngine::CreateCollision
virtual CollisionPtr CreateCollision(const std::string &_shapeType, LinkPtr _link)=0
Create a collision.
gazebo::physics::PhysicsEngine::contactManager
ContactManager * contactManager
Class that handles all contacts generated by the physics engine.
Definition: PhysicsEngine.hh:288
gazebo::physics::PhysicsEngine::GetTargetRealTimeFactor
double GetTargetRealTimeFactor() const
Get target real time factor.
gazebo::physics::PhysicsEngine::physicsUpdateMutex
boost::recursive_mutex * physicsUpdateMutex
Mutex to protect the update cycle.
Definition: PhysicsEngine.hh:284
gazebo::physics::WorldPtr
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
gazebo::physics::PhysicsEngine::~PhysicsEngine
virtual ~PhysicsEngine()
Destructor.
gazebo::physics::PhysicsEngine::CreateModel
virtual ModelPtr CreateModel(BasePtr _base)
Create a new model.
gazebo::physics::PhysicsEngine::SetMaxContacts
virtual void SetMaxContacts(unsigned int _maxContacts)
\TODO: Remove this function, and replace it with a more generic property map
gazebo::physics::PhysicsEngine::realTimeUpdateRate
double realTimeUpdateRate
Real time update rate.
Definition: PhysicsEngine.hh:291
gazebo::physics::PhysicsEngine::GetPhysicsUpdateMutex
boost::recursive_mutex * GetPhysicsUpdateMutex() const
returns a pointer to the PhysicsEngine::physicsUpdateMutex.
Definition: PhysicsEngine.hh:250
gazebo::physics::PhysicsEngine::node
transport::NodePtr node
Node for communication.
Definition: PhysicsEngine.hh:272
gazebo::physics::PhysicsEngine::targetRealTimeFactor
double targetRealTimeFactor
Target real time factor.
Definition: PhysicsEngine.hh:294
gazebo::physics::PhysicsEngine::Load
virtual void Load(sdf::ElementPtr _sdf)
Load the physics engine.