17#ifndef GAZEBO_PHYSICS_WORLD_HH_
18#define GAZEBO_PHYSICS_WORLD_HH_
27#include <boost/enable_shared_from_this.hpp>
75 class GZ_PHYSICS_VISIBLE
World :
76 public boost::enable_shared_from_this<World>
81 public:
explicit World(
const std::string &_name =
"");
89 public:
void Load(sdf::ElementPtr _sdf);
93 public:
const sdf::ElementPtr
SDF();
102 public:
void Save(
const std::string &_filename);
118 public:
void Run(const
unsigned int _iterations = 0);
122 public:
bool Running() const;
136 public:
void Clear();
140 public:
std::
string Name() const;
161 public:
common::SphericalCoordinatesPtr SphericalCoords() const;
169 public:
void SetGravity(const
ignition::math::Vector3d &_gravity);
173 public:
void SetGravitySDF(const
ignition::math::Vector3d &_gravity);
177 public:
ignition::math::Vector3d MagneticField() const;
181 public:
void SetMagneticField(const
ignition::math::Vector3d &_mag);
185 public:
unsigned int ModelCount() const;
192 public:
ModelPtr ModelByIndex(const
unsigned int _index) const;
200 public:
unsigned int LightCount() const;
210 public:
void ResetEntities(
Base::EntityType _type =
Base::BASE);
213 public:
void ResetTime();
216 public:
void Reset();
220 public:
void PrintEntityTree();
229 public:
void SetSimTime(const
common::Time &_t);
245 public:
bool IsPaused() const;
249 public:
void SetPaused(const
bool _p);
287 const
ignition::math::Vector3d &_pt) const;
295 const
ignition::math::Vector3d &_pt) const;
304 public:
void InsertModelFile(const
std::
string &_sdfFilename);
309 public:
void InsertModelString(const
std::
string &_sdfString);
314 public:
void InsertModelSDF(const sdf::SDF &_sdf);
319 public:
std::
string StripWorldName(const
std::
string &_name) const;
324 public:
void EnableAllModels();
329 public:
void DisableAllModels();
333 public:
void Step(const
unsigned int _steps);
339 public:
void LoadPlugin(const
std::
string &_filename,
340 const
std::
string &_name,
341 sdf::ElementPtr _sdf);
345 public:
void RemovePlugin(const
std::
string &_name);
349 public:
std::mutex &WorldPoseMutex() const;
353 public:
bool PhysicsEnabled() const;
357 public:
void SetPhysicsEnabled(const
bool _enable);
361 public:
bool WindEnabled() const;
365 public:
void SetWindEnabled(const
bool _enable);
369 public:
bool AtmosphereEnabled() const;
373 public:
void SetAtmosphereEnabled(const
bool _enable);
376 public:
void UpdateStateSDF();
380 public:
bool IsLoaded() const;
384 public:
void ClearModels();
390 public:
void PublishModelPose(physics::
ModelPtr _model);
396 public:
void PublishModelScale(physics::
ModelPtr _model);
402 public:
void PublishLightPose(const physics::
LightPtr _light);
406 public: uint32_t Iterations() const;
410 public: msgs::Scene SceneMsg() const;
416 public:
void RunBlocking(const
unsigned int _iterations = 0);
428 public:
void RemoveModel(const
std::
string &_name);
432 public:
void ResetPhysicsStates();
444 public:
bool SensorsInitialized() const;
450 public:
void _SetSensorsInitialized(const
bool _init);
461 public:
std::
string UniqueModelName(const
std::
string &_name);
465 public:
void SetSensorWaitFunc(
std::function<
void(
double,
double)> _func);
474 private:
ModelPtr ModelById(const
unsigned int _id) const;
480 private:
void LoadPlugins();
485 private:
void LoadEntities(sdf::ElementPtr _sdf,
BasePtr _parent);
497 public:
LightPtr LoadLight(const sdf::ElementPtr &_sdf,
513 private:
void RunLoop();
516 private:
void Step();
519 private:
void LogStep();
522 private:
void Update();
526 private:
void OnPause(
bool _p);
529 private:
void OnStep();
533 private:
void OnControl(ConstWorldControlPtr &_data);
537 private:
void OnPlaybackControl(ConstLogPlaybackControlPtr &_data);
541 private:
void OnRequest(ConstRequestPtr &_msg);
547 private:
void BuildSceneMsg(msgs::Scene &_scene,
BasePtr _entity);
551 private:
void JointLog(ConstJointPtr &_msg);
555 private:
void OnFactoryMsg(ConstFactoryPtr &_data);
559 private:
void OnModelMsg(ConstModelPtr &_msg);
562 private:
void ModelUpdateTBB();
565 private:
void ModelUpdateSingleLoop();
569 private:
void LoadPlugin(sdf::ElementPtr _sdf);
574 private:
void FillModelMsg(msgs::
Model &_msg,
ModelPtr _model);
578 private:
void ProcessEntityMsgs();
582 private:
void ProcessRequestMsgs();
586 private:
void ProcessFactoryMsgs();
590 private:
void ProcessModelMsgs();
594 private:
void ProcessLightFactoryMsgs();
598 private:
void ProcessLightModifyMsgs();
602 private:
void ProcessPlaybackControlMsgs();
605 private:
bool OnLog(
std::ostringstream &_stream);
609 private:
void LogModelResources();
612 private:
void ProcessMessages();
615 private:
void PublishWorldStats();
618 private:
void LogWorker();
621 private:
void RegisterIntrospectionItems();
624 private:
void UnregisterIntrospectionItems();
629 private:
void OnLightFactoryMsg(ConstLightPtr &_msg);
634 private:
void OnLightModifyMsg(ConstLightPtr &_msg);
652 private:
bool PluginInfoService(const
ignition::msgs::StringMsg &_request,
653 ignition::msgs::Plugin_V &_plugins);
658 private:
bool SceneInfoService(msgs::Scene &_response);
663 private:
bool ShadowCasterMaterialNameService(
664 ignition::msgs::StringMsg &_response);
671 private:
bool ShadowCasterRenderBackFacesService(
672 ignition::msgs::Boolean &_response);
676 private:
std::unique_ptr<WorldPrivate> dataPtr;
common
Definition FuelModelDatabase.hh:42
default namespace for gazebo
Forward declarations for transport.
This models a base atmosphere class to serve as a common interface to any derived atmosphere models.
Definition Atmosphere.hh:43
Base class for most physics classes.
Definition Base.hh:73
DART Link class.
Definition DARTLink.hh:40
Base class for all physics objects in Gazebo.
Definition Entity.hh:53
A model is a collection of links, joints, and plugins.
Definition Model.hh:60
Simbody physics engine.
Definition SimbodyPhysics.hh:43
Base class for wind.
Definition Wind.hh:42
Store state information of a physics::World object.
Definition WorldState.hh:48
The world provides access to all other object within a simulated environment.
Definition World.hh:77
void Fini()
Finalize the world.
void SetState(const WorldState &_state)
Set the current world state.
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...
void RemoveModel(ModelPtr _model)
Remove a model.
void SetPhysicsEnabled(const bool _enable)
enable/disable physics engine during World::Update.
void InsertModelFile(const std::string &_sdfFilename)
Insert a model from an SDF file.
unsigned int LightCount() const
Get the number of lights.
void ClearModels()
Remove all entities from the world.
void Stop()
Stop the world.
bool SensorsInitialized() const
Get whether sensors have been initialized.
void SetGravitySDF(const ignition::math::Vector3d &_gravity)
Set the gravity sdf value.
ModelPtr ModelByIndex(const unsigned int _index) const
Get a model based on an index.
void SetMagneticField(const ignition::math::Vector3d &_mag)
Set the magnetic field vector.
PhysicsEnginePtr Physics() const
Return the physics engine.
PresetManagerPtr PresetMgr() const
Return the preset manager.
void _SetSensorsInitialized(const bool _init)
void SetSimTime(const common::Time &_t)
Set the sim time.
void SetSensorWaitFunc(std::function< void(double, double)> _func)
Set callback 'waitForSensors'.
void Reset()
Reset time and model poses, configurations in simulation.
void PublishLightPose(const physics::LightPtr _light)
Publish pose updates for a light.
void RemovePlugin(const std::string &_name)
Remove a running plugin.
void _AddDirty(Entity *_entity)
std::string Name() const
Get the name of the world.
void SetPaused(const bool _p)
Set whether the simulation is paused.
void ResetPhysicsStates()
Reset the velocity, acceleration, force and torque of all child models.
void SetWindEnabled(const bool _enable)
enable/disable wind.
bool WindEnabled() const
check if wind is enabled/disabled.
void SetAtmosphereEnabled(const bool _enable)
enable/disable atmosphere model.
std::string StripWorldName(const std::string &_name) const
Return a version of the name with "<world_name>::" removed.
void ResetEntities(Base::EntityType _type=Base::BASE)
Reset with options.
uint32_t Iterations() const
Get the total number of iterations.
void EnableAllModels()
Enable all links in all the models.
Light_V Lights() const
Get a list of all the lights.
LightPtr LightByName(const std::string &_name) const
Get a light by name.
bool IsLoaded() const
Return true if the world has been loaded.
void InsertModelString(const std::string &_sdfString)
Insert a model from an SDF string.
common::URI URI() const
Return the URI of the world.
ignition::math::Vector3d Gravity() const
Return the gravity vector.
void Run(const unsigned int _iterations=0)
Run the world in a thread.
ModelPtr ModelBelowPoint(const ignition::math::Vector3d &_pt) const
Get the nearest model below and not encapsulating a point.
void PublishModelScale(physics::ModelPtr _model)
Publish scale updates for a model.
std::mutex & WorldPoseMutex() const
Get the set world pose mutex.
LightPtr LoadLight(const sdf::ElementPtr &_sdf, const BasePtr &_parent)
Load a light.
ignition::math::Vector3d MagneticField() const
Return the magnetic field vector.
void ResetTime()
Reset simulation time back to zero.
Model_V Models() const
Get a list of all the models.
bool PhysicsEnabled() const
check if physics engine is enabled/disabled.
bool IsPaused() const
Returns the state of the simulation true if paused.
common::Time StartTime() const
Get the wall time simulation was started.
const sdf::World * GetSDFDom() const
Get the SDF DOM for the world.
common::Time RealTime() const
Get the real time (elapsed time).
void Clear()
Remove all entities from the world.
void InsertModelSDF(const sdf::SDF &_sdf)
Insert a model using SDF.
void Save(const std::string &_filename)
Save a world to a file.
bool Running() const
Return the running state of the world.
BasePtr BaseByName(const std::string &_name) const
Get an element by name.
void DisableAllModels()
Disable all links in all the models.
ModelPtr ModelByName(const std::string &_name) const
Get a model by name.
const sdf::ElementPtr SDF()
Get the SDF of the world in the current state.
void LoadPlugin(const std::string &_filename, const std::string &_name, sdf::ElementPtr _sdf)
Load a plugin.
void PublishModelPose(physics::ModelPtr _model)
Publish pose updates for a model.
EntityPtr EntityByName(const std::string &_name) const
Get a pointer to an Entity based on a name.
common::SphericalCoordinatesPtr SphericalCoords() const
Return the spherical coordinates converter.
void Load(sdf::ElementPtr _sdf)
Load the world using SDF parameters.
void Init() GAZEBO_DEPRECATED(11.0)
Initialize the world.
void PrintEntityTree()
Print Entity tree.
void UpdateStateSDF()
Update the state SDF value from the current state.
bool AtmosphereEnabled() const
check if atmosphere model is enabled/disabled.
World(const std::string &_name="")
Constructor.
msgs::Scene SceneMsg() const
Get the current scene in message form.
common::Time SimTime() const
Get the world simulation time, note if you want the PC wall clock call common::Time::GetWallTime.
void RunBlocking(const unsigned int _iterations=0)
Run the world.
EntityPtr EntityBelowPoint(const ignition::math::Vector3d &_pt) const
Get the nearest entity below a point.
unsigned int ModelCount() const
Get the number of models.
common::Time PauseTime() const
Get the amount of time simulation has been paused.
void SetGravity(const ignition::math::Vector3d &_gravity)
Set the gravity vector.
std::vector< ModelPtr > Model_V
Definition PhysicsTypes.hh:206
boost::shared_ptr< Light > LightPtr
Definition PhysicsTypes.hh:106
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition PhysicsTypes.hh:126
boost::shared_ptr< Actor > ActorPtr
Definition PhysicsTypes.hh:98
boost::shared_ptr< Base > BasePtr
Definition PhysicsTypes.hh:78
std::vector< LightPtr > Light_V
Definition PhysicsTypes.hh:222
boost::shared_ptr< PresetManager > PresetManagerPtr
Definition PhysicsTypes.hh:130
std::function< void(const std::string &, const msgs::PosesStamped &)> UpdateScenePosesFunc
Function signature for API that updates scene poses.
Definition PhysicsTypes.hh:252
boost::shared_ptr< Entity > EntityPtr
Definition PhysicsTypes.hh:86
boost::shared_ptr< Road > RoadPtr
Definition PhysicsTypes.hh:162
boost::shared_ptr< Model > ModelPtr
Definition PhysicsTypes.hh:94
Forward declarations for the common classes.
Definition Animation.hh:27
#define GAZEBO_DEPRECATED(version)
Definition system.hh:328