World.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 #include <vector>
21 #include <list>
22 #include <set>
23 #include <deque>
24 #include <string>
25 #include <boost/thread.hpp>
26 #include <boost/enable_shared_from_this.hpp>
27 #include <boost/shared_ptr.hpp>
28 
29 #include <sdf/sdf.hh>
30 
32 
33 #include "gazebo/msgs/msgs.hh"
34 
37 #include "gazebo/common/Event.hh"
38 
39 #include "gazebo/physics/Base.hh"
42 #include "gazebo/util/system.hh"
43 
44 namespace gazebo
45 {
46  namespace physics
47  {
49  class WorldPrivate;
50 
53 
62  class GAZEBO_VISIBLE World : public boost::enable_shared_from_this<World>
63  {
67  public: explicit World(const std::string &_name = "");
68 
70  public: ~World();
71 
75  public: void Load(sdf::ElementPtr _sdf);
76 
80  public: void Save(const std::string &_filename);
81 
84  public: void Init();
85 
90  public: void Run(unsigned int _iterations = 0);
91 
94  public: bool GetRunning() const;
95 
98  public: void Stop();
99 
102  public: void Fini();
103 
107  public: void Clear();
108 
111  public: std::string GetName() const;
112 
116  public: PhysicsEnginePtr GetPhysicsEngine() const;
117 
120  public: common::SphericalCoordinatesPtr GetSphericalCoordinates() const;
121 
124  public: unsigned int GetModelCount() const;
125 
131  public: ModelPtr GetModel(unsigned int _index) const;
132 
135  public: Model_V GetModels() const;
136 
141  public: void ResetEntities(Base::EntityType _type = Base::BASE);
142 
144  public: void ResetTime();
145 
147  public: void Reset();
148 
151  public: void PrintEntityTree();
152 
156  public: common::Time GetSimTime() const;
157 
160  public: void SetSimTime(const common::Time &_t);
161 
164  public: common::Time GetPauseTime() const;
165 
168  public: common::Time GetStartTime() const;
169 
172  public: common::Time GetRealTime() const;
173 
176  public: bool IsPaused() const;
177 
180  public: void SetPaused(bool _p);
181 
187  public: BasePtr GetByName(const std::string &_name);
188 
194  public: ModelPtr GetModel(const std::string &_name);
195 
201  public: EntityPtr GetEntity(const std::string &_name);
202 
210  public: ModelPtr GetModelBelowPoint(const math::Vector3 &_pt);
211 
217  public: EntityPtr GetEntityBelowPoint(const math::Vector3 &_pt);
218 
221  public: void SetState(const WorldState &_state);
222 
226  public: void InsertModelFile(const std::string &_sdfFilename);
227 
231  public: void InsertModelString(const std::string &_sdfString);
232 
236  public: void InsertModelSDF(const sdf::SDF &_sdf);
237 
241  public: std::string StripWorldName(const std::string &_name) const;
242 
246  public: void EnableAllModels();
247 
251  public: void DisableAllModels();
252 
255  public: void Step(unsigned int _steps);
256 
261  public: void LoadPlugin(const std::string &_filename,
262  const std::string &_name,
263  sdf::ElementPtr _sdf);
264 
267  public: void RemovePlugin(const std::string &_name);
268 
271  public: boost::mutex *GetSetWorldPoseMutex() const;
272 
275  public: bool GetEnablePhysicsEngine();
276 
279  public: void EnablePhysicsEngine(bool _enable);
280 
282  public: void UpdateStateSDF();
283 
286  public: bool IsLoaded() const;
287 
290  public: void ClearModels();
291 
296  public: void PublishModelPose(physics::ModelPtr _model);
297 
300  public: uint32_t GetIterations() const;
301 
304  public: msgs::Scene GetSceneMsg() const;
305 
310  public: void RunBlocking(unsigned int _iterations = 0);
311 
316  public: void RemoveModel(ModelPtr _model);
317 
322  public: void RemoveModel(const std::string &_name);
323 
331  private: ModelPtr GetModelById(unsigned int _id);
333 
337  private: void LoadPlugins();
338 
342  private: void LoadEntities(sdf::ElementPtr _sdf, BasePtr _parent);
343 
348  private: ModelPtr LoadModel(sdf::ElementPtr _sdf, BasePtr _parent);
349 
354  private: ActorPtr LoadActor(sdf::ElementPtr _sdf, BasePtr _parent);
355 
360  private: RoadPtr LoadRoad(sdf::ElementPtr _sdf, BasePtr _parent);
361 
363  private: void RunLoop();
364 
366  private: void Step();
367 
369  private: void LogStep();
370 
372  private: void Update();
373 
376  private: void OnPause(bool _p);
377 
379  private: void OnStep();
380 
383  private: void OnControl(ConstWorldControlPtr &_data);
384 
387  private: void OnRequest(ConstRequestPtr &_msg);
388 
393  private: void BuildSceneMsg(msgs::Scene &_scene, BasePtr _entity);
394 
397  private: void JointLog(ConstJointPtr &_msg);
398 
401  private: void OnFactoryMsg(ConstFactoryPtr &_data);
402 
405  private: void OnModelMsg(ConstModelPtr &_msg);
406 
408  private: void ModelUpdateTBB();
409 
411  private: void ModelUpdateSingleLoop();
412 
415  private: void LoadPlugin(sdf::ElementPtr _sdf);
416 
420  private: void FillModelMsg(msgs::Model &_msg, ModelPtr _model);
421 
424  private: void ProcessEntityMsgs();
425 
428  private: void ProcessRequestMsgs();
429 
432  private: void ProcessFactoryMsgs();
433 
436  private: void ProcessModelMsgs();
437 
439  private: bool OnLog(std::ostringstream &_stream);
440 
442  private: void ProcessMessages();
443 
445  private: void PublishWorldStats();
446 
448  private: void LogWorker();
449 
452  private: void OnLightMsg(ConstLightPtr &_msg);
453 
456  private: WorldPrivate *dataPtr;
457 
459  private: friend class ODELink;
460 
462  private: friend class DARTLink;
463 
465  private: friend class SimbodyPhysics;
466  };
468  }
469 }
470 #endif
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
Forward declarations for transport.
default namespace for gazebo
Private data class for World.
Definition: WorldPrivate.hh:43
boost::shared_ptr< PhysicsEngine > PhysicsEnginePtr
Definition: PhysicsTypes.hh:106
The world provides access to all other object within a simulated environment.
Definition: World.hh:62
boost::shared_ptr< Entity > EntityPtr
Definition: PhysicsTypes.hh:74
Simbody physics engine.
Definition: SimbodyPhysics.hh:42
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.
std::vector< ModelPtr > Model_V
Definition: PhysicsTypes.hh:170
Store state information of a physics::World object.
Definition: WorldState.hh:46
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
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
boost::shared_ptr< Road > RoadPtr
Definition: PhysicsTypes.hh:130