World.h
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014 Jose Luis Blanco Claraco (University of Almeria) |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under GNU General Public License version 3 |
7  | See <http://www.gnu.org/licenses/> |
8  +-------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mvsim/VehicleBase.h>
14 #include <mvsim/Block.h>
15 
16 #include <mrpt/gui/CDisplayWindow3D.h>
17 
18 #include <mrpt/version.h>
19 #if MRPT_VERSION<0x199
20 #include <mrpt/utils/utils_defs.h> // mrpt::format()
21 #include <mrpt/utils/CTimeLogger.h>
22 #include <mrpt/utils/CTicTac.h>
23 #include <mrpt/utils/TColor.h>
24 using mrpt::utils::CTicTac;
25 using mrpt::utils::CTimeLogger;
26 using mrpt::utils::CTimeLoggerEntry;
27 using mrpt::utils::TColor;
28 using mrpt::utils::TColorf;
29 using mrpt::utils::keep_max;
30 using mrpt::utils::DEG2RAD;
31 using mrpt::utils::RAD2DEG;
32 #else
33 #include <mrpt/core/format.h>
34 #include <mrpt/core/bits_math.h>
35 #include <mrpt/system/CTimeLogger.h>
36 #include <mrpt/system/CTicTac.h>
37 #include <mrpt/img/TColor.h>
38 using mrpt::system::CTicTac;
39 using mrpt::system::CTimeLogger;
40 using mrpt::system::CTimeLoggerEntry;
41 using mrpt::img::TColor;
42 using mrpt::img::TColorf;
43 using mrpt::keep_max;
44 using mrpt::DEG2RAD;
45 using mrpt::RAD2DEG;
46 #endif
47 
48 #include <mrpt/version.h>
49 #if MRPT_VERSION >= 0x130
50 #include <mrpt/obs/CObservation.h>
51 #else
52 #include <mrpt/slam/CObservation.h>
53 #endif
54 
55 #include <Box2D/Dynamics/b2World.h>
56 #include <Box2D/Dynamics/b2Body.h>
57 
58 #include <list>
59 
60 namespace mvsim
61 {
67 class World
68 {
69  public:
72  World();
73  ~World();
74 
75  void clear_all(bool acquire_mt_lock = true);
76 
91  void load_from_XML(
92  const std::string& xml_text,
93  const std::string& fileNameForPath = std::string("."));
99  double get_simul_time() const
100  {
101  return m_simul_time;
102  }
103 
104  double get_simul_timestep() const
105  {
106  return m_simul_timestep;
107  }
108  void set_simul_timestep(double timestep)
109  {
110  m_simul_timestep = timestep;
111  }
112 
113  double get_gravity() const
114  {
115  return m_gravity;
116  }
117  void set_gravity(double accel)
119  {
120  m_gravity = accel;
121  }
122 
129  void run_simulation(double dt);
130 
133  {
134  int keycode;
135  mrpt::gui::mrptKeyModifier key_modifier;
136 
137  TGUIKeyEvent() : keycode(0) {}
138  };
139 
141  {
143  std::string msg_lines;
144 
146  };
147 
155  void update_GUI(TUpdateGUIParams* params = NULL);
156 
157  bool is_GUI_open() const;
158 
160  void close_GUI();
161 
166  typedef std::multimap<std::string, VehicleBase*>
168  typedef std::list<WorldElementBase*>
171  typedef std::multimap<std::string, Block*>
173 
179  const b2World* getBox2DWorld() const { return m_box2d_world; }
181  const TListVehicles& getListOfVehicles() const { return m_vehicles; }
183  const TListBlocks& getListOfBlocks() const { return m_blocks; }
186  {
187  return m_world_elements;
188  }
189 
190  CTimeLogger& getTimeLogger() { return m_timlogger; }
193  std::string resolvePath(const std::string& in_path) const;
194 
201  {
202  virtual void visit(VehicleBase* obj) = 0;
203  };
206  {
207  virtual void visit(WorldElementBase* obj) = 0;
208  };
209 
212 
215 
220  virtual void onNewObservation(
221  const VehicleBase& veh,
222 #if MRPT_VERSION >= 0x130
223  const mrpt::obs::CObservation* obs
224 #else
225  const mrpt::slam::CObservation* obs
226 #endif
227  )
228  {
229  /* default: do nothing */
230  }
233  private:
234  friend class VehicleBase;
235  friend class Block;
236 
237  // -------- World Params ----------
238  double m_gravity;
239  double m_simul_time;
241  double m_simul_timestep;
244  int m_b2d_vel_iters,
247  std::string m_base_path;
248 
249  // ------- GUI options -----
251  {
252  unsigned int win_w, win_h;
253  bool ortho;
255  double force_scale;
257  double fov_deg;
258  std::string
260 
261  TGUI_Options();
262  void parse_from(const rapidxml::xml_node<char>& node);
263  };
264 
266 
268  // -------- World contents ----------
269  std::mutex m_world_cs;
270 
273  b2Body*
275 
279 
281  void internal_one_timestep(double dt);
282 
283  // -------- GUI stuff ----------
284  mrpt::gui::CDisplayWindow3D::Ptr m_gui_win;
285 
286  CTimeLogger m_timlogger;
288 };
289 }
std::list< WorldElementBase * > TListWorldElements
getListOfVehicles()
Definition: World.h:170
double force_scale
In meters/Newton.
Definition: World.h:255
mrpt::gui::CDisplayWindow3D::Ptr m_gui_win
Definition: World.h:284
const TListBlocks & getListOfBlocks() const
Definition: World.h:183
void set_simul_timestep(double timestep)
Simulation fixed-time interval for numerical integration.
Definition: World.h:108
int m_b2d_pos_iters
Velocity and position iteration count (Box2D)
Definition: World.h:245
TListWorldElements m_world_elements
Definition: World.h:277
void update_GUI(TUpdateGUIParams *params=NULL)
Definition: World_gui.cpp:68
~World()
Dtor.
Definition: World.cpp:35
TListVehicles & getListOfVehicles()
Definition: World.h:182
CTicTac m_timer_iteration
Definition: World.h:287
double m_simul_time
evaluate weights for friction, etc.
Definition: World.h:240
TListVehicles m_vehicles
Definition: World.h:276
void runVisitorOnWorldElements(WorldElementVisitorBase &v)
Definition: World.cpp:248
std::multimap< std::string, VehicleBase * > TListVehicles
Definition: World.h:167
void clear_all(bool acquire_mt_lock=true)
Definition: World.cpp:43
std::string follow_vehicle
Name of the vehicle to follow (empty=none)
Definition: World.h:259
virtual void onNewObservation(const VehicleBase &veh, const mrpt::slam::CObservation *obs)
Definition: World.h:220
void internal_one_timestep(double dt)
Definition: World.cpp:109
TGUIKeyEvent keyevent
Keystrokes in the window are returned here.
Definition: World.h:142
double get_gravity() const
Definition: World.h:113
const b2World * getBox2DWorld() const
Definition: World.h:179
double get_simul_timestep() const
Simulation fixed-time interval for numerical integration.
Definition: World.h:104
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
void set_gravity(double accel)
Definition: World.h:118
CTimeLogger & getTimeLogger()
Definition: World.h:190
TListBlocks m_blocks
Definition: World.h:278
TListBlocks & getListOfBlocks()
Definition: World.h:184
CTimeLogger m_timlogger
Definition: World.h:286
bool is_GUI_open() const
Forces closing the GUI window, if any.
Definition: World_gui.cpp:61
std::string resolvePath(const std::string &in_path) const
Definition: World.cpp:210
std::mutex m_world_cs
first time the GUI window is created.
Definition: World.h:269
b2Body * m_b2_ground_body
Used to declare friction between vehicles-ground.
Definition: World.h:274
std::multimap< std::string, Block * > TListBlocks
Definition: World.h:172
TGUI_Options m_gui_options
Definition: World.h:265
unsigned int win_w
Definition: World.h:252
std::string msg_lines
Messages to show.
Definition: World.h:143
void load_from_XML(const std::string &xml_text, const std::string &fileNameForPath=std::string("."))
int m_b2d_vel_iters
integration.
Definition: World.h:245
mrpt::gui::mrptKeyModifier key_modifier
Definition: World.h:135
b2Body * getBox2DGroundBody()
Definition: World.h:180
const TListVehicles & getListOfVehicles() const
Definition: World.h:181
double m_simul_timestep
Definition: World.h:243
void runVisitorOnVehicles(VehicleVisitorBase &v)
Definition: World.cpp:240
b2World * getBox2DWorld()
Definition: World.h:178
World()
Default ctor: inits an empty world.
Definition: World.cpp:22
void run_simulation(double dt)
Definition: World.cpp:89
std::string m_base_path
Path from which to take relative directories.
Definition: World.h:247
const TListWorldElements & getListOfWorldElements() const
Definition: World.h:185
b2World * m_box2d_world
objects from multithreading access.
Definition: World.h:272
double m_gravity
Definition: World.h:238
double get_simul_time() const
Simulation wall-clock time.
Definition: World.h:99
int keycode
0=no Key. Otherwise, ASCII code.
Definition: World.h:134
void close_GUI()
a previous call to update_GUI()
Definition: World_gui.cpp:63


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40