WB-Toolbox  6.0.0
ASimulinkToolboxforWholeBodyControl
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wbt::base::WholeBodySingleton Class Reference

#include <WholeBodySingleton.h>

Detailed Description

This class handles and contains configuration and devices used by all the blocks allocated by a running model. It is possible obtaining a singleton of this class by calling WholeBodySingleton::sharedInstance.

See also
wbt::RobotInterface
wbt::Configuration
wbt::yarpDevices

Public Member Functions

 WholeBodySingleton ()
 
 ~WholeBodySingleton ()
 
 WholeBodySingleton (const WholeBodySingleton &)=delete
 
WholeBodySingletonoperator= (const WholeBodySingleton &)=delete
 
bool isKeyValid (const std::string &confKey) const
 
int numberOfDoFs (const std::string &confKey) const
 
const ConfigurationgetConfiguration (const std::string &confKey) const
 
const std::shared_ptr< RobotInterfacegetRobotInterface (const std::string &confKey) const
 
const std::shared_ptr< iDynTree::KinDynComputations > getKinDynComputations (const std::string &confKey) const
 
std::shared_ptr< RobotInterfacecreateRobotInterface (const Configuration &config)
 
std::shared_ptr< RobotInterfacestoreConfiguration (const blockfactory::core::Parameters &parameters)
 
void eraseConfiguration (const std::string &confKey)
 

Static Public Member Functions

static wbt::base::WholeBodySingletonsharedInstance ()
 

Private Attributes

std::unordered_map< std::string, std::weak_ptr< wbt::base::RobotInterface > > m_interfaces
 

Constructor & Destructor Documentation

◆ WholeBodySingleton() [1/2]

WholeBodySingleton::WholeBodySingleton ( )
default

◆ ~WholeBodySingleton()

WholeBodySingleton::~WholeBodySingleton ( )
default

◆ WholeBodySingleton() [2/2]

wbt::base::WholeBodySingleton::WholeBodySingleton ( const WholeBodySingleton )
delete

Member Function Documentation

◆ createRobotInterface()

std::shared_ptr< RobotInterface > WholeBodySingleton::createRobotInterface ( const Configuration config)

Stores in the singleton the new configuration into a RobotInterface object

If the config is valid and hasn't been already stored, it creates a new entry in WholeBodySingleton::m_interfaces. If a configuration with matching confKey is found, if the Configuration object is the same it does nothing, otherwise it overrides it.

Note
Since confKey is the name of the block, the overriding can happen only after subsequent compilation in Simulink, when the block's parameters have been changed.
Parameters
configThe wbt::Configuration object parsed from Simulink's parameters
Returns
Returns a shared pointer to the RobotInterface object created from the Configuration object.
See also
WholeBodySingleton::isKeyValid

◆ eraseConfiguration()

void WholeBodySingleton::eraseConfiguration ( const std::string &  confKey)

Delete the wbt::RobotInterface referred by confKey. No-op if it doesn't exist.

Parameters
confKeyThe key describing the configuration (name of the Simulink block)

◆ getConfiguration()

const Configuration & WholeBodySingleton::getConfiguration ( const std::string &  confKey) const

Returns the Configuration object labelled by confKey. This object is contained into the wbt::RobotInterface object.

See also
WholeBodySingleton::getRobotInterface
Parameters
confKeyThe key describing the configuration (name of the Simulink block)
Returns
A constant reference to the Configuration object

◆ getKinDynComputations()

const std::shared_ptr< iDynTree::KinDynComputations > WholeBodySingleton::getKinDynComputations ( const std::string &  confKey) const

Returns a shared_ptr to the KinDynComputations object used to perform calculation on the provided model

Parameters
confKeyThe key describing the configuration (name of the Simulink block)
Returns
A shared_ptr to the iDynTree::KinDynComputations of the requested configuration

◆ getRobotInterface()

const std::shared_ptr< RobotInterface > WholeBodySingleton::getRobotInterface ( const std::string &  confKey) const

Returns a shared_ptr to the RobotInterface object containing the configuration labelled by confKey and all the objects used to gather and set robot data

Parameters
confKeyThe key describing the configuration (name of the Simulink block)
Returns
A shared_ptr to the RobotInterface of the requested configuration

◆ isKeyValid()

bool WholeBodySingleton::isKeyValid ( const std::string &  confKey) const

Check if a Configuration labelled by confKey exists and is a valid object.

Parameters
confKeyThe key describing the configuration (name of the Simulink block)
Returns
True if the configuration is valid

◆ numberOfDoFs()

int WholeBodySingleton::numberOfDoFs ( const std::string &  confKey) const

Returns the DoFs associated with the configuration labelled by confKey

Parameters
confKeyThe key describing the configuration (name of the Simulink block)
Returns
The number of degrees of freedom. It returns -1 when failing.

◆ operator=()

WholeBodySingleton& wbt::base::WholeBodySingleton::operator= ( const WholeBodySingleton )
delete

◆ sharedInstance()

WholeBodySingleton & WholeBodySingleton::sharedInstance ( )
static

Returns the singleton instance to this object.

Note
The singleton stays in memory until the entire matlab is closed. The WBToolbox is designed in such a way that assures to reach a clean state when all blocks have been terminated.
Returns
the singleton instance

◆ storeConfiguration()

std::shared_ptr< RobotInterface > WholeBodySingleton::storeConfiguration ( const blockfactory::core::Parameters &  parameters)

Stores a new whole-body configuration and return a RobotInterface object

Parameters
parametersA wbt::Parameters object containing all the parameters to fill a wbt::Configuration object
Returns
Returns a shared pointer to the RobotInterface object created from the Configuration object.
See also
WholeBodySingleton::storeConfiguration, wbt::Configuration, Parameters::containConfigurationData

Member Data Documentation

◆ m_interfaces

std::unordered_map<std::string, std::weak_ptr<wbt::base::RobotInterface> > wbt::base::WholeBodySingleton::m_interfaces
private

Object that stores all the configurations labelled by the name of the Simulink Block's name.

See also
wbt::RobotInterface

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