Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
mvsim::World Class Reference

#include <World.h>

Inheritance diagram for mvsim::World:
Inheritance graph
[legend]

Classes

struct  GUI
 
struct  TGUI_Options
 
struct  TGUIKeyEvent
 
struct  TUpdateGUIParams
 

Public Types

Public types
using VehicleList = std::multimap< std::string, VehicleBase::Ptr >
 
using WorldElementList = std::list< WorldElementBase::Ptr >
 
using BlockList = std::multimap< std::string, Block::Ptr >
 
using SimulableList = std::multimap< std::string, Simulable::Ptr >
 

Public Member Functions

mvsim::ClientcommsClient ()
 
const mvsim::ClientcommsClient () const
 
void connectToServer ()
 
Initialization, simulation set-up
 World ()
 Default ctor: inits an empty world. More...
 
 ~World ()
 Dtor. More...
 
void clear_all ()
 
void load_from_XML (const std::string &xml_text, const std::string &fileNameForPath=std::string("."))
 
Access inner working objects
std::unique_ptr< b2World > & getBox2DWorld ()
 
const std::unique_ptr< b2World > & getBox2DWorld () const
 
b2BodygetBox2DGroundBody ()
 
const VehicleListgetListOfVehicles () const
 
VehicleListgetListOfVehicles ()
 
const BlockListgetListOfBlocks () const
 
BlockListgetListOfBlocks ()
 
const WorldElementListgetListOfWorldElements () const
 
SimulableListgetListOfSimulableObjects ()
 
const SimulableListgetListOfSimulableObjects () const
 
mrpt::system::CTimeLogger & getTimeLogger ()
 
std::string resolvePath (const std::string &in_path) const
 
std::string xmlPathToActualPath (const std::string &modelURI) const
 
Optional user hooks
virtual void onNewObservation ([[maybe_unused]] const VehicleBase &veh, [[maybe_unused]] const mrpt::obs::CObservation *obs)
 

Private Member Functions

void insertBlock (const Block::Ptr &block)
 
void internal_one_timestep (double dt)
 
void process_load_walls (const rapidxml::xml_node< char > &node)
 

Private Attributes

b2Bodym_b2_ground_body = nullptr
 
int m_b2d_pos_iters = 3
 
int m_b2d_vel_iters = 6
 
std::string m_base_path {"."}
 
BlockList m_blocks
 
std::unique_ptr< b2Worldm_box2d_world
 
mvsim::Client m_client {"World"}
 
double m_gravity = 9.81
 
GUI m_gui {*this}
 gui state More...
 
TGUI_Options m_gui_options
 
const TParameterDefinitions m_other_world_params
 
double m_simul_time = 0
 
double m_simul_timestep = 10e-3
 
SimulableList m_simulableObjects
 
std::mutex m_simulationStepRunningMtx
 
mrpt::system::CTicTac m_timer_iteration
 
mrpt::system::CTimeLogger m_timlogger
 
VehicleList m_vehicles
 
std::recursive_mutex m_world_cs
 first time the GUI window is created. More...
 
WorldElementList m_world_elements
 

Friends

class Block
 
class VehicleBase
 

Simulation execution

std::string m_gui_msg_lines
 
std::mutex m_gui_msg_lines_mtx
 
std::thread m_gui_thread
 
std::atomic_bool m_gui_thread_running = false
 
std::atomic_bool m_gui_thread_must_close = false
 
std::mutex m_gui_thread_start_mtx
 
std::vector< std::function< void(void)> > m_gui_user_pending_tasks
 
std::mutex m_gui_user_pending_tasks_mtx
 
TGUIKeyEvent m_lastKeyEvent
 
std::atomic_bool m_lastKeyEventValid = false
 
std::mutex m_lastKeyEvent_mtx
 
double get_simul_time () const
 Simulation wall-clock time. More...
 
double get_simul_timestep () const
 Simulation fixed-time interval for numerical integration. More...
 
void set_simul_timestep (double timestep)
 Simulation fixed-time interval for numerical integration. More...
 
double get_gravity () const
 
void set_gravity (double accel)
 
void run_simulation (double dt)
 
void update_GUI (TUpdateGUIParams *params=nullptr)
 
const mrpt::gui::CDisplayWindowGUI::Ptr & gui_window () const
 
void internalUpdate3DSceneObjects (mrpt::opengl::COpenGLScene::Ptr &gl_scene)
 
void internal_GUI_thread ()
 
void internal_process_pending_gui_user_tasks ()
 
void enqueue_task_to_run_in_gui_thread (const std::function< void(void)> &f)
 
bool is_GUI_open () const
 Forces closing the GUI window, if any. More...
 
void close_GUI ()
 a previous call to update_GUI() More...
 

Visitors API

using vehicle_visitor_t = std::function< void(VehicleBase &)>
 
using world_element_visitor_t = std::function< void(WorldElementBase &)>
 
void runVisitorOnVehicles (const vehicle_visitor_t &v)
 
void runVisitorOnWorldElements (const world_element_visitor_t &v)
 

Detailed Description

Simulation happens inside a World object. This is the central class for usage from user code, running the simulation, loading XML models, managing GUI visualization, etc. The ROS node acts as a bridge between this class and the ROS subsystem.

See: https://mvsimulator.readthedocs.io/en/latest/world.html

Definition at line 41 of file World.h.

Member Typedef Documentation

Map 'block-name' => block object. See getListOfBlocks()

Definition at line 179 of file World.h.

For convenience, all elements (vehicles, world elements, blocks) are also stored here for each look-up by name

Definition at line 183 of file World.h.

Definition at line 222 of file World.h.

Map 'vehicle-name' => vehicle object. See getListOfVehicles()

Definition at line 173 of file World.h.

Definition at line 223 of file World.h.

See getListOfWorldElements()

Definition at line 176 of file World.h.

Constructor & Destructor Documentation

World::World ( )

Default ctor: inits an empty world.

Definition at line 27 of file World.cpp.

World::~World ( )

Dtor.

Definition at line 33 of file World.cpp.

Member Function Documentation

void World::clear_all ( )

Resets the entire simulation environment to an empty world.

Definition at line 48 of file World.cpp.

void World::close_GUI ( )

a previous call to update_GUI()

Forces closing the GUI window, if any.

Definition at line 44 of file World_gui.cpp.

mvsim::Client& mvsim::World::commsClient ( )
inline

Definition at line 247 of file World.h.

const mvsim::Client& mvsim::World::commsClient ( ) const
inline

Definition at line 248 of file World.h.

void World::connectToServer ( )

Connect to server, advertise topics and services, etc. per the world description loaded from XML file.

Definition at line 205 of file World.cpp.

void mvsim::World::enqueue_task_to_run_in_gui_thread ( const std::function< void(void)> &  f)
inline

Definition at line 148 of file World.h.

double mvsim::World::get_gravity ( ) const
inline

Gravity acceleration (Default=9.8 m/s^2). Used to evaluate weights for friction, etc.

Definition at line 82 of file World.h.

double mvsim::World::get_simul_time ( ) const
inline

Simulation wall-clock time.

Definition at line 68 of file World.h.

double mvsim::World::get_simul_timestep ( ) const
inline

Simulation fixed-time interval for numerical integration.

Definition at line 73 of file World.h.

b2Body* mvsim::World::getBox2DGroundBody ( )
inline

Definition at line 194 of file World.h.

std::unique_ptr<b2World>& mvsim::World::getBox2DWorld ( )
inline

Definition at line 189 of file World.h.

const std::unique_ptr<b2World>& mvsim::World::getBox2DWorld ( ) const
inline

Definition at line 190 of file World.h.

const BlockList& mvsim::World::getListOfBlocks ( ) const
inline

Definition at line 197 of file World.h.

BlockList& mvsim::World::getListOfBlocks ( )
inline

Definition at line 198 of file World.h.

SimulableList& mvsim::World::getListOfSimulableObjects ( )
inline

Definition at line 204 of file World.h.

const SimulableList& mvsim::World::getListOfSimulableObjects ( ) const
inline

Definition at line 205 of file World.h.

const VehicleList& mvsim::World::getListOfVehicles ( ) const
inline

Definition at line 195 of file World.h.

VehicleList& mvsim::World::getListOfVehicles ( )
inline

Definition at line 196 of file World.h.

const WorldElementList& mvsim::World::getListOfWorldElements ( ) const
inline

Definition at line 199 of file World.h.

mrpt::system::CTimeLogger& mvsim::World::getTimeLogger ( )
inline

Definition at line 210 of file World.h.

const mrpt::gui::CDisplayWindowGUI::Ptr& mvsim::World::gui_window ( ) const
inline

Definition at line 129 of file World.h.

void World::insertBlock ( const Block::Ptr block)
private

Definition at line 311 of file World.cpp.

void World::internal_GUI_thread ( )

Definition at line 339 of file World_gui.cpp.

void World::internal_one_timestep ( double  dt)
private

Runs one individual time step

Definition at line 97 of file World.cpp.

void World::internal_process_pending_gui_user_tasks ( )

Definition at line 536 of file World_gui.cpp.

void World::internalUpdate3DSceneObjects ( mrpt::opengl::COpenGLScene::Ptr &  gl_scene)

Definition at line 549 of file World_gui.cpp.

bool World::is_GUI_open ( ) const

Forces closing the GUI window, if any.

Return true if the GUI window is open, after

Definition at line 42 of file World_gui.cpp.

void World::load_from_XML ( const std::string xml_text,
const std::string fileNameForPath = std::string(".") 
)

Load an entire world description into this object from a specification in XML format.

Parameters
[in]fileNameForPathOptionally, provide the full path to an XML file from which to take relative paths.
Exceptions
std::exceptionOn any error, with what() giving a descriptive error message

Definition at line 28 of file World_load_xml.cpp.

virtual void mvsim::World::onNewObservation ( [[maybe_unused] ] const VehicleBase veh,
[[maybe_unused] ] const mrpt::obs::CObservation obs 
)
inlinevirtual

Definition at line 235 of file World.h.

void World::process_load_walls ( const rapidxml::xml_node< char > &  node)
private

Definition at line 122 of file World_walls.cpp.

std::string World::resolvePath ( const std::string s_in) const

Replace macros, prefix the base_path if input filename is relative, etc.

Definition at line 162 of file World.cpp.

void World::run_simulation ( double  dt)

Runs the simulation for a given time interval (in seconds)

Note
The minimum simulation time is the timestep set (e.g. via set_simul_timestep()), even if time advanced further than the provided "dt".

Runs the simulation for a given time interval (in seconds)

Definition at line 71 of file World.cpp.

void World::runVisitorOnVehicles ( const vehicle_visitor_t v)

Run the user-provided visitor on each vehicle

Definition at line 192 of file World.cpp.

void World::runVisitorOnWorldElements ( const world_element_visitor_t v)

Run the user-provided visitor on each world element

Definition at line 199 of file World.cpp.

void mvsim::World::set_gravity ( double  accel)
inline

Gravity acceleration (Default=9.8 m/s^2). Used to evaluate weights for friction, etc.

Definition at line 87 of file World.h.

void mvsim::World::set_simul_timestep ( double  timestep)
inline

Simulation fixed-time interval for numerical integration.

Definition at line 77 of file World.h.

void World::update_GUI ( TUpdateGUIParams params = nullptr)

Updates (or sets-up upon first call) the GUI visualization of the scene.

Parameters
[in,out]paramsOptional inputs/outputs to the GUI update process. See struct for details.
Note
This method is prepared to be called concurrently with the simulation, and doing so is recommended to assure a smooth multi-threading simulation.

Definition at line 633 of file World_gui.cpp.

std::string World::xmlPathToActualPath ( const std::string modelURI) const

Definition at line 140 of file World.cpp.

Friends And Related Function Documentation

friend class Block
friend

Definition at line 252 of file World.h.

friend class VehicleBase
friend

Definition at line 251 of file World.h.

Member Data Documentation

b2Body* mvsim::World::m_b2_ground_body = nullptr
private

Used to declare friction between vehicles-ground

Definition at line 322 of file World.h.

int mvsim::World::m_b2d_pos_iters = 3
private

Definition at line 265 of file World.h.

int mvsim::World::m_b2d_vel_iters = 6
private

Velocity and position iteration count (refer to libbox2d docs)

Definition at line 265 of file World.h.

std::string mvsim::World::m_base_path {"."}
private

Path from which to take relative directories.

Definition at line 279 of file World.h.

BlockList mvsim::World::m_blocks
private

Definition at line 326 of file World.h.

std::unique_ptr<b2World> mvsim::World::m_box2d_world
private

Box2D dynamic simulator instance

Definition at line 319 of file World.h.

mvsim::Client mvsim::World::m_client {"World"}
private

Definition at line 254 of file World.h.

double mvsim::World::m_gravity = 9.81
private

Gravity acceleration (Default=9.8 m/s^2). Used to evaluate weights for friction, etc.

Definition at line 259 of file World.h.

GUI mvsim::World::m_gui {*this}
private

gui state

Definition at line 371 of file World.h.

std::string mvsim::World::m_gui_msg_lines

Definition at line 139 of file World.h.

std::mutex mvsim::World::m_gui_msg_lines_mtx

Definition at line 140 of file World.h.

TGUI_Options mvsim::World::m_gui_options
private

Some of these options are only used the

Definition at line 311 of file World.h.

std::thread mvsim::World::m_gui_thread

Definition at line 142 of file World.h.

std::atomic_bool mvsim::World::m_gui_thread_must_close = false

Definition at line 145 of file World.h.

std::atomic_bool mvsim::World::m_gui_thread_running = false

Definition at line 144 of file World.h.

std::mutex mvsim::World::m_gui_thread_start_mtx

Definition at line 146 of file World.h.

std::vector<std::function<void(void)> > mvsim::World::m_gui_user_pending_tasks

Definition at line 155 of file World.h.

std::mutex mvsim::World::m_gui_user_pending_tasks_mtx

Definition at line 156 of file World.h.

TGUIKeyEvent mvsim::World::m_lastKeyEvent

Definition at line 158 of file World.h.

std::mutex mvsim::World::m_lastKeyEvent_mtx

Definition at line 160 of file World.h.

std::atomic_bool mvsim::World::m_lastKeyEventValid = false

Definition at line 159 of file World.h.

const TParameterDefinitions mvsim::World::m_other_world_params
private
Initial value:
= {
{"gravity", {"%lf", &m_gravity}},
{"simul_timestep", {"%lf", &m_simul_timestep}},
{"b2d_vel_iters", {"%i", &m_b2d_vel_iters}},
{"b2d_pos_iters", {"%i", &m_b2d_pos_iters}},
}

Definition at line 267 of file World.h.

double mvsim::World::m_simul_time = 0
private

In seconds, real simulation time since beginning (may be different than wall-clock time because of time warp, etc.)

Definition at line 276 of file World.h.

double mvsim::World::m_simul_timestep = 10e-3
private

Simulation fixed-time interval for numerical integration.

Definition at line 262 of file World.h.

SimulableList mvsim::World::m_simulableObjects
private

Definition at line 331 of file World.h.

std::mutex mvsim::World::m_simulationStepRunningMtx
private

Definition at line 336 of file World.h.

mrpt::system::CTicTac mvsim::World::m_timer_iteration
private

Definition at line 376 of file World.h.

mrpt::system::CTimeLogger mvsim::World::m_timlogger
private

Definition at line 375 of file World.h.

VehicleList mvsim::World::m_vehicles
private

Definition at line 324 of file World.h.

std::recursive_mutex mvsim::World::m_world_cs
private

first time the GUI window is created.

Mutex protecting simulation objects from multi-thread access

Definition at line 316 of file World.h.

WorldElementList mvsim::World::m_world_elements
private

Definition at line 325 of file World.h.


The documentation for this class was generated from the following files:


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:52