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

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

#include <ControllerManager.h>

Public Member Functions

 ControllerManager (interfaces::ControlCenter *c)
 Constructor. More...
 
virtual ~ControllerManager ()
 Destructor. More...
 
virtual void getListController (std::vector< interfaces::core_objects_exchange > *controllerList) const
 Gives information about core exchange data for controllers. More...
 
virtual int getControllerCount (void) const
 Returns the number of controllers that are currently present in the simulation. More...
 
virtual const interfaces::ControllerData getFullController (unsigned long index) const
 Gives all information of a certain controller. More...
 
virtual void removeController (unsigned long index)
 Removes a controller from the simulation. More...
 
virtual void setControllerAutoMode (unsigned long id, bool mode)
 Sets the mode of the controller with the given id. More...
 
virtual void setControllerIP (unsigned long id, const std::string &ip)
 Sets the IP of the controller with the given id. More...
 
virtual void setControllerPort (unsigned long id, int port)
 Gets the mode of the controller with the given id. More...
 
virtual bool getControllerAutoMode (unsigned long id) const
 Gets the mode of the controller with the given id. More...
 
virtual const std::string getControllerIP (unsigned long id) const
 Gets the IP of the controller with the given id. More...
 
virtual int getControllerPort (unsigned long id) const
 Gets the port of the controller with the given id. More...
 
virtual void connectController (unsigned long id)
 Connects the controller with the given id. More...
 
virtual void disconnectController (unsigned long id)
 Disconnects the controller with the given id. More...
 
virtual void updateControllers (interfaces::sReal calc_ms)
 This function updates all controllers with timing value calc_ms in miliseconds. More...
 
virtual void resetControllerData (void)
 Resets the data of all controllers. More...
 
virtual void clearAllControllers (void)
 Destroys all controllers in the simulation. More...
 
virtual void handleError (void)
 
virtual unsigned long addController (const interfaces::ControllerData &controller)
 Add a controller to the simulation. More...
 
virtual void setDefaultPort (int port)
 Sets the default port, with which all controllers are created. More...
 
virtual int getDefaultPort (void) const
 Gets the default port, with which all controllers are created. More...
 
virtual bool isLoadingAllowed (void) const
 Checks weather adding new controllers is allowed. More...
 
virtual void setLoadingAllowed (bool allowed)
 Allows or forbids adding new controllers. More...
 
virtual std::list< interfaces::sRealgetSensorValues (unsigned long id)
 
- Public Member Functions inherited from mars::interfaces::ControllerManagerInterface
virtual ~ControllerManagerInterface ()
 Destructor. More...
 

Private Attributes

bool do_not_load_controller
 a flag indicating if adding new controllers is allowed More...
 
int std_port
 the default port passed to every newly added controller More...
 
unsigned long next_controller_id
 the id of the next controller added to the simulation More...
 
std::map< unsigned long, Controller * > simController
 a containter holding all controllers in the simulation More...
 
interfaces::ControlCentercontrol
 a pointer to the control center More...
 
utils::Mutex iMutex
 a mutex for the controllers containter More...
 

Detailed Description

"ControllerManager" imlements the interfaces for all controller operations that are used for the communication between the simulation modules.

Inherits from ControllerManagerInterface.

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 60 of file ControllerManager.h.

Constructor & Destructor Documentation

◆ ControllerManager()

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

Constructor.

Parameters
cThe pointer to the ControlCenter of the simulation.

Definition at line 55 of file ControllerManager.cpp.

◆ ~ControllerManager()

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

Destructor.

Definition at line 73 of file ControllerManager.h.

Member Function Documentation

◆ addController()

unsigned long mars::sim::ControllerManager::addController ( const interfaces::ControllerData controller)
virtual

Add a controller to the simulation.

Returns
The id of the newly added controller.
Returns
The id of the newly added controller.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 321 of file ControllerManager.cpp.

◆ clearAllControllers()

void mars::sim::ControllerManager::clearAllControllers ( void  )
virtual

Destroys all controllers in the simulation.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 287 of file ControllerManager.cpp.

◆ connectController()

void mars::sim::ControllerManager::connectController ( unsigned long  id)
virtual

Connects the controller with the given id.

Parameters
idThe id of the controller that is to be connected.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 235 of file ControllerManager.cpp.

◆ disconnectController()

void mars::sim::ControllerManager::disconnectController ( unsigned long  id)
virtual

Disconnects the controller with the given id.

Parameters
idThe id of the controller that is to be disconnected.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 248 of file ControllerManager.cpp.

◆ getControllerAutoMode()

bool mars::sim::ControllerManager::getControllerAutoMode ( unsigned long  id) const
virtual

Gets the mode of the controller with the given id.

Parameters
idThe id of the controller whose mode is needed.
Returns
The mode of the controller with the given id.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 183 of file ControllerManager.cpp.

◆ getControllerCount()

int mars::sim::ControllerManager::getControllerCount ( void  ) const
virtual

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

Returns
The number of all controllers.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 88 of file ControllerManager.cpp.

◆ getControllerIP()

const std::string mars::sim::ControllerManager::getControllerIP ( unsigned long  id) const
virtual

Gets the IP of the controller with the given id.

Parameters
idThe id of the controller whose IP is needed.
Returns
The IP of the controller with the given id.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 199 of file ControllerManager.cpp.

◆ getControllerPort()

int mars::sim::ControllerManager::getControllerPort ( unsigned long  id) const
virtual

Gets the port of the controller with the given id.

Parameters
idThe id of the controller whose port is needed.
Returns
The port of the controller with the given id.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 219 of file ControllerManager.cpp.

◆ getDefaultPort()

int mars::sim::ControllerManager::getDefaultPort ( void  ) const
virtual

Gets the default port, with which all controllers are created.

Returns
The default port.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 365 of file ControllerManager.cpp.

◆ getFullController()

const ControllerData mars::sim::ControllerManager::getFullController ( unsigned long  index) const
virtual

Gives all information of a certain controller.

Parameters
indexThe unique id of the controller to get information for.
Returns
A pointer to the ControllerData of the controller with the given id.
Exceptions
std::runtime_errorif the controller cannot be found

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 102 of file ControllerManager.cpp.

◆ getListController()

void mars::sim::ControllerManager::getListController ( std::vector< interfaces::core_objects_exchange > *  controllerList) const
virtual

Gives information about core exchange data for controllers.

Parameters
controllerListA pointer to a vector that is filled with a core_objects_exchange struct for every controller. The vector is cleared in the beginning of this function.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 70 of file ControllerManager.cpp.

◆ getSensorValues()

std::list< sReal > mars::sim::ControllerManager::getSensorValues ( unsigned long  id)
virtual

◆ handleError()

void mars::sim::ControllerManager::handleError ( void  )
virtual

◆ isLoadingAllowed()

bool mars::sim::ControllerManager::isLoadingAllowed ( void  ) const
virtual

Checks weather adding new controllers is allowed.

Returns
true if allowed, false otherwise.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 383 of file ControllerManager.cpp.

◆ removeController()

void mars::sim::ControllerManager::removeController ( unsigned long  index)
virtual

Removes a controller from the simulation.

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

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 120 of file ControllerManager.cpp.

◆ resetControllerData()

void mars::sim::ControllerManager::resetControllerData ( void  )
virtual

Resets the data of all controllers.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 275 of file ControllerManager.cpp.

◆ setControllerAutoMode()

void mars::sim::ControllerManager::setControllerAutoMode ( unsigned long  id,
bool  mode 
)
virtual

Sets the mode of the controller with the given id.

Parameters
idThe id of the controller whose mode is to be set.
modeThe new mode.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 142 of file ControllerManager.cpp.

◆ setControllerIP()

void mars::sim::ControllerManager::setControllerIP ( unsigned long  id,
const std::string &  ip 
)
virtual

Sets the IP of the controller with the given id.

Parameters
idThe id of the controller whose IP is to be set.
ipThe new IP.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 157 of file ControllerManager.cpp.

◆ setControllerPort()

void mars::sim::ControllerManager::setControllerPort ( unsigned long  id,
int  port 
)
virtual

Gets the mode of the controller with the given id.

Parameters
idThe id of the controller whose mode is needed.
Returns
The mode of the controller with the given id.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 167 of file ControllerManager.cpp.

◆ setDefaultPort()

void mars::sim::ControllerManager::setDefaultPort ( int  port)
virtual

Sets the default port, with which all controllers are created.

Parameters
portThe default port.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 374 of file ControllerManager.cpp.

◆ setLoadingAllowed()

void mars::sim::ControllerManager::setLoadingAllowed ( bool  allowed)
virtual

Allows or forbids adding new controllers.

Parameters
allowedIndicates if adding will be allowed or not.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 392 of file ControllerManager.cpp.

◆ updateControllers()

void mars::sim::ControllerManager::updateControllers ( interfaces::sReal  calc_ms)
virtual

This function updates all controllers with timing value calc_ms in miliseconds.

Warning
This function is only used internally and should not be called outside the core.
Parameters
calc_msThe timing value in miliseconds.

Implements mars::interfaces::ControllerManagerInterface.

Definition at line 263 of file ControllerManager.cpp.

Member Data Documentation

◆ control

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

a pointer to the control center

Definition at line 253 of file ControllerManager.h.

◆ do_not_load_controller

bool mars::sim::ControllerManager::do_not_load_controller
private

a flag indicating if adding new controllers is allowed

Definition at line 241 of file ControllerManager.h.

◆ iMutex

utils::Mutex mars::sim::ControllerManager::iMutex
mutableprivate

a mutex for the controllers containter

Definition at line 256 of file ControllerManager.h.

◆ next_controller_id

unsigned long mars::sim::ControllerManager::next_controller_id
private

the id of the next controller added to the simulation

Definition at line 247 of file ControllerManager.h.

◆ simController

std::map<unsigned long, Controller*> mars::sim::ControllerManager::simController
private

a containter holding all controllers in the simulation

Definition at line 250 of file ControllerManager.h.

◆ std_port

int mars::sim::ControllerManager::std_port
private

the default port passed to every newly added controller

Definition at line 244 of file ControllerManager.h.


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