World Class Reference

The world provides access to all other object within a simulated environment. More...

#include <physics/physics.hh>

Inherits enable_shared_from_this< World >.

Public Member Functions

 World (const std::string &_name="")
 Constructor. More...
 
 ~World ()
 Destructor. More...
 
void _AddDirty (Entity *_entity)
 
void _SetSensorsInitialized (const bool _init)
 
physics::AtmosphereAtmosphere () const
 Get a reference to the atmosphere model used by the world. More...
 
bool AtmosphereEnabled () const
 check if atmosphere model is enabled/disabled. More...
 
BasePtr BaseByName (const std::string &_name) const
 Get an element by name. More...
 
void Clear ()
 Remove all entities from the world. More...
 
void ClearModels ()
 Remove all entities from the world. More...
 
void DisableAllModels ()
 Disable all links in all the models. More...
 
void EnableAllModels ()
 Enable all links in all the models. More...
 
EntityPtr EntityBelowPoint (const ignition::math::Vector3d &_pt) const
 Get the nearest entity below a point. More...
 
EntityPtr EntityByName (const std::string &_name) const
 Get a pointer to an Entity based on a name. More...
 
void Fini ()
 Finalize the world. More...
 
const sdf::World * GetSDFDom () const
 Get the SDF DOM for the world. More...
 
ignition::math::Vector3d Gravity () const
 Return the gravity vector. More...
 
void Init () GAZEBO_DEPRECATED(11.0)
 Initialize the world. More...
 
void Init (UpdateScenePosesFunc _func)
 Initialize the world. More...
 
void InsertModelFile (const std::string &_sdfFilename)
 Insert a model from an SDF file. More...
 
void InsertModelSDF (const sdf::SDF &_sdf)
 Insert a model using SDF. More...
 
void InsertModelString (const std::string &_sdfString)
 Insert a model from an SDF string. More...
 
bool IsLoaded () const
 Return true if the world has been loaded. More...
 
bool IsPaused () const
 Returns the state of the simulation true if paused. More...
 
uint32_t Iterations () const
 Get the total number of iterations. More...
 
LightPtr LightByName (const std::string &_name) const
 Get a light by name. More...
 
unsigned int LightCount () const
 Get the number of lights. More...
 
Light_V Lights () const
 Get a list of all the lights. More...
 
void Load (sdf::ElementPtr _sdf)
 Load the world using SDF parameters. More...
 
LightPtr LoadLight (const sdf::ElementPtr &_sdf, const BasePtr &_parent)
 Load a light. More...
 
void LoadPlugin (const std::string &_filename, const std::string &_name, sdf::ElementPtr _sdf)
 Load a plugin. More...
 
ignition::math::Vector3d MagneticField () const
 Return the magnetic field vector. More...
 
ModelPtr ModelBelowPoint (const ignition::math::Vector3d &_pt) const
 Get the nearest model below and not encapsulating a point. More...
 
ModelPtr ModelByIndex (const unsigned int _index) const
 Get a model based on an index. More...
 
ModelPtr ModelByName (const std::string &_name) const
 Get a model by name. More...
 
unsigned int ModelCount () const
 Get the number of models. More...
 
Model_V Models () const
 Get a list of all the models. More...
 
std::string Name () const
 Get the name of the world. More...
 
common::Time PauseTime () const
 Get the amount of time simulation has been paused. More...
 
PhysicsEnginePtr Physics () const
 Return the physics engine. More...
 
bool PhysicsEnabled () const
 check if physics engine is enabled/disabled. More...
 
PresetManagerPtr PresetMgr () const
 Return the preset manager. More...
 
void PrintEntityTree ()
 Print Entity tree. More...
 
void PublishLightPose (const physics::LightPtr _light)
 Publish pose updates for a light. More...
 
void PublishModelPose (physics::ModelPtr _model)
 Publish pose updates for a model. More...
 
void PublishModelScale (physics::ModelPtr _model)
 Publish scale updates for a model. More...
 
common::Time RealTime () const
 Get the real time (elapsed time). More...
 
void RemoveModel (ModelPtr _model)
 Remove a model. More...
 
void RemoveModel (const std::string &_name)
 Remove a model by name. More...
 
void RemovePlugin (const std::string &_name)
 Remove a running plugin. More...
 
void Reset ()
 Reset time and model poses, configurations in simulation. More...
 
void ResetEntities (Base::EntityType _type=Base::BASE)
 Reset with options. More...
 
void ResetPhysicsStates ()
 Reset the velocity, acceleration, force and torque of all child models. More...
 
void ResetTime ()
 Reset simulation time back to zero. More...
 
void Run (const unsigned int _iterations=0)
 Run the world in a thread. More...
 
void RunBlocking (const unsigned int _iterations=0)
 Run the world. More...
 
bool Running () const
 Return the running state of the world. More...
 
void Save (const std::string &_filename)
 Save a world to a file. More...
 
msgs::Scene SceneMsg () const
 Get the current scene in message form. More...
 
const sdf::ElementPtr SDF ()
 Get the SDF of the world in the current state. More...
 
bool SensorsInitialized () const
 Get whether sensors have been initialized. More...
 
void SetAtmosphereEnabled (const bool _enable)
 enable/disable atmosphere model. More...
 
void SetGravity (const ignition::math::Vector3d &_gravity)
 Set the gravity vector. More...
 
void SetGravitySDF (const ignition::math::Vector3d &_gravity)
 Set the gravity sdf value. More...
 
void SetMagneticField (const ignition::math::Vector3d &_mag)
 Set the magnetic field vector. More...
 
void SetPaused (const bool _p)
 Set whether the simulation is paused. More...
 
void SetPhysicsEnabled (const bool _enable)
 enable/disable physics engine during World::Update. More...
 
void SetSimTime (const common::Time &_t)
 Set the sim time. More...
 
void SetState (const WorldState &_state)
 Set the current world state. More...
 
void SetWindEnabled (const bool _enable)
 enable/disable wind. More...
 
common::Time SimTime () const
 Get the world simulation time, note if you want the PC wall clock call common::Time::GetWallTime. More...
 
common::SphericalCoordinatesPtr SphericalCoords () const
 Return the spherical coordinates converter. More...
 
common::Time StartTime () const
 Get the wall time simulation was started. More...
 
void Step (const unsigned int _steps)
 Step the world forward in time. More...
 
void Stop ()
 Stop the world. More...
 
std::string StripWorldName (const std::string &_name) const
 Return a version of the name with "<world_name>::" removed. More...
 
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 name. More...
 
void UpdateStateSDF ()
 Update the state SDF value from the current state. More...
 
common::URI URI () const
 Return the URI of the world. More...
 
physics::WindWind () const
 Get a reference to the wind used by the world. More...
 
bool WindEnabled () const
 check if wind is enabled/disabled. More...
 
std::mutex & WorldPoseMutex () const
 Get the set world pose mutex. More...
 

Detailed Description

The world provides access to all other object within a simulated environment.

The World is the container for all models and their components (links, joints, sensors, plugins, etc), and WorldPlugin instances. Many core function are also handled in the World, including physics update, model updates, and message processing.

Constructor & Destructor Documentation

◆ World()

World ( const std::string &  _name = "")
explicit

Constructor.

Constructor for the World. Must specify a unique name.

Parameters
[in]_nameName of the world.

◆ ~World()

~World ( )

Destructor.

Member Function Documentation

◆ _AddDirty()

void _AddDirty ( Entity _entity)

◆ _SetSensorsInitialized()

void _SetSensorsInitialized ( const bool  _init)

◆ Atmosphere()

Get a reference to the atmosphere model used by the world.

Returns
Reference to the atmosphere model.

◆ AtmosphereEnabled()

bool AtmosphereEnabled ( ) const

check if atmosphere model is enabled/disabled.

Parameters
Trueif the atmosphere model is enabled.

◆ BaseByName()

BasePtr BaseByName ( const std::string &  _name) const

Get an element by name.

Searches the list of entities, and return a pointer to the model with a matching _name.

Parameters
[in]_nameThe name of the Model to find.
Returns
A pointer to the entity, or NULL if no entity was found.

◆ Clear()

void Clear ( )

Remove all entities from the world.

This function has delayed effect. Models are cleared at the end of the current update iteration.

◆ ClearModels()

void ClearModels ( )

Remove all entities from the world.

Implementation of World::Clear

◆ DisableAllModels()

void DisableAllModels ( )

Disable all links in all the models.

Disable is a physics concept. Disabling means that the physics engine should not update an entity.

◆ EnableAllModels()

void EnableAllModels ( )

Enable all links in all the models.

Enable is a physics concept. Enabling means that the physics engine should update an entity.

◆ EntityBelowPoint()

EntityPtr EntityBelowPoint ( const ignition::math::Vector3d &  _pt) const

Get the nearest entity below a point.

Projects a Ray down (-Z axis) starting at the given point. The first entity hit by the Ray is returned.

Parameters
[in]_ptThe 3D point to search below
Returns
A pointer to nearest Entity, NULL if none is found.

◆ EntityByName()

EntityPtr EntityByName ( const std::string &  _name) const

Get a pointer to an Entity based on a name.

This function is the same as BaseByName, but limits the search to only Entities.

Parameters
[in]_nameThe name of the Entity to find.
Returns
A pointer to the Entity, or NULL if no Entity was found.

◆ Fini()

void Fini ( )

Finalize the world.

Call this function to tear-down the world.

◆ GetSDFDom()

const sdf::World* GetSDFDom ( ) const

Get the SDF DOM for the world.

Returns
The SDF DOM for this world.

◆ Gravity()

ignition::math::Vector3d Gravity ( ) const

Return the gravity vector.

Returns
The gravity vector.

◆ Init() [1/2]

void Init ( )

Initialize the world.

This is called after Load.

Deprecated:
See Init(UpdateScenePosesFunc)

◆ Init() [2/2]

void Init ( UpdateScenePosesFunc  _func)

Initialize the world.

This is called after Load.

Parameters
[in]_funcfunction to be called when Poses are available.

◆ InsertModelFile()

void InsertModelFile ( const std::string &  _sdfFilename)

Insert a model from an SDF file.

Spawns a model into the world base on and SDF file.

Parameters
[in]_sdfFilenameThe name of the SDF file (including path).

◆ InsertModelSDF()

void InsertModelSDF ( const sdf::SDF &  _sdf)

Insert a model using SDF.

Spawns a model into the world base on and SDF object.

Parameters
[in]_sdfA reference to an SDF object.

◆ InsertModelString()

void InsertModelString ( const std::string &  _sdfString)

Insert a model from an SDF string.

Spawns a model into the world base on and SDF string.

Parameters
[in]_sdfStringA string containing valid SDF markup.

◆ IsLoaded()

bool IsLoaded ( ) const

Return true if the world has been loaded.

Returns
True if World::Load has completed.

◆ IsPaused()

bool IsPaused ( ) const

Returns the state of the simulation true if paused.

Returns
True if paused.

◆ Iterations()

uint32_t Iterations ( ) const

Get the total number of iterations.

Returns
Number of iterations that simulation has taken.

◆ LightByName()

LightPtr LightByName ( const std::string &  _name) const

Get a light by name.

This function is the same as BaseByName(), but limits the search to only lights.

Parameters
[in]_nameThe name of the Light to find.
Returns
A pointer to the Light, or NULL if no light was found.

◆ LightCount()

unsigned int LightCount ( ) const

Get the number of lights.

Returns
The number of lights in the World.

◆ Lights()

Light_V Lights ( ) const

Get a list of all the lights.

Returns
A list of all the Lights in the world.

◆ Load()

void Load ( sdf::ElementPtr  _sdf)

Load the world using SDF parameters.

Load a world from and SDF pointer.

Parameters
[in]_sdfSDF parameters.

◆ LoadLight()

LightPtr LoadLight ( const sdf::ElementPtr &  _sdf,
const BasePtr _parent 
)

Load a light.

Parameters
[in]_sdfSDF element containing the Light description.
[in]_parentParent of the light.
Returns
Pointer to the newly created Light.

◆ LoadPlugin()

void LoadPlugin ( const std::string &  _filename,
const std::string &  _name,
sdf::ElementPtr  _sdf 
)

Load a plugin.

Parameters
[in]_filenameThe filename of the plugin.
[in]_nameA unique name for the plugin.
[in]_sdfThe SDF to pass into the plugin.

◆ MagneticField()

ignition::math::Vector3d MagneticField ( ) const

Return the magnetic field vector.

Returns
The magnetic field vector.

◆ ModelBelowPoint()

ModelPtr ModelBelowPoint ( const ignition::math::Vector3d &  _pt) const

Get the nearest model below and not encapsulating a point.

Only objects below the start point can be returned. Any object that encapsulates the start point can not be returned from this function. This function makes use of World::GetEntityBelowPoint.

Parameters
[in]_ptThe 3D point to search below.
Returns
A pointer to nearest Model, NULL if none is found.

◆ ModelByIndex()

ModelPtr ModelByIndex ( const unsigned int  _index) const

Get a model based on an index.

Get a Model using an index, where index must be greater than zero and less than World::ModelCount()

Parameters
[in]_indexThe index of the model [0..GetModelCount)
Returns
A pointer to the Model. NULL if _index is invalid.

◆ ModelByName()

ModelPtr ModelByName ( const std::string &  _name) const

Get a model by name.

This function is the same as BaseByName, but limits the search to only models.

Parameters
[in]_nameThe name of the Model to find.
Returns
A pointer to the Model, or NULL if no model was found.

◆ ModelCount()

unsigned int ModelCount ( ) const

Get the number of models.

Returns
The number of models in the World.

◆ Models()

Model_V Models ( ) const

Get a list of all the models.

Returns
A list of all the Models in the world.

◆ Name()

std::string Name ( ) const

Get the name of the world.

Returns
The name of the world.

◆ PauseTime()

common::Time PauseTime ( ) const

Get the amount of time simulation has been paused.

Returns
The pause time.

◆ Physics()

PhysicsEnginePtr Physics ( ) const

Return the physics engine.

Get a pointer to the physics engine used by the world.

Returns
Pointer to the physics engine.

◆ PhysicsEnabled()

bool PhysicsEnabled ( ) const

check if physics engine is enabled/disabled.

Parameters
Trueif the physics engine is enabled.

◆ PresetMgr()

PresetManagerPtr PresetMgr ( ) const

Return the preset manager.

Returns
Pointer to the preset manager.

◆ PrintEntityTree()

void PrintEntityTree ( )

Print Entity tree.

Prints alls the entities to stdout.

◆ PublishLightPose()

void PublishLightPose ( const physics::LightPtr  _light)

Publish pose updates for a light.

Adds light to a list of lights to publish, which is processed and cleared once every iteration.

Parameters
[in]_lightPointer to the light to publish.

◆ PublishModelPose()

void PublishModelPose ( physics::ModelPtr  _model)

Publish pose updates for a model.

This list of models to publish is processed and cleared once every iteration.

Parameters
[in]_modelPointer to the model to publish.

◆ PublishModelScale()

void PublishModelScale ( physics::ModelPtr  _model)

Publish scale updates for a model.

This list of models to publish is processed and cleared once every iteration.

Parameters
[in]_modelPointer to the model to publish.

◆ RealTime()

common::Time RealTime ( ) const

Get the real time (elapsed time).

Returns
The real time.

◆ RemoveModel() [1/2]

void RemoveModel ( ModelPtr  _model)

Remove a model.

This function will block until the physics engine is not locked. The duration of the block is less than the time to complete a simulation iteration.

Parameters
[in]_modelPointer to a model to remove.

◆ RemoveModel() [2/2]

void RemoveModel ( const std::string &  _name)

Remove a model by name.

This function will block until the physics engine is not locked. The duration of the block is less than the time to complete a simulation iteration.

Parameters
[in]_nameName of the model to remove.

◆ RemovePlugin()

void RemovePlugin ( const std::string &  _name)

Remove a running plugin.

Parameters
[in]_nameThe unique name of the plugin to remove.

◆ Reset()

void Reset ( )

Reset time and model poses, configurations in simulation.

◆ ResetEntities()

void ResetEntities ( Base::EntityType  _type = Base::BASE)

Reset with options.

The _type parameter specifies which type of eneities to reset. See Base::EntityType.

Parameters
[in]_typeThe type of reset.

◆ ResetPhysicsStates()

void ResetPhysicsStates ( )

Reset the velocity, acceleration, force and torque of all child models.

◆ ResetTime()

void ResetTime ( )

Reset simulation time back to zero.

◆ Run()

void Run ( const unsigned int  _iterations = 0)

Run the world in a thread.

Run the update loop.

Parameters
[in]_iterationsRun for this many iterations, then stop. A value of zero disables run stop.

◆ RunBlocking()

void RunBlocking ( const unsigned int  _iterations = 0)

Run the world.

This call blocks. Run the update loop.

Parameters
[in]_iterationsRun for this many iterations, then stop. A value of zero disables run stop.

◆ Running()

bool Running ( ) const

Return the running state of the world.

Returns
True if the world is running.

◆ Save()

void Save ( const std::string &  _filename)

Save a world to a file.

Save the current world and its state to a file.

Parameters
[in]_filenameName of the file to save into.

◆ SceneMsg()

msgs::Scene SceneMsg ( ) const

Get the current scene in message form.

Returns
The scene state as a protobuf message.

◆ SDF()

const sdf::ElementPtr SDF ( )

Get the SDF of the world in the current state.

Returns
The SDF

◆ SensorsInitialized()

bool SensorsInitialized ( ) const

Get whether sensors have been initialized.

Returns
True if sensors have been initialized.

◆ SetAtmosphereEnabled()

void SetAtmosphereEnabled ( const bool  _enable)

enable/disable atmosphere model.

Parameters
[in]_enableTrue to enable the atmosphere model.

◆ SetGravity()

void SetGravity ( const ignition::math::Vector3d &  _gravity)

Set the gravity vector.

Parameters
[in]_gravityNew gravity vector.

◆ SetGravitySDF()

void SetGravitySDF ( const ignition::math::Vector3d &  _gravity)

Set the gravity sdf value.

Parameters
[in]_gravityNew gravity vector.

◆ SetMagneticField()

void SetMagneticField ( const ignition::math::Vector3d &  _mag)

Set the magnetic field vector.

Parameters
[in]_magNew magnetic field vector.

◆ SetPaused()

void SetPaused ( const bool  _p)

Set whether the simulation is paused.

Parameters
[in]_pTrue pauses the simulation. False runs the simulation.

◆ SetPhysicsEnabled()

void SetPhysicsEnabled ( const bool  _enable)

enable/disable physics engine during World::Update.

Parameters
[in]_enableTrue to enable the physics engine.

◆ SetSimTime()

void SetSimTime ( const common::Time _t)

Set the sim time.

Parameters
[in]_tThe new simulation time

◆ SetState()

void SetState ( const WorldState _state)

Set the current world state.

Parameters
_stateThe state to set the World to.

◆ SetWindEnabled()

void SetWindEnabled ( const bool  _enable)

enable/disable wind.

Parameters
[in]_enableTrue to enable the wind.

◆ SimTime()

common::Time SimTime ( ) const

Get the world simulation time, note if you want the PC wall clock call common::Time::GetWallTime.

Returns
The current simulation time

◆ SphericalCoords()

common::SphericalCoordinatesPtr SphericalCoords ( ) const

Return the spherical coordinates converter.

Returns
Pointer to the spherical coordinates converter.

◆ StartTime()

common::Time StartTime ( ) const

Get the wall time simulation was started.

Returns
The start time.

◆ Step()

void Step ( const unsigned int  _steps)

Step the world forward in time.

Parameters
[in]_stepsThe number of steps the World should take.

◆ Stop()

void Stop ( )

Stop the world.

Request the update loop thread to stop. Wait for it to join if this function is called from another thread. Return immediately otherwise.

◆ StripWorldName()

std::string StripWorldName ( const std::string &  _name) const

Return a version of the name with "<world_name>::" removed.

Parameters
[in]_nameUsually the name of an entity.
Returns
The stripped world name.

◆ 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 name.

If _name is already unique, the returned value is the same.

Parameters
[in]_nameDesired model name.
Returns
Unique model name.

◆ UpdateStateSDF()

void UpdateStateSDF ( )

Update the state SDF value from the current state.

◆ URI()

common::URI URI ( ) const

Return the URI of the world.

Returns
URI of this world.

◆ Wind()

physics::Wind& Wind ( ) const

Get a reference to the wind used by the world.

Returns
Reference to the wind.

◆ WindEnabled()

bool WindEnabled ( ) const

check if wind is enabled/disabled.

Parameters
Trueif the wind is enabled.

◆ WorldPoseMutex()

std::mutex& WorldPoseMutex ( ) const

Get the set world pose mutex.

Returns
Reference to the mutex.

The documentation for this class was generated from the following file: