25 #include <boost/thread.hpp>
26 #include <boost/enable_shared_from_this.hpp>
27 #include <boost/shared_ptr.hpp>
64 public:
explicit World(
const std::string &_name =
"");
72 public:
void Load(sdf::ElementPtr _sdf);
77 public:
void Save(
const std::string &_filename);
87 public:
void Run(
unsigned int _iterations = 0);
91 public:
bool GetRunning()
const;
104 public:
void Clear();
108 public: std::string GetName()
const;
121 public:
unsigned int GetModelCount()
const;
128 public:
ModelPtr GetModel(
unsigned int _index)
const;
132 public:
Model_V GetModels()
const;
141 public:
void ResetTime();
144 public:
void Reset();
149 public:
EntityPtr GetSelectedEntity()
const;
153 public:
void PrintEntityTree();
178 public:
bool IsPaused()
const;
182 public:
void SetPaused(
bool _p);
189 public:
BasePtr GetByName(
const std::string &_name);
196 public:
ModelPtr GetModel(
const std::string &_name);
203 public:
EntityPtr GetEntity(
const std::string &_name);
223 public:
void SetState(
const WorldState &_state);
228 public:
void InsertModelFile(
const std::string &_sdfFilename);
233 public:
void InsertModelString(
const std::string &_sdfString);
238 public:
void InsertModelSDF(
const sdf::SDF &_sdf);
243 public: std::string StripWorldName(
const std::string &_name)
const;
248 public:
void EnableAllModels();
253 public:
void DisableAllModels();
257 public:
void Step(
unsigned int _steps);
263 public:
void LoadPlugin(
const std::string &_filename,
264 const std::string &_name,
265 sdf::ElementPtr _sdf);
269 public:
void RemovePlugin(
const std::string &_name);
274 {
return this->setWorldPoseMutex;}
279 {
return this->enablePhysicsEngine;}
284 {this->enablePhysicsEngine = _enable;}
287 public:
void UpdateStateSDF();
291 public:
bool IsLoaded()
const;
295 public:
void ClearModels();
305 public: uint32_t GetIterations()
const;
309 public: msgs::Scene GetSceneMsg()
const;
315 public:
void RunBlocking(
unsigned int _iterations = 0);
321 public:
void RemoveModel(
ModelPtr _model);
327 public:
void RemoveModel(
const std::string &_name);
336 private:
ModelPtr GetModelById(
unsigned int _id);
342 private:
void LoadPlugins();
347 private:
void LoadEntities(sdf::ElementPtr _sdf,
BasePtr _parent);
368 private:
void RunLoop();
371 private:
void Step();
374 private:
void LogStep();
377 private:
void Update();
381 private:
void OnPause(
bool _p);
384 private:
void OnStep();
388 private:
void OnControl(ConstWorldControlPtr &_data);
392 private:
void OnRequest(ConstRequestPtr &_msg);
396 private:
void SetSelectedEntityCB(
const std::string &_name);
402 private:
void BuildSceneMsg(msgs::Scene &_scene,
BasePtr _entity);
406 private:
void JointLog(ConstJointPtr &_msg);
410 private:
void OnFactoryMsg(ConstFactoryPtr &_data);
414 private:
void OnModelMsg(ConstModelPtr &_msg);
417 private:
void ModelUpdateTBB();
420 private:
void ModelUpdateSingleLoop();
424 private:
void LoadPlugin(sdf::ElementPtr _sdf);
429 private:
void FillModelMsg(msgs::Model &_msg,
ModelPtr _model);
433 private:
void ProcessEntityMsgs();
437 private:
void ProcessRequestMsgs();
441 private:
void ProcessFactoryMsgs();
445 private:
void ProcessModelMsgs();
448 private:
bool OnLog(std::ostringstream &_stream);
451 private:
void ProcessMessages();
454 private:
void PublishWorldStats();
457 private:
void LogWorker();
461 private:
void OnLightMsg(ConstLightPtr &_msg);
476 private: boost::thread *thread;
485 private: std::string name;
500 private:
int stepInc;
554 private: msgs::WorldStatistics worldStatsMsg;
557 private: msgs::Scene sceneMsg;
560 private: void (
World::*modelUpdateFunc)();
572 private: boost::recursive_mutex *receiveMutex;
575 private: boost::mutex *loadModelMutex;
581 private: boost::mutex *setWorldPoseMutex;
589 private: boost::recursive_mutex *worldUpdateMutex;
592 private: sdf::ElementPtr sdf;
595 private: std::vector<WorldPluginPtr> plugins;
598 private: std::list<std::string> deleteEntity;
606 private: std::list<msgs::Request> requestMsgs;
609 private: std::list<msgs::Factory> factoryMsgs;
612 private: std::list<msgs::Model> modelMsgs;
615 private:
bool needsReset;
618 private:
bool resetAll;
621 private:
bool resetTimeOnly;
624 private:
bool resetModelOnly;
627 private:
bool initialized;
630 private:
bool loaded;
633 private:
bool enablePhysicsEngine;
639 private:
bool pluginsLoaded;
651 private: std::deque<WorldState> states[2];
654 private:
int currentStateBuffer;
657 private:
int stateToggle;
659 private: sdf::ElementPtr logPlayStateSDF;
664 private: sdf::SDFPtr factorySDF;
667 private: std::set<ModelPtr> publishModelPoses;
673 private: uint64_t iterations;
676 private: uint64_t stopIterations;
679 private: boost::condition_variable logCondition;
683 private: boost::condition_variable logContinueCondition;
686 private: uint64_t logPrevIteration;
692 private: boost::mutex logMutex;
695 private: boost::mutex logBufferMutex;
698 private: boost::mutex entityDeleteMutex;
701 private: boost::thread *logThread;
708 private: boost::mutex factoryDeleteMutex;
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:66
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:82
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
void EnablePhysicsEngine(bool _enable)
enable/disable physics engine during World::Update.
Definition: World.hh:283
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:48
Forward declarations for transport.
Information for use in an update event.
Definition: UpdateInfo.hh:30
default namespace for gazebo
bool GetEnablePhysicsEngine()
check if physics engine is enabled/disabled.
Definition: World.hh:278
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition: PhysicsTypes.hh:106
The world provides access to all other object within a simulated environment.
Definition: World.hh:59
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:74
std::vector< ConnectionPtr > Connection_V
Definition: CommonTypes.hh:148
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:52
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:78
boost::shared_ptr< Actor > ActorPtr
Definition: PhysicsTypes.hh:86
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
GAZEBO_VISIBLE void stop()
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:166
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
Store state information of a physics::World object.
Definition: WorldState.hh:46
boost::mutex * GetSetWorldPoseMutex() const
Get the set world pose mutex.
Definition: World.hh:273
boost::shared_ptr< SphericalCoordinates > SphericalCoordinatesPtr
Definition: CommonTypes.hh:135
Base type.
Definition: Base.hh:80
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
std::list< Entity * > dirtyPoses
when physics engine makes an update and changes a link pose, this flag is set to trigger Entity::SetW...
Definition: World.hh:603
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
boost::shared_ptr< RayShape > RayShapePtr
Definition: PhysicsTypes.hh:114
boost::shared_ptr< Road > RoadPtr
Definition: PhysicsTypes.hh:130