Privacy
An open-source, flexible 3D physical simulation framework
mars::sim::SensorManager Class Reference

"SensorManager" imlements the interfaces for all sensor operations that are used for the communication between the simulation modules. More...

#include <SensorManager.h>

Public Member Functions

 SensorManager (interfaces::ControlCenter *c)
 Constructor. More...
 
virtual ~SensorManager ()
 Destructor. More...
 
virtual void getListSensors (std::vector< interfaces::core_objects_exchange > *sensorList) const
 Add a sensor to the simulation. More...
 
virtual const interfaces::BaseSensorgetFullSensor (unsigned long index) const
 Gives information about core exchange data for camera sensors. More...
 
virtual void removeSensor (unsigned long index)
 Removes a sensor from the simulation. More...
 
virtual interfaces::BaseSensorgetSimSensor (unsigned long index) const
 This function returns the SimSensor object for a given index. More...
 
unsigned long getSensorID (std::string name) const
 
virtual int getSensorData (unsigned long id, interfaces::sReal **data) const
 This function provides the sensor data for a given index. More...
 
virtual int getSensorCount (void) const
 Returns the number of sensors that are currently present in the simulation. More...
 
virtual void clearAllSensors (bool clear_all=false)
 Destroys all sensors in the simulation. More...
 
virtual void reloadSensors (void)
 This function reloads all sensors from a temporary sensor pool. More...
 
void addSensorType (const std::string &name, interfaces::BaseSensor *(*func)(interfaces::ControlCenter *, interfaces::BaseConfig *))
 
void addMarsParser (const std::string, interfaces::BaseConfig *(*)(interfaces::ControlCenter *, configmaps::ConfigMap *))
 
virtual interfaces::BaseSensorcreateAndAddSensor (configmaps::ConfigMap *config, bool reload=true)
 Adds an sensor to the known sensors list. More...
 
virtual interfaces::BaseSensorcreateAndAddSensor (const std::string &type_name, interfaces::BaseConfig *config, bool reload=false)
 
- Public Member Functions inherited from mars::interfaces::SensorManagerInterface
virtual ~SensorManagerInterface ()
 Destructor. More...
 

Private Attributes

unsigned long next_sensor_id
 the id of the next sensor added to the simulation More...
 
std::map< unsigned long, interfaces::BaseSensor * > simSensors
 a containter for all sensors currently present in the simulation More...
 
std::vector< SensorReloadHelpersimSensorsReload
 a containter for all sensors that are loaded after a reset of the simulation More...
 
interfaces::ControlCentercontrol
 a pointer to the control center More...
 
utils::Mutex iMutex
 a mutex fot the sensor containters More...
 
std::map< const std::string, interfaces::BaseSensor *(*)(interfaces::ControlCenter *, interfaces::BaseConfig *)> availableSensors
 
std::map< const std::string, interfaces::BaseConfig *(*)(interfaces::ControlCenter *, configmaps::ConfigMap *)> marsParser
 

Detailed Description

"SensorManager" imlements the interfaces for all sensor operations that are used for the communication between the simulation modules.

Warning
It is very important to assure the serialization between the threads to have the desired results. Currently the verified use of the functions is only guaranteed by calling it within the main thread (update callback from gui_thread).

Definition at line 69 of file SensorManager.h.

Constructor & Destructor Documentation

◆ SensorManager()

mars::sim::SensorManager::SensorManager ( interfaces::ControlCenter c)

Constructor.

Parameters
cThe pointer to the ControlCenter of the simulation.

Definition at line 78 of file SensorManager.cpp.

◆ ~SensorManager()

virtual mars::sim::SensorManager::~SensorManager ( )
inlinevirtual

Destructor.

Definition at line 82 of file SensorManager.h.

Member Function Documentation

◆ addMarsParser()

void mars::sim::SensorManager::addMarsParser ( const std::string  ,
interfaces::BaseConfig *)(interfaces::ControlCenter *, configmaps::ConfigMap * 
)

Definition at line 293 of file SensorManager.cpp.

◆ addSensorType()

void mars::sim::SensorManager::addSensorType ( const std::string &  name,
interfaces::BaseSensor *(*)(interfaces::ControlCenter *, interfaces::BaseConfig *)  func 
)

Definition at line 298 of file SensorManager.cpp.

◆ clearAllSensors()

void mars::sim::SensorManager::clearAllSensors ( bool  clear_all = false)
virtual

Destroys all sensors in the simulation.

The clear_all flag indicates if the reload sensors should be destroyed as well. If set to false they are left intact.

Parameters
clear_allIndicates if the reload sensors should be destroyed as well. If set to false they are left intact.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 260 of file SensorManager.cpp.

◆ createAndAddSensor() [1/2]

BaseSensor * mars::sim::SensorManager::createAndAddSensor ( configmaps::ConfigMap config,
bool  reload = true 
)
virtual

Adds an sensor to the known sensors list.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 335 of file SensorManager.cpp.

◆ createAndAddSensor() [2/2]

BaseSensor * mars::sim::SensorManager::createAndAddSensor ( const std::string &  type_name,
interfaces::BaseConfig config,
bool  reload = false 
)
virtual

Implements mars::interfaces::SensorManagerInterface.

Definition at line 302 of file SensorManager.cpp.

◆ getFullSensor()

const BaseSensor * mars::sim::SensorManager::getFullSensor ( unsigned long  index) const
virtual

Gives information about core exchange data for camera sensors.

Gives all information of a certain sensor.

Parameters
cameraListA pointer to a vector that is filled with a core_objects_exchange struct for every camera sensor. The vector is cleared in the beginning of this function. Gives all information of a certain sensor.
indexThe unique id of the sensor to get information for.
Returns
A pointer to the BaseSensor of the sensor with the given id.
Parameters
indexThe unique id of the sensor to get information for.
Returns
A pointer to the BaseSensor of the sensor with the given id.
Exceptions
std::runtime_errorif a motor with the given index does not exist.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 156 of file SensorManager.cpp.

◆ getListSensors()

void mars::sim::SensorManager::getListSensors ( std::vector< interfaces::core_objects_exchange > *  sensorList) const
virtual

Add a sensor to the simulation.

Gives information about core exchange data for sensors.

Parameters
sensorSA pointer to the BaseSensor that defines the new sensor.
reloadUsed internally by the simulation. The default value is false. If this param is set to true the new sensor will not be reloaded after a reset of the simulation.
Returns
The unique id of the newly added sensor. Gives information about core exchange data for sensors.
Parameters
sensorListA pointer to a vector that is filled with a core_objects_exchange struct for every sensor. The vector is cleared in the beginning of this function.
sensorListA pointer to a vector that is filled with a core_objects_exchange struct for every sensor. The vector is cleared in the beginning of this function.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 136 of file SensorManager.cpp.

◆ getSensorCount()

int mars::sim::SensorManager::getSensorCount ( void  ) const
virtual

Returns the number of sensors that are currently present in the simulation.

Returns
The number of all sensors.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 245 of file SensorManager.cpp.

◆ getSensorData()

int mars::sim::SensorManager::getSensorData ( unsigned long  id,
interfaces::sReal **  data 
) const
virtual

This function provides the sensor data for a given index.

Parameters
dataThe sensor data of the sensor.
indexThe index of the sensor to get the data

Implements mars::interfaces::SensorManagerInterface.

Definition at line 227 of file SensorManager.cpp.

◆ getSensorID()

unsigned long mars::sim::SensorManager::getSensorID ( std::string  name) const
virtual

Implements mars::interfaces::SensorManagerInterface.

Definition at line 170 of file SensorManager.cpp.

◆ getSimSensor()

BaseSensor * mars::sim::SensorManager::getSimSensor ( unsigned long  index) const
virtual

This function returns the SimSensor object for a given index.

Parameters
nameThe index of the sensor to get the core sensor object.
Returns
Returns a pointer to the corresponding sensor object.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 210 of file SensorManager.cpp.

◆ reloadSensors()

void mars::sim::SensorManager::reloadSensors ( void  )
virtual

This function reloads all sensors from a temporary sensor pool.

All sensors that have been added with reload value as true are added back to the simulation again with a reload value of true.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 280 of file SensorManager.cpp.

◆ removeSensor()

void mars::sim::SensorManager::removeSensor ( unsigned long  index)
virtual

Removes a sensor from the simulation.

Parameters
indexThe unique id of the sensor to remove form the simulation.

Implements mars::interfaces::SensorManagerInterface.

Definition at line 187 of file SensorManager.cpp.

Member Data Documentation

◆ availableSensors

std::map<const std::string, interfaces::BaseSensor* (*)(interfaces::ControlCenter*, interfaces::BaseConfig*)> mars::sim::SensorManager::availableSensors
private

Definition at line 231 of file SensorManager.h.

◆ control

interfaces::ControlCenter* mars::sim::SensorManager::control
private

a pointer to the control center

Definition at line 224 of file SensorManager.h.

◆ iMutex

utils::Mutex mars::sim::SensorManager::iMutex
mutableprivate

a mutex fot the sensor containters

Definition at line 227 of file SensorManager.h.

◆ marsParser

std::map<const std::string, interfaces::BaseConfig* (*)(interfaces::ControlCenter*, configmaps::ConfigMap*)> mars::sim::SensorManager::marsParser
private

Definition at line 234 of file SensorManager.h.

◆ next_sensor_id

unsigned long mars::sim::SensorManager::next_sensor_id
private

the id of the next sensor added to the simulation

Definition at line 214 of file SensorManager.h.

◆ simSensors

std::map<unsigned long, interfaces::BaseSensor*> mars::sim::SensorManager::simSensors
private

a containter for all sensors currently present in the simulation

Definition at line 217 of file SensorManager.h.

◆ simSensorsReload

std::vector<SensorReloadHelper> mars::sim::SensorManager::simSensorsReload
private

a containter for all sensors that are loaded after a reset of the simulation

Definition at line 220 of file SensorManager.h.


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