##

World.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_WORLD_HH_
#define GAZEBO_PHYSICS_WORLD_HH_
#include <vector>
#include <list>
#include <set>
#include <deque>
#include <string>
#include <memory>
#include <boost/enable_shared_from_this.hpp>
#include <sdf/sdf.hh>
#include "gazebo/transport/TransportTypes.hh"
#include "gazebo/msgs/msgs.hh"
#include "gazebo/common/CommonTypes.hh"
#include "gazebo/common/UpdateInfo.hh"
#include "gazebo/common/Event.hh"
#include "gazebo/common/URI.hh"
#include "gazebo/physics/Base.hh"
#include "gazebo/physics/PhysicsTypes.hh"
#include "gazebo/physics/WorldState.hh"
#include "gazebo/physics/Wind.hh"
#include "gazebo/util/system.hh"
// Forward declare reference and pointer parameters
namespace ignition
{
namespace msgs
{
class Plugin_V;
class StringMsg;
}
}
namespace gazebo
{
namespace physics
{
class WorldPrivate;
class GZ_PHYSICS_VISIBLE World :
public boost::enable_shared_from_this<World>
{
public: explicit World(const std::string &_name = "");
public: ~World();
public: void Load(sdf::ElementPtr _sdf);
public: const sdf::ElementPtr SDF();
public: void Save(const std::string &_filename);
public: void Init();
public: void Run(const unsigned int _iterations = 0);
public: bool Running() const;
public: void Stop();
public: void Fini();
public: void Clear();
public: std::string Name() const;
public: PhysicsEnginePtr Physics() const;
public: physics::Atmosphere &Atmosphere() const;
public: PresetManagerPtr PresetMgr() const;
public: physics::Wind &Wind() const;
public: common::SphericalCoordinatesPtr SphericalCoords() const;
public: ignition::math::Vector3d Gravity() const;
public: void SetGravity(const ignition::math::Vector3d &_gravity);
public: void SetGravitySDF(const ignition::math::Vector3d &_gravity);
public: virtual ignition::math::Vector3d MagneticField() const;
public: void SetMagneticField(const ignition::math::Vector3d &_mag);
public: unsigned int ModelCount() const;
public: ModelPtr ModelByIndex(const unsigned int _index) const;
public: Model_V Models() const;
public: unsigned int LightCount() const;
public: Light_V Lights() const;
public: void ResetEntities(Base::EntityType _type = Base::BASE);
public: void ResetTime();
public: void Reset();
public: void PrintEntityTree();
public: common::Time SimTime() const;
public: void SetSimTime(const common::Time &_t);
public: common::Time PauseTime() const;
public: common::Time StartTime() const;
public: common::Time RealTime() const;
public: bool IsPaused() const;
public: void SetPaused(const bool _p);
public: BasePtr BaseByName(const std::string &_name) const;
public: ModelPtr ModelByName(const std::string &_name) const;
public: LightPtr LightByName(const std::string &_name) const;
public: EntityPtr EntityByName(const std::string &_name) const;
public: ModelPtr ModelBelowPoint(
const ignition::math::Vector3d &_pt) const;
public: EntityPtr EntityBelowPoint(
const ignition::math::Vector3d &_pt) const;
public: void SetState(const WorldState &_state);
public: void InsertModelFile(const std::string &_sdfFilename);
public: void InsertModelString(const std::string &_sdfString);
public: void InsertModelSDF(const sdf::SDF &_sdf);
public: std::string StripWorldName(const std::string &_name) const;
public: void EnableAllModels();
public: void DisableAllModels();
public: void Step(const unsigned int _steps);
public: void LoadPlugin(const std::string &_filename,
const std::string &_name,
sdf::ElementPtr _sdf);
public: void RemovePlugin(const std::string &_name);
public: std::mutex &WorldPoseMutex() const;
public: bool PhysicsEnabled() const;
public: void SetPhysicsEnabled(const bool _enable);
public: bool WindEnabled() const;
public: void SetWindEnabled(const bool _enable);
public: bool AtmosphereEnabled() const;
public: void SetAtmosphereEnabled(const bool _enable);
public: void UpdateStateSDF();
public: bool IsLoaded() const;
public: void ClearModels();
public: void PublishModelPose(physics::ModelPtr _model);
public: void PublishModelScale(physics::ModelPtr _model);
public: void PublishLightPose(const physics::LightPtr _light);
public: uint32_t Iterations() const;
public: msgs::Scene SceneMsg() const;
public: void RunBlocking(const unsigned int _iterations = 0);
public: void RemoveModel(ModelPtr _model);
public: void RemoveModel(const std::string &_name);
public: void ResetPhysicsStates();
public: void _AddDirty(Entity *_entity);
public: bool SensorsInitialized() const;
public: void _SetSensorsInitialized(const bool _init);
public: common::URI URI() const;
public: std::string UniqueModelName(const std::string &_name);
private: ModelPtr ModelById(const unsigned int _id) const;
private: void LoadPlugins();
private: void LoadEntities(sdf::ElementPtr _sdf, BasePtr _parent);
private: ModelPtr LoadModel(sdf::ElementPtr _sdf, BasePtr _parent);
public: LightPtr LoadLight(const sdf::ElementPtr &_sdf,
const BasePtr &_parent);
private: ActorPtr LoadActor(sdf::ElementPtr _sdf, BasePtr _parent);
private: RoadPtr LoadRoad(sdf::ElementPtr _sdf, BasePtr _parent);
private: void RunLoop();
private: void Step();
private: void LogStep();
private: void Update();
private: void OnPause(bool _p);
private: void OnStep();
private: void OnControl(ConstWorldControlPtr &_data);
private: void OnPlaybackControl(ConstLogPlaybackControlPtr &_data);
private: void OnRequest(ConstRequestPtr &_msg);
private: void BuildSceneMsg(msgs::Scene &_scene, BasePtr _entity);
private: void JointLog(ConstJointPtr &_msg);
private: void OnFactoryMsg(ConstFactoryPtr &_data);
private: void OnModelMsg(ConstModelPtr &_msg);
private: void ModelUpdateTBB();
private: void ModelUpdateSingleLoop();
private: void LoadPlugin(sdf::ElementPtr _sdf);
private: void FillModelMsg(msgs::Model &_msg, ModelPtr _model);
private: void ProcessEntityMsgs();
private: void ProcessRequestMsgs();
private: void ProcessFactoryMsgs();
private: void ProcessModelMsgs();
private: void ProcessLightFactoryMsgs();
private: void ProcessLightModifyMsgs();
private: void ProcessPlaybackControlMsgs();
private: bool OnLog(std::ostringstream &_stream);
private: void LogModelResources();
private: void ProcessMessages();
private: void PublishWorldStats();
private: void LogWorker();
private: void RegisterIntrospectionItems();
private: void UnregisterIntrospectionItems();
private: void OnLightFactoryMsg(ConstLightPtr &_msg);
private: void OnLightModifyMsg(ConstLightPtr &_msg);
private: bool PluginInfoService(const ignition::msgs::StringMsg &_request,
ignition::msgs::Plugin_V &_plugins);
private: std::unique_ptr<WorldPrivate> dataPtr;
private: friend class DARTLink;
private: friend class SimbodyPhysics;
};
}
}
#endif
gazebo::physics::World::_AddDirty
void _AddDirty(Entity *_entity)
gazebo::physics::ActorPtr
boost::shared_ptr< Actor > ActorPtr
Definition: PhysicsTypes.hh:97
gazebo::common::URI
A complete URI.
Definition: URI.hh:176
ignition
Definition: Model.hh:40
UpdateInfo.hh
gazebo::physics::World::Physics
PhysicsEnginePtr Physics() const
Return the physics engine.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::physics::World::PublishModelPose
void PublishModelPose(physics::ModelPtr _model)
Publish pose updates for a model.
gazebo::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
gazebo::physics::World::SetPhysicsEnabled
void SetPhysicsEnabled(const bool _enable)
enable/disable physics engine during World::Update.
gazebo::physics::Base::BASE
Base type.
Definition: Base.hh:77
gazebo::physics::World::InsertModelSDF
void InsertModelSDF(const sdf::SDF &_sdf)
Insert a model using SDF.
gazebo::physics::ModelPtr
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
gazebo::physics::Model_V
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:205
gazebo::physics::World::SceneMsg
msgs::Scene SceneMsg() const
Get the current scene in message form.
gazebo::physics::World::SphericalCoords
common::SphericalCoordinatesPtr SphericalCoords() const
Return the spherical coordinates converter.
TransportTypes.hh
Forward declarations for transport.
gazebo::physics::World::Init
void Init()
Initialize the world.
gazebo::physics::World::Running
bool Running() const
Return the running state of the world.
gazebo::physics::World::ResetEntities
void ResetEntities(Base::EntityType _type=Base::BASE)
Reset with options.
system.hh
gazebo::physics::World::WorldPoseMutex
std::mutex & WorldPoseMutex() const
Get the set world pose mutex.
msgs.hh
CommonTypes.hh
gazebo::physics::World::Run
void Run(const unsigned int _iterations=0)
Run the world in a thread.
PhysicsTypes.hh
default namespace for gazebo
gazebo::physics::World::SetWindEnabled
void SetWindEnabled(const bool _enable)
enable/disable wind.
gazebo::physics::World::IsLoaded
bool IsLoaded() const
Return true if the world has been loaded.
gazebo::physics::World::PublishModelScale
void PublishModelScale(physics::ModelPtr _model)
Publish scale updates for a model.
gazebo::physics::World::UpdateStateSDF
void UpdateStateSDF()
Update the state SDF value from the current state.
gazebo::physics::World::WindEnabled
bool WindEnabled() const
check if wind is enabled/disabled.
gazebo::physics::World::Step
void Step(const unsigned int _steps)
Step the world forward in time.
gazebo::physics::World::DisableAllModels
void DisableAllModels()
Disable all links in all the models.
gazebo::physics::World::LoadLight
LightPtr LoadLight(const sdf::ElementPtr &_sdf, const BasePtr &_parent)
Load a light.
gazebo::physics::World::PrintEntityTree
void PrintEntityTree()
Print Entity tree.
gazebo::physics::World::InsertModelString
void InsertModelString(const std::string &_sdfString)
Insert a model from an SDF string.
gazebo::physics::World::SetAtmosphereEnabled
void SetAtmosphereEnabled(const bool _enable)
enable/disable atmosphere model.
gazebo::physics::World::EnableAllModels
void EnableAllModels()
Enable all links in all the models.
gazebo::physics::World::SetGravity
void SetGravity(const ignition::math::Vector3d &_gravity)
Set the gravity vector.
gazebo::physics::RoadPtr
boost::shared_ptr< Road > RoadPtr
Definition: PhysicsTypes.hh:161
gazebo::physics::Atmosphere
This models a base atmosphere class to serve as a common interface to any derived atmosphere models.
Definition: Atmosphere.hh:42
gazebo::physics::World::RemoveModel
void RemoveModel(ModelPtr _model)
Remove a model.
gazebo::physics::World::LightCount
unsigned int LightCount() const
Get the number of lights.
gazebo::physics::LightPtr
boost::shared_ptr< Light > LightPtr
Definition: PhysicsTypes.hh:105
gazebo::physics::World
The world provides access to all other object within a simulated environment.
Definition: World.hh:74
gazebo::physics::World::PresetMgr
PresetManagerPtr PresetMgr() const
Return the preset manager.
URI.hh
gazebo::physics::World::ResetPhysicsStates
void ResetPhysicsStates()
Reset the velocity, acceleration, force and torque of all child models.
gazebo::physics::World::Save
void Save(const std::string &_filename)
Save a world to a file.
gazebo::physics::World::Load
void Load(sdf::ElementPtr _sdf)
Load the world using SDF parameters.
gazebo::physics::World::Lights
Light_V Lights() const
Get a list of all the lights.
WorldState.hh
gazebo::physics::World::~World
~World()
Destructor.
gazebo::physics::World::SetSimTime
void SetSimTime(const common::Time &_t)
Set the sim time.
gazebo::common::SphericalCoordinatesPtr
boost::shared_ptr< SphericalCoordinates > SphericalCoordinatesPtr
Definition: CommonTypes.hh:121
gazebo::physics::Wind
Base class for wind.
Definition: Wind.hh:41
Base.hh
gazebo::physics::BasePtr
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
gazebo::physics::World::Fini
void Fini()
Finalize the world.
gazebo::physics::SimbodyPhysics
Simbody physics engine.
Definition: SimbodyPhysics.hh:42
gazebo::physics::World::PauseTime
common::Time PauseTime() const
Get the amount of time simulation has been paused.
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::physics::World::Clear
void Clear()
Remove all entities from the world.
gazebo::physics::World::ResetTime
void ResetTime()
Reset simulation time back to zero.
gazebo::physics::World::Stop
void Stop()
Stop the world.
gazebo::physics::World::Models
Model_V Models() const
Get a list of all the models.
gazebo::physics::World::_SetSensorsInitialized
void _SetSensorsInitialized(const bool _init)
gazebo::physics::World::RemovePlugin
void RemovePlugin(const std::string &_name)
Remove a running plugin.
gazebo::physics::World::EntityBelowPoint
EntityPtr EntityBelowPoint(const ignition::math::Vector3d &_pt) const
Get the nearest entity below a point.
gazebo::physics::World::SetMagneticField
void SetMagneticField(const ignition::math::Vector3d &_mag)
Set the magnetic field vector.
gazebo::physics::World::EntityByName
EntityPtr EntityByName(const std::string &_name) const
Get a pointer to an Entity based on a name.
gazebo::physics::EntityPtr
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:85
gazebo::physics::World::LoadPlugin
void LoadPlugin(const std::string &_filename, const std::string &_name, sdf::ElementPtr _sdf)
Load a plugin.
gazebo::physics::World::IsPaused
bool IsPaused() const
Returns the state of the simulation true if paused.
gazebo::physics::Entity
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
gazebo::physics::World::StartTime
common::Time StartTime() const
Get the wall time simulation was started.
gazebo::physics::World::Reset
void Reset()
Reset time and model poses, configurations in simulation.
gazebo::physics::World::SetState
void SetState(const WorldState &_state)
Set the current world state.
gazebo::physics::PhysicsEnginePtr
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition: PhysicsTypes.hh:125
gazebo::physics::World::SetGravitySDF
void SetGravitySDF(const ignition::math::Vector3d &_gravity)
Set the gravity sdf value.
gazebo::physics::World::Wind
physics::Wind & Wind() const
Get a reference to the wind used by the world.
gazebo::physics::World::Gravity
ignition::math::Vector3d Gravity() const
Return the gravity vector.
gazebo::physics::World::PublishLightPose
void PublishLightPose(const physics::LightPtr _light)
Publish pose updates for a light.
gazebo::physics::World::BaseByName
BasePtr BaseByName(const std::string &_name) const
Get an element by name.
Event.hh
gazebo::physics::World::Iterations
uint32_t Iterations() const
Get the total number of iterations.
gazebo::physics::World::InsertModelFile
void InsertModelFile(const std::string &_sdfFilename)
Insert a model from an SDF file.
gazebo::physics::World::ClearModels
void ClearModels()
Remove all entities from the world.
gazebo::physics::World::StripWorldName
std::string StripWorldName(const std::string &_name) const
Return a version of the name with "<world_name>::" removed.
gazebo::physics::WorldState
Store state information of a physics::World object.
Definition: WorldState.hh:47
gazebo::physics::Base::EntityType
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:75
gazebo::physics::World::RealTime
common::Time RealTime() const
Get the real time (elapsed time).
gazebo::physics::World::ModelByIndex
ModelPtr ModelByIndex(const unsigned int _index) const
Get a model based on an index.
gazebo::physics::World::LightByName
LightPtr LightByName(const std::string &_name) const
Get a light by name.
gazebo::physics::World::ModelCount
unsigned int ModelCount() const
Get the number of models.
gazebo::physics::World::World
World(const std::string &_name="")
Constructor.
gazebo::physics::World::SetPaused
void SetPaused(const bool _p)
Set whether the simulation is paused.
gazebo::physics::World::ModelByName
ModelPtr ModelByName(const std::string &_name) const
Get a model by name.
gazebo::physics::World::RunBlocking
void RunBlocking(const unsigned int _iterations=0)
Run the world.
gazebo::physics::PresetManagerPtr
boost::shared_ptr< PresetManager > PresetManagerPtr
Definition: PhysicsTypes.hh:129
gazebo::physics::World::AtmosphereEnabled
bool AtmosphereEnabled() const
check if atmosphere model is enabled/disabled.
gazebo::physics::World::SDF
const sdf::ElementPtr SDF()
Get the SDF of the world in the current state.
gazebo::physics::World::SensorsInitialized
bool SensorsInitialized() const
Get whether sensors have been initialized.
gazebo::physics::World::UniqueModelName
std::string UniqueModelName(const std::string &_name)
Get a model name which doesn't equal any existing model's name, by appending numbers to the given nam...
gazebo::physics::World::SimTime
common::Time SimTime() const
Get the world simulation time, note if you want the PC wall clock call common::Time::GetWallTime.
gazebo::physics::DARTLink
DART Link class.
Definition: DARTLink.hh:39
gazebo::physics::World::PhysicsEnabled
bool PhysicsEnabled() const
check if physics engine is enabled/disabled.
gazebo::physics::World::Name
std::string Name() const
Get the name of the world.
gazebo::physics::World::URI
common::URI URI() const
Return the URI of the world.
Wind.hh
gazebo::physics::Light_V
std::vector< LightPtr > Light_V
Definition: PhysicsTypes.hh:221
gazebo::physics::World::ModelBelowPoint
ModelPtr ModelBelowPoint(const ignition::math::Vector3d &_pt) const
Get the nearest model below and not encapsulating a point.
gazebo::physics::World::Atmosphere
physics::Atmosphere & Atmosphere() const
Get a reference to the atmosphere model used by the world.
gazebo::physics::World::MagneticField
virtual ignition::math::Vector3d MagneticField() const
Return the magnetic field vector.