Helios++
Helios software for LiDAR simulations
Simulation Class Referenceabstract

Class representing a simulation. More...

#include <Simulation.h>

Inheritance diagram for Simulation:
Collaboration diagram for Simulation:

Public Member Functions

 Simulation (int const parallelizationStrategy, std::shared_ptr< PulseThreadPoolInterface > pulseThreadPoolInterface, int const chunkSize, std::string fixedGpsTimeStart="")
 Simulation constructor. More...
 
virtual void prepareSimulation (int simFrequency_hz)
 Prepare the simulation before starting its main loop. More...
 
virtual void doSimStep ()
 Perform computations for current simulation step.
 
virtual void onLegComplete ()=0
 Handle leg completion.
 
void start ()
 Start the simmulation.
 
void stop ()
 Stop the simulation. More...
 
void pause (bool pause)
 Pause or unpause the simulation. More...
 
void shutdown ()
 Handle simulation shutdown.
 
double calcCurrentGpsTime ()
 Compute the current GPS time (nanoseconds) More...
 
void setSimSpeedFactor (double factor)
 Set the simulation speed factor. More...
 
double getSimSpeedFactor () const
 Obtain simulation speed factor. More...
 
void setScanner (std::shared_ptr< Scanner > scanner)
 Set scanner for the simulation. More...
 
std::shared_ptr< ScannergetScanner ()
 Obtain simulation scanner. More...
 
bool isPaused () const
 Check if simulation is paused (true) or not (false) More...
 
bool isStopped () const
 Check if simulation is stopped (true) or not (false) More...
 
size_t getSimFrequency () const
 Obtain simulation frequency. More...
 
void setSimFrequency (size_t const simFrequency)
 Set simulation frequency. More...
 
size_t getCallbackFrequency () const
 Get the callback frequency. It is, how many steps must elapse between consecutive callbacks. More...
 
void setCallbackFrequency (size_t const callbackFrequency)
 Set the new callback frequency. More...
 
SimulationStepLoopgetStepLoop ()
 Get the simulation step loop of the simulation. More...
 

Public Attributes

unsigned int mCurrentLegIndex = 0
 Index of leg at current simulation stage.
 
bool exportToFile = true
 Flag specifying if simulation output must be exported to a file (true) or not (false)
 
bool exitAtEnd = false
 Flag specifying if simulation must end when current leg has been completed (true) or not (false)
 
bool finished = false
 Flag specifying if simulation has finished (true) or not (false)
 
std::shared_ptr< SimulationCycleCallbackcallback = nullptr
 

Protected Attributes

int parallelizationStrategy
 Specify the parallelization strategy. More...
 
std::shared_ptr< PulseThreadPoolInterfacethreadPool
 Pulse thread pool. More...
 
PulseTaskDropper taskDropper
 Pulse task dropper. More...
 
double mSimSpeedFactor = 1
 Simulation speed factor.
 
std::shared_ptr< ScannermScanner = nullptr
 Scanner used by the simulation. More...
 
SimulationStepLoop stepLoop
 The handler for simulation steps, it also contains the discrete time object that hanldes simulation frequency and time.
 
size_t callbackFrequency = 0
 The callback frequency. It specifies how many steps must elapse between consecutive callbacks.
 
std::mutex mutex
 Mutex to handle simulation pause and iterations on a multi threading context.
 
std::condition_variable condvar
 Condition variable tu handle simulation iterations on a multi threading context.
 
std::shared_ptr< std::unique_lock< std::mutex > > pauseLock = nullptr
 Shared pointer to the lock used to handle the mutex for simulation pause purposes. More...
 
bool mStopped = false
 Flag specifying if the simulation has been stopped (true) or not (false)
 
bool mPaused = false
 Flag specifying if the simulation has been paused (true) or not (false)
 
std::chrono::nanoseconds timeStart_ns
 Time corresponding to simulation start (nanoseconds)
 
double currentGpsTime_ns = 0
 Time corresponding to simulation start (currentGpsTime in nanoseconds)
 
double stepGpsTime_ns = 0
 The time step for GPS time (in nanoseconds) More...
 
std::string fixedGpsTimeStart = ""
 Given fixed time start for GPS time as a string. More...
 
SimulationReporter reporter
 The report to generate reports about simulation. More...
 

Friends

class SimulationReporter
 

Detailed Description

Class representing a simulation.

Constructor & Destructor Documentation

◆ Simulation()

Simulation::Simulation ( int const  parallelizationStrategy,
std::shared_ptr< PulseThreadPoolInterface pulseThreadPoolInterface,
int const  chunkSize,
std::string  fixedGpsTimeStart = "" 
)

Simulation constructor.

Parameters
pulseThreadPoolInterfaceThe thread pool to be used for parallel computation during simulation
See also
PulseThreadPoolInterface
PulseThreadPool
PulseWarehouseThreadPool
PulseTaskDropper

Member Function Documentation

◆ calcCurrentGpsTime()

double Simulation::calcCurrentGpsTime ( )

Compute the current GPS time (nanoseconds)

Returns
Current GPS time (nanoseconds)

◆ getCallbackFrequency()

size_t Simulation::getCallbackFrequency ( ) const
inline

Get the callback frequency. It is, how many steps must elapse between consecutive callbacks.

Returns
Callback frequency
See also
Simulation::callbackFrequency
Simulation::setCallbackFrequency

◆ getScanner()

std::shared_ptr<Scanner> Simulation::getScanner ( )
inline

Obtain simulation scanner.

Returns
Simulation scanner
See also
Simulation::mScanner

◆ getSimFrequency()

size_t Simulation::getSimFrequency ( ) const
inline

Obtain simulation frequency.

Returns
Simulation frequency (hertz)
See also
Simulation::stepLoop

◆ getSimSpeedFactor()

double Simulation::getSimSpeedFactor ( ) const
inline

Obtain simulation speed factor.

Returns
Simulation speed factor
See also
Simulation::mSimSpeedFactor

◆ getStepLoop()

SimulationStepLoop& Simulation::getStepLoop ( )
inline

Get the simulation step loop of the simulation.

Returns
The simulation's step loop
See also
Simulation:stepLoop
SimulationStepLoop

◆ isPaused()

bool Simulation::isPaused ( ) const
inline

Check if simulation is paused (true) or not (false)

Returns
True if simulation is paused, false otherwise
See also
Simulation::mPaused

◆ isStopped()

bool Simulation::isStopped ( ) const
inline

Check if simulation is stopped (true) or not (false)

Returns
True if simulation is stopped, false otherwise
See also
Simulation::mStopped

◆ pause()

void Simulation::pause ( bool  pause)

Pause or unpause the simulation.

Parameters
pauseTrue to pause the simulation, false to unpause it

◆ prepareSimulation()

void Simulation::prepareSimulation ( int  simFrequency_hz)
virtual

Prepare the simulation before starting its main loop.

Parameters
simFrequency_hzThe simulation frequency in hertz

◆ setCallbackFrequency()

void Simulation::setCallbackFrequency ( size_t const  callbackFrequency)
inline

Set the new callback frequency.

Parameters
callbackFrequencyNew callback frequency
See also
Simulation::callbackFrequency
Simulation::getCallbackFrequency

◆ setScanner()

void Simulation::setScanner ( std::shared_ptr< Scanner scanner)

Set scanner for the simulation.

Parameters
scannerNew scanner for the simulation
See also
Simulation::mScanner

◆ setSimFrequency()

void Simulation::setSimFrequency ( size_t const  simFrequency)
inline

Set simulation frequency.

Parameters
simFrequencyNew simulation frequency (hertz)
See also
Simulation::stepLoop

◆ setSimSpeedFactor()

void Simulation::setSimSpeedFactor ( double  factor)

Set the simulation speed factor.

Factors less than or equal to 0 will be setted to 0.0001 and factors greater than 10000 will be truncated to 10000.

In consequence, simulation speed factor will always be in interval \([0.0001, 10000]\) when setted through this setter

Parameters
factorNew simulation speed factor
See also
Simulation::mSimSpeedFactor

◆ stop()

void Simulation::stop ( )
inline

Stop the simulation.

NOTICE this method will not stop simulation immediately but when possible without compromising its execution. This means stop will occur in a safe way.

Member Data Documentation

◆ fixedGpsTimeStart

std::string Simulation::fixedGpsTimeStart = ""
protected

Given fixed time start for GPS time as a string.

Valid formats are either "YYYY-MM-DD hh:mm:ss" or POSIX timestamp.

If it is an empty string "", then it means no fixed GPS time start must be considered

◆ mScanner

std::shared_ptr<Scanner> Simulation::mScanner = nullptr
protected

Scanner used by the simulation.

See also
Scanner

◆ parallelizationStrategy

int Simulation::parallelizationStrategy
protected

Specify the parallelization strategy.

See also
ArgumentsParser::parseParallelizationStrategy

◆ pauseLock

std::shared_ptr<std::unique_lock<std::mutex> > Simulation::pauseLock = nullptr
protected

Shared pointer to the lock used to handle the mutex for simulation pause purposes.

See also
Simulation::mutex

◆ reporter

SimulationReporter Simulation::reporter
protected

The report to generate reports about simulation.

See also
SimulationReporter

◆ stepGpsTime_ns

double Simulation::stepGpsTime_ns = 0
protected

The time step for GPS time (in nanoseconds)

See also
Simulation::currentGpsTime_ns

◆ taskDropper

PulseTaskDropper Simulation::taskDropper
protected

Pulse task dropper.

See also
PulseTaskDropper

◆ threadPool

std::shared_ptr<PulseThreadPoolInterface> Simulation::threadPool
protected

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