|
MVSim
Lightweight simulator for 2.5D vehicles and robots
|
#include <World.h>


Classes | |
| struct | GeoreferenceOptions |
| struct | GUIKeyEvent |
| 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 > |
| using | ActorList = std::multimap< std::string, HumanActor::Ptr > |
Public Member Functions | |
| void | connectToServer () |
| mvsim::Client & | commsClient () |
| const mvsim::Client & | commsClient () const |
| void | free_opengl_resources () |
| auto & | physical_objects_mtx () |
| bool | headless () const |
| void | headless (bool setHeadless) |
| bool | sensor_has_to_create_egl_context () |
| const std::map< std::string, std::string > & | user_defined_variables () const |
| std::optional< mvsim::TJoyStickEvent > | getJoystickState () const |
| bool | evaluate_tag_if (const rapidxml::xml_node< char > &node) const |
| float | collisionThreshold () const |
| std::set< float > | getElevationsAt (const mrpt::math::TPoint2D &worldXY) const |
| float | getHighestElevationUnder (const mrpt::math::TPoint3Df &queryPt) const |
| void | internal_simul_pre_step_terrain_elevation () |
| std::optional< std::any > | getPropertyAt (const std::string &propertyName, const mrpt::math::TPoint3D &worldXYZ) const |
| const GeoreferenceOptions & | georeferenceOptions () const |
| mrpt::math::TVector3D | worldRenderOffset () const |
| (See docs for worldRenderOffset_) | |
| mrpt::math::TPose3D | applyWorldRenderOffset (mrpt::math::TPose3D p) const |
| mrpt::poses::CPose3D | applyWorldRenderOffset (mrpt::poses::CPose3D p) const |
| void | worldRenderOffsetPropose (const mrpt::math::TVector3D &v) |
| (See docs for worldRenderOffset_) | |
Initialization, simulation set-up | |
| World () | |
| Default ctor: inits an empty world. | |
| ~World () | |
| Dtor. | |
| World (const World &)=delete | |
| World & | operator= (const World &)=delete |
| World (World &&)=delete | |
| World & | operator= (World &&)=delete |
| void | clear_all () |
| void | load_from_XML_file (const std::string &xmlFileNamePath) |
| void | internal_initialize () |
| 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 |
| b2Body * | getBox2DGroundBody () |
| const VehicleList & | getListOfVehicles () const |
| VehicleList & | getListOfVehicles () |
| const BlockList & | getListOfBlocks () const |
| BlockList & | getListOfBlocks () |
| const WorldElementList & | getListOfWorldElements () const |
| const std::vector< WorldJoint > & | getListOfJoints () const |
| const ActorList & | getListOfActors () const |
| ActorList & | getListOfActors () |
| SimulableList & | getListOfSimulableObjects () |
| Always lock/unlock getListOfSimulableObjectsMtx() before using this: | |
| const SimulableList & | getListOfSimulableObjects () const |
| auto & | getListOfSimulableObjectsMtx () |
| mrpt::system::CTimeLogger & | getTimeLogger () |
| std::string | local_to_abs_path (const std::string &in_path) const |
| std::string | xmlPathToActualPath (const std::string &modelURI) const |
Friends | |
| class | VehicleBase |
| class | Block |
Visitors API | |
| using | vehicle_visitor_t = std::function< void(VehicleBase &)> |
| using | world_element_visitor_t = std::function< void(WorldElementBase &)> |
| using | block_visitor_t = std::function< void(Block &)> |
| void | runVisitorOnVehicles (const vehicle_visitor_t &v) |
| void | runVisitorOnWorldElements (const world_element_visitor_t &v) |
| void | runVisitorOnBlocks (const block_visitor_t &v) |
Optional user hooks | |
| using | on_observation_callback_t = std::function< void(const Simulable &, const mrpt::obs::CObservation::Ptr &)> |
| void | registerCallbackOnObservation (const on_observation_callback_t &f) |
| void | dispatchOnObservation (const Simulable &veh, const mrpt::obs::CObservation::Ptr &obs) |
Simulation execution | |
| mrpt::opengl::CSetOfObjects::Ptr | guiUserObjectsPhysical_ |
| mrpt::opengl::CSetOfObjects::Ptr | guiUserObjectsViz_ |
| std::mutex | guiUserObjectsMtx_ |
| std::mutex | pendingRunSensorsOn3DSceneMtx_ |
| bool | pendingRunSensorsOn3DScene_ = false |
| std::string | guiMsgLines_ |
| std::mutex | guiMsgLinesMtx_ |
| std::thread | gui_thread_ |
| std::atomic_bool | gui_thread_running_ = false |
| std::atomic_bool | simulator_must_close_ = false |
| std::mutex | gui_thread_start_mtx_ |
| std::vector< std::function< void(void)> > | guiUserPendingTasks_ |
| std::mutex | guiUserPendingTasksMtx_ |
| GUIKeyEvent | lastKeyEvent_ |
| std::atomic_bool | lastKeyEventValid_ = false |
| std::mutex | lastKeyEventMtx_ |
| double | get_simul_time () const |
| void | force_set_simul_time (double newSimulatedTime) |
| Normally should not be called by users, for internal use only. | |
| mrpt::Clock::time_point | get_simul_timestamp () const |
| double | get_simul_timestep () const |
| Simulation fixed-time interval for numerical integration. | |
| void | set_simul_timestep (double timestep) |
| double | get_gravity () const |
| void | set_gravity (double accel) |
| void | run_simulation (double dt) |
| void | insert_vehicle (const VehicleBase::Ptr &veh) |
| void | update_GUI (TUpdateGUIParams *params=nullptr) |
| const mrpt::gui::CDisplayWindowGUI::Ptr & | gui_window () const |
| const mrpt::math::TPoint3D & | gui_mouse_point () const |
| void | internalGraphicsLoopTasksForSimulation () |
| void | internalRunSensorsOn3DScene (mrpt::opengl::COpenGLScene &physicalObjects) |
| void | internalUpdate3DSceneObjects (mrpt::opengl::COpenGLScene &viz, mrpt::opengl::COpenGLScene &physical) |
| void | internal_GUI_thread () |
| void | internal_process_pending_gui_user_tasks () |
| void | mark_as_pending_running_sensors_on_3D_scene () |
| void | clear_pending_running_sensors_on_3D_scene () |
| bool | pending_running_sensors_on_3D_scene () |
| bool | simulator_must_close () const |
| void | simulator_must_close (bool value) |
| void | enqueue_task_to_run_in_gui_thread (const std::function< void(void)> &f) |
| bool | is_GUI_open () const |
| void | close_GUI () |
| Forces closing the GUI window, if any. | |
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
| using mvsim::World::ActorList = std::multimap<std::string, HumanActor::Ptr> |
Map 'actor-name' => actor object. See getListOfActors()
| using mvsim::World::BlockList = std::multimap<std::string, Block::Ptr> |
Map 'block-name' => block object. See getListOfBlocks()
| using mvsim::World::SimulableList = std::multimap<std::string, Simulable::Ptr> |
For convenience, all elements (vehicles, world elements, blocks) are also stored here for each look-up by name
| using mvsim::World::VehicleList = std::multimap<std::string, VehicleBase::Ptr> |
Map 'vehicle-name' => vehicle object. See getListOfVehicles()
| using mvsim::World::WorldElementList = std::list<WorldElementBase::Ptr> |
See getListOfWorldElements()
| void mvsim::World::clear_all | ( | ) |
Resets the entire simulation environment to an empty world.
| void mvsim::World::connectToServer | ( | ) |
Connect to server, advertise topics and services, etc. per the world description loaded from XML file.
| void mvsim::World::dispatchOnObservation | ( | const Simulable & | veh, |
| const mrpt::obs::CObservation::Ptr & | obs | ||
| ) |
Calls all registered callbacks:
|
inline |
Gravity acceleration (Default=9.8 m/s^2). Used to evaluate weights for friction, etc.
|
inline |
Seconds since start of simulation.
|
inline |
Get the current simulation full timestamp, computed as the real wall clock timestamp at the beginning of the simulation, plus the number of seconds simulation has run.
| std::set<float> mvsim::World::getElevationsAt | ( | const mrpt::math::TPoint2D & | worldXY | ) | const |
Returns the list of "z" coordinate or "elevations" for all simulable objects at a given world-frame 2D coordinates (x,y). If no object reports any height, the value "0.0" will be always reported by default. In multistorey worlds, for example, this will return the height of each floor for the queried point.
| float mvsim::World::getHighestElevationUnder | ( | const mrpt::math::TPoint3Df & | queryPt | ) | const |
with query points the center of a wheel, this returns the highest "ground" under it, or .0 if nothing found.
| std::optional<mvsim::TJoyStickEvent> mvsim::World::getJoystickState | ( | ) | const |
If joystick usage is enabled (via XML file option, for example), this will read the joystick state and return it. Otherwise (or on device error or disconnection), a null optional variable is returned.
| std::optional<std::any> mvsim::World::getPropertyAt | ( | const std::string & | propertyName, |
| const mrpt::math::TPoint3D & | worldXYZ | ||
| ) | const |
Query all mvsim::WorldElementBase objects for a given custom property at the specific 3D location. It returns nullopt if no object defines this property.
| void mvsim::World::internalGraphicsLoopTasksForSimulation | ( | ) |
Update 3D vehicles, sensors, run render-based sensors, etc: Called from World_gui thread in normal mode, or mvsim-cli in headless mode.
| bool mvsim::World::is_GUI_open | ( | ) | const |
Return true if the GUI window is open, after a previous call to update_GUI()
| void mvsim::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.
| [in] | fileNameForPath | Optionally, provide the full path to an XML file from which to take relative paths. |
| std::exception | On any error, with what() giving a descriptive error message |
| void mvsim::World::load_from_XML_file | ( | const std::string & | xmlFileNamePath | ) |
Load an entire world description into this object from a specification in XML format.
| [in] | xmlFileNamePath | The relative or full path to the XML file. |
| std::exception | On any error, with what() giving a descriptive error message |
| std::string mvsim::World::local_to_abs_path | ( | const std::string & | in_path | ) | const |
Replace macros, prefix the base_path if input filename is relative, etc.
| void mvsim::World::run_simulation | ( | double | dt | ) |
Runs the simulation for a given time interval (in seconds)
| void mvsim::World::runVisitorOnBlocks | ( | const block_visitor_t & | v | ) |
Run the user-provided visitor on each world block
| void mvsim::World::runVisitorOnVehicles | ( | const vehicle_visitor_t & | v | ) |
Run the user-provided visitor on each vehicle
| void mvsim::World::runVisitorOnWorldElements | ( | const world_element_visitor_t & | v | ) |
Run the user-provided visitor on each world element
|
inline |
Gravity acceleration (Default=9.8 m/s^2). Used to evaluate weights for friction, etc.
|
inline |
Simulation fixed-time interval for numerical integration 0 means auto-determine as the minimum of 50 ms and the shortest sensor sample period.
| void mvsim::World::update_GUI | ( | TUpdateGUIParams * | params = nullptr | ) |
Updates (or sets-up upon first call) the GUI visualization of the scene.
| [in,out] | params | Optional inputs/outputs to the GUI update process. See struct for details. |
| std::string mvsim::World::xmlPathToActualPath | ( | const std::string & | modelURI | ) | const |
Parses URIs in all the forms explained in RemoteResourcesManager::resolve_path(), then passes it through local_to_abs_path().
| mrpt::opengl::CSetOfObjects::Ptr mvsim::World::guiUserObjectsPhysical_ |
If !=null, a set of objects to be rendered merged with the default visualization. Lock the mutex gui_user_objects_mtx_ while writing. There are two sets of objects: "viz" for visualization only, "physical" for objects which should be detected by sensors.