World.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_WORLD_HH_
18 #define _GAZEBO_WORLD_HH_
19 
20 #ifdef _WIN32
21  // Ensure that Winsock2.h is included before Windows.h, which can get
22  // pulled in by anybody (e.g., Boost).
23  #include <Winsock2.h>
24 #endif
25 
26 #include <vector>
27 #include <list>
28 #include <set>
29 #include <deque>
30 #include <string>
31 #include <boost/thread.hpp>
32 #include <boost/enable_shared_from_this.hpp>
33 #include <boost/shared_ptr.hpp>
34 
35 #include <sdf/sdf.hh>
36 
38 
39 #include "gazebo/msgs/msgs.hh"
40 
43 #include "gazebo/common/Event.hh"
44 
45 #include "gazebo/physics/Base.hh"
48 #include "gazebo/util/system.hh"
49 
50 namespace gazebo
51 {
52  namespace physics
53  {
55  class WorldPrivate;
56 
59 
69  public boost::enable_shared_from_this<World>
70  {
74  public: explicit World(const std::string &_name = "");
75 
77  public: ~World();
78 
82  public: void Load(sdf::ElementPtr _sdf);
83 
87  public: void Save(const std::string &_filename);
88 
91  public: void Init();
92 
97  public: void Run(unsigned int _iterations = 0);
98 
101  public: bool GetRunning() const;
102 
105  public: void Stop();
106 
109  public: void Fini();
110 
114  public: void Clear();
115 
118  public: std::string GetName() const;
119 
123  public: PhysicsEnginePtr GetPhysicsEngine() const;
124 
127  public: PresetManagerPtr GetPresetManager() const;
128 
131  public: common::SphericalCoordinatesPtr GetSphericalCoordinates() const;
132 
135  public: ignition::math::Vector3d Gravity() const;
136 
139  public: void SetGravity(const ignition::math::Vector3d &_gravity);
140 
143  public: void SetGravitySDF(const ignition::math::Vector3d &_gravity);
144 
147  public: virtual ignition::math::Vector3d MagneticField() const;
148 
151  public: void SetMagneticField(const ignition::math::Vector3d &_mag);
152 
155  public: unsigned int GetModelCount() const;
156 
162  public: ModelPtr GetModel(unsigned int _index) const;
163 
166  public: Model_V GetModels() const;
167 
170  public: Light_V Lights() const;
171 
176  public: void ResetEntities(Base::EntityType _type = Base::BASE);
177 
179  public: void ResetTime();
180 
182  public: void Reset();
183 
186  public: void PrintEntityTree();
187 
191  public: common::Time GetSimTime() const;
192 
195  public: void SetSimTime(const common::Time &_t);
196 
199  public: common::Time GetPauseTime() const;
200 
203  public: common::Time GetStartTime() const;
204 
207  public: common::Time GetRealTime() const;
208 
211  public: bool IsPaused() const;
212 
215  public: void SetPaused(bool _p);
216 
222  public: BasePtr GetByName(const std::string &_name);
223 
229  public: ModelPtr GetModel(const std::string &_name);
230 
236  public: LightPtr Light(const std::string &_name);
237 
243  public: EntityPtr GetEntity(const std::string &_name);
244 
252  public: ModelPtr GetModelBelowPoint(const math::Vector3 &_pt);
253 
259  public: EntityPtr GetEntityBelowPoint(const math::Vector3 &_pt);
260 
263  public: void SetState(const WorldState &_state);
264 
268  public: void InsertModelFile(const std::string &_sdfFilename);
269 
273  public: void InsertModelString(const std::string &_sdfString);
274 
278  public: void InsertModelSDF(const sdf::SDF &_sdf);
279 
283  public: std::string StripWorldName(const std::string &_name) const;
284 
288  public: void EnableAllModels();
289 
293  public: void DisableAllModels();
294 
297  public: void Step(unsigned int _steps);
298 
303  public: void LoadPlugin(const std::string &_filename,
304  const std::string &_name,
305  sdf::ElementPtr _sdf);
306 
309  public: void RemovePlugin(const std::string &_name);
310 
313  public: boost::mutex *GetSetWorldPoseMutex() const;
314 
317  public: bool GetEnablePhysicsEngine();
318 
321  public: void EnablePhysicsEngine(bool _enable);
322 
324  public: void UpdateStateSDF();
325 
328  public: bool IsLoaded() const;
329 
332  public: void ClearModels();
333 
338  public: void PublishModelPose(physics::ModelPtr _model);
339 
344  public: void PublishModelScale(physics::ModelPtr _model);
345 
350  public: void PublishLightPose(const physics::LightPtr _light);
351 
354  public: uint32_t GetIterations() const;
355 
358  public: msgs::Scene GetSceneMsg() const;
359 
364  public: void RunBlocking(unsigned int _iterations = 0);
365 
370  public: void RemoveModel(ModelPtr _model);
371 
376  public: void RemoveModel(const std::string &_name);
377 
380  public: void ResetPhysicsStates();
381 
388  public: void _AddDirty(Entity *_entity);
389 
392  public: bool SensorsInitialized() const;
393 
398  public: void _SetSensorsInitialized(const bool _init);
399 
407  private: ModelPtr GetModelById(unsigned int _id);
409 
413  private: void LoadPlugins();
414 
418  private: void LoadEntities(sdf::ElementPtr _sdf, BasePtr _parent);
419 
424  private: ModelPtr LoadModel(sdf::ElementPtr _sdf, BasePtr _parent);
425 
430  private: LightPtr LoadLight(const sdf::ElementPtr &_sdf,
431  const BasePtr &_parent);
432 
437  private: ActorPtr LoadActor(sdf::ElementPtr _sdf, BasePtr _parent);
438 
443  private: RoadPtr LoadRoad(sdf::ElementPtr _sdf, BasePtr _parent);
444 
446  private: void RunLoop();
447 
449  private: void Step();
450 
452  private: void LogStep();
453 
455  private: void Update();
456 
459  private: void OnPause(bool _p);
460 
462  private: void OnStep();
463 
466  private: void OnControl(ConstWorldControlPtr &_data);
467 
470  private: void OnPlaybackControl(ConstLogPlaybackControlPtr &_data);
471 
474  private: void OnRequest(ConstRequestPtr &_msg);
475 
480  private: void BuildSceneMsg(msgs::Scene &_scene, BasePtr _entity);
481 
484  private: void JointLog(ConstJointPtr &_msg);
485 
488  private: void OnFactoryMsg(ConstFactoryPtr &_data);
489 
492  private: void OnModelMsg(ConstModelPtr &_msg);
493 
495  private: void ModelUpdateTBB();
496 
498  private: void ModelUpdateSingleLoop();
499 
502  private: void LoadPlugin(sdf::ElementPtr _sdf);
503 
507  private: void FillModelMsg(msgs::Model &_msg, ModelPtr _model);
508 
511  private: void ProcessEntityMsgs();
512 
515  private: void ProcessRequestMsgs();
516 
519  private: void ProcessFactoryMsgs();
520 
523  private: void ProcessModelMsgs();
524 
527  private: void ProcessLightFactoryMsgs();
528 
531  private: void ProcessLightModifyMsgs();
532 
534  private: bool OnLog(std::ostringstream &_stream);
535 
537  private: void ProcessMessages();
538 
540  private: void PublishWorldStats();
541 
543  private: void LogWorker();
544 
550  private: void OnLightMsg(ConstLightPtr &_msg);
551 
555  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
556 
560  private: void OnLightModifyMsg(ConstLightPtr &_msg);
561 
564  private: WorldPrivate *dataPtr;
565 
567  private: friend class DARTLink;
568 
570  private: friend class SimbodyPhysics;
571  };
573  }
574 }
575 #endif
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:72
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:88
A light entity.
Definition: physics/Light.hh:33
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:259
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
Forward declarations for transport.
boost::shared_ptr< Light > LightPtr
Definition: PhysicsTypes.hh:96
default namespace for gazebo
std::vector< LightPtr > Light_V
Definition: PhysicsTypes.hh:212
Private data class for World.
Definition: WorldPrivate.hh:44
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition: PhysicsTypes.hh:116
The world provides access to all other object within a simulated environment.
Definition: World.hh:68
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:80
Simbody physics engine.
Definition: SimbodyPhysics.hh:42
Base class for all physics objects in Gazebo.
Definition: Entity.hh:58
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:84
boost::shared_ptr< Actor > ActorPtr
Definition: PhysicsTypes.hh:92
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:196
Store state information of a physics::World object.
Definition: WorldState.hh:47
boost::shared_ptr< SphericalCoordinates > SphericalCoordinatesPtr
Definition: CommonTypes.hh:140
Base type.
Definition: Base.hh:86
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
boost::shared_ptr< Road > RoadPtr
Definition: PhysicsTypes.hh:152
boost::shared_ptr< PresetManager > PresetManagerPtr
Definition: PhysicsTypes.hh:120