Pogosim
Loading...
Searching...
No Matches
Simulation Class Reference

Class representing the simulation environment. More...

#include <simulator.h>

Public Member Functions

 Simulation (Configuration &_config)
 Constructs a Simulation object.
virtual ~Simulation ()
 Destructor.
void init_all ()
 Initializes the simulation components.
void create_robots ()
 Creates the robot instances.
void create_objects ()
 Creates objects in the simulation.
void create_arena ()
 Creates the arena from a CSV file.
void create_walls ()
 Creates arena walls.
void init_box2d ()
 Initializes the Box2D world.
void init_config ()
 Initializes the simulation configuration.
void init_SDL ()
 Initializes SDL and related subsystems.
void speed_up ()
 Speeds up the simulation GUI.
void speed_down ()
 Slows down the simulation GUI.
void pause ()
 Toggles the simulation pause state.
void help_message ()
 Displays a help message with GUI keyboard shortcuts.
void handle_SDL_events ()
 Handles SDL events.
void compute_neighbors ()
 Computes neighboring robots.
void init_callbacks ()
 Initializes simulation callbacks.
void init_data_logger ()
 Initializes the data logger.
void init_console_logger ()
 Initializes the console logger.
void draw_scale_bar ()
 Draws a scale bar on the GUI.
void render_all ()
 Renders all simulation components.
void export_frames ()
 Exports the current frame to a PNG file.
void export_data ()
 Exports simulation data from the current robot.
void main_loop ()
 Runs the main simulation loop.
void stop_simulation_main_loop ()
 Stops the main simulation loop.
void delete_old_data ()
 Deletes old data files.
Configurationget_config ()
 Retrieves the current configuration.
DataLoggerget_data_logger ()
 Retrieves the data logger.
LightLevelMapget_light_map ()
 Retrieves the light map.
arena_polygons_t const & get_arena_geometry ()
 Retrieve the arena geometry.
boundary_condition_t const & get_boundary_condition ()
 Retrieve the arena boundary conditions.
void apply_periodic_wrapping ()
 Wrap objects position to have period boundary conditions.
uint32_t get_nb_robots () const
 Returns the number of robots in the simulation.

Public Attributes

bool current_robot_enable_data_logging
 Flag to enable data logging on the current robot.

Detailed Description

Class representing the simulation environment.

The Simulation class encapsulates the configuration, SDL window and renderer, Box2D world, robots, arena geometry, data logging, and GUI event handling for the simulation.

Constructor & Destructor Documentation

◆ Simulation()

Simulation::Simulation ( Configuration & _config)

Constructs a Simulation object.

Initializes the simulation configuration, console logging, Box2D world, and SDL subsystems.

Parameters
_configReference to a Configuration object.

◆ ~Simulation()

Simulation::~Simulation ( )
virtual

Destructor.

Cleans up fonts, SDL, and Box2D world resources.

Member Function Documentation

◆ apply_periodic_wrapping()

void Simulation::apply_periodic_wrapping ( )

Wrap objects position to have period boundary conditions.

◆ compute_neighbors()

void Simulation::compute_neighbors ( )

Computes neighboring robots.

Updates each robot's neighbor list based on their positions and communication radius.

◆ create_arena()

void Simulation::create_arena ( )

Creates the arena from a CSV file.

Reads the arena polygons from a CSV file, computes the bounding box, creates walls, and adjusts visualization scaling.

◆ create_objects()

void Simulation::create_objects ( )

Creates objects in the simulation.

◆ create_robots()

void Simulation::create_robots ( )

Creates the robot instances.

Generates initial positions for robots based on the configuration, creates Robot objects, and initializes their user code.

◆ create_walls()

void Simulation::create_walls ( )

Creates arena walls.

Defines static bodies for arena boundaries using Box2D.

◆ delete_old_data()

void Simulation::delete_old_data ( )

Deletes old data files.

Deletes files with a specified extension from the frames directory if configured to do so.

◆ draw_scale_bar()

void Simulation::draw_scale_bar ( )

Draws a scale bar on the GUI.

Renders a horizontal scale bar along with a label indicating the scale in millimeters.

◆ export_data()

void Simulation::export_data ( )

Exports simulation data from the current robot.

Iterates over all robots, logs their state to the DataLogger, and saves the data row.

◆ export_frames()

void Simulation::export_frames ( )

Exports the current frame to a PNG file.

Saves the current window content to a PNG file if the frame export period has elapsed.

◆ get_arena_geometry()

arena_polygons_t const & Simulation::get_arena_geometry ( )
inline

Retrieve the arena geometry.

Returns
Arena polygons.

◆ get_boundary_condition()

boundary_condition_t const & Simulation::get_boundary_condition ( )
inline

Retrieve the arena boundary conditions.

Returns
Arena BC

◆ get_config()

Configuration & Simulation::get_config ( )

Retrieves the current configuration.

Returns
Configuration& configuration

◆ get_data_logger()

DataLogger * Simulation::get_data_logger ( )

Retrieves the data logger.

Returns
DataLogger* Pointer to the DataLogger instance.

◆ get_light_map()

LightLevelMap * Simulation::get_light_map ( )

Retrieves the light map.

Returns
LightLevelMap* Pointer to the LightLevelMap instance.

◆ get_nb_robots()

uint32_t Simulation::get_nb_robots ( ) const
inline

Returns the number of robots in the simulation.

Returns
Number of robots

◆ handle_SDL_events()

void Simulation::handle_SDL_events ( )

Handles SDL events.

Processes SDL events such as keyboard input, mouse movement, and window events, and updates simulation state accordingly.

◆ help_message()

void Simulation::help_message ( )

Displays a help message with GUI keyboard shortcuts.

◆ init_all()

void Simulation::init_all ( )

Initializes the simulation components.

Calls functions to create the arena and robots

◆ init_box2d()

void Simulation::init_box2d ( )

Initializes the Box2D world.

Creates a Box2D world with zero gravity.

◆ init_callbacks()

void Simulation::init_callbacks ( )

Initializes simulation callbacks.

Currently initializes the data logger.

◆ init_config()

void Simulation::init_config ( )

Initializes the simulation configuration.

Reads configuration parameters and initializes global variables such as window size, arena dimensions, robot radius, and GUI settings.

◆ init_console_logger()

void Simulation::init_console_logger ( )

Initializes the console logger.

Sets up file-based logging if enabled in the configuration.

Exceptions
std::runtime_errorif the console filename is empty when logging is enabled.

◆ init_data_logger()

void Simulation::init_data_logger ( )

Initializes the data logger.

Sets up the DataLogger schema based on configuration and opens the data file.

Exceptions
std::runtime_errorif required configuration values are missing.

◆ init_SDL()

void Simulation::init_SDL ( )

Initializes SDL and related subsystems.

Sets up the SDL window, renderer, font, and initializes fpng for image exporting.

Exceptions
std::runtime_errorif SDL initialization fails.

◆ main_loop()

void Simulation::main_loop ( )

Runs the main simulation loop.

Processes SDL events, updates robot states, steps the Box2D world, computes neighbors, logs data, renders frames, and manages simulation timing until the simulation time is reached or exit is requested.

◆ pause()

void Simulation::pause ( )

Toggles the simulation pause state.

◆ render_all()

void Simulation::render_all ( )

Renders all simulation components.

Clears the renderer, draws the arena walls, robots, current time, and scale bar.

◆ speed_down()

void Simulation::speed_down ( )

Slows down the simulation GUI.

Decreases the GUI speed-up factor and logs the new value.

◆ speed_up()

void Simulation::speed_up ( )

Speeds up the simulation GUI.

Increases the GUI speed-up factor and logs the new value.

◆ stop_simulation_main_loop()

void Simulation::stop_simulation_main_loop ( )

Stops the main simulation loop.

Member Data Documentation

◆ current_robot_enable_data_logging

bool Simulation::current_robot_enable_data_logging

Flag to enable data logging on the current robot.


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