yarp-devices
Public Types | Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | List of all members
roboticslab::DeviceMapper Class Referencefinal

Exposes raw subdevice interface handles on a per-axis manner. More...

#include <DeviceMapper.hpp>

Public Types

using dev_index_t = std::tuple< const RawDevice *, int >
 Tuple of a raw device pointer and either an offset or a local index.
 
using dev_group_t = std::tuple< const RawDevice *, std::vector< int >, int >
 Tuple of a raw device pointer, its local indices and the global index.
 
template<typename T , typename... T_ref>
using motor_single_joint_fn = bool(T::*)(int, T_ref...)
 Alias for a single-joint command. See class description.
 
template<typename T , typename... T_refs>
using motor_all_joints_fn = bool(T::*)(T_refs *...)
 Alias for a full-joint command. See class description.
 
template<typename T , typename... T_refs>
using motor_multi_joints_fn = bool(T::*)(int, const int *, T_refs *...)
 Alias for a joint-group command. See class description.
 
template<typename T , typename T_out >
using sensor_status_fn = T_out(T::*)(std::size_t) const
 
template<typename T >
using sensor_size_fn = std::size_t(T::*)(std::size_t) const
 
template<typename T , typename... T_out_params>
using sensor_output_fn = bool(T::*)(std::size_t, T_out_params &...) const
 

Public Member Functions

 DeviceMapper ()
 Constructor.
 
 ~DeviceMapper ()
 Destructor.
 
void enableParallelization (unsigned int concurrentTasks)
 Whether to enable parallel mappings and on how many concurrent threads.
 
bool registerDevice (yarp::dev::PolyDriver *driver)
 Extract interface handles and perform sanity checks.
 
void clear ()
 Delete all internal handles.
 
std::unique_ptr< FutureTaskcreateTask () const
 Create an instance of a deferred task.
 
const std::vector< std::unique_ptr< const RawDevice > > & getDevices () const
 Retrieve all registered raw devices, regardless of type. More...
 
dev_index_t getMotorDevice (int globalAxis) const
 Retrieve a motor device handle and its local index given a global index. More...
 
std::vector< dev_index_tgetMotorDevicesWithOffsets () const
 Retrieve all registered motor subdevices and their associated offsets. More...
 
std::vector< dev_group_tgetMotorDevicesWithIndices (int globalAxesCount, const int *globalAxes) const
 Retrieve motor subdevices that map to the specified global axes. More...
 
int getControlledAxes () const
 Retrieve the number of controlled axes across all subdevices.
 
template<typename T , typename... T_ref>
bool mapSingleJoint (motor_single_joint_fn< T, T_ref... > fn, int j, T_ref... ref)
 Single-joint command mapping. See class description.
 
template<typename T , typename... T_refs>
bool mapAllJoints (motor_all_joints_fn< T, T_refs... > fn, T_refs *... refs)
 Full-joint command mapping. See class description.
 
template<typename T , typename... T_refs>
bool mapJointGroup (motor_multi_joints_fn< T, T_refs... > fn, int n_joint, const int *joints, T_refs *... refs)
 Joint-group command mapping. See class description.
 
template<typename T >
int getConnectedSensors () const
 Retrieve the number of connected sensors of the specified type across all subdevices.
 
template<typename T >
dev_index_t getSensorDevice (int globalIndex) const
 Retrieve a sensor device handle and its local index given a global index. More...
 
template<typename T , typename T_out >
T_out getSensorStatus (sensor_status_fn< T, T_out > fn, std::size_t index) const
 Retrieve the status of the sensor device at the specified global index. More...
 
template<typename T >
std::size_t getSensorArraySize (sensor_size_fn< T > fn, std::size_t index) const
 Retrieve the size of the sensor array at the specified global index. More...
 
template<typename T , typename... T_out_params>
bool getSensorOutput (sensor_output_fn< T, T_out_params... > fn, std::size_t index, T_out_params &... params) const
 Retrieve information from the sensor device at the specified global index. More...
 

Private Types

using dev_index_offset_t = std::tuple< int, int, int >
 

Static Private Member Functions

static const int getSensorFailureStatus ()
 

Private Attributes

std::vector< std::unique_ptr< const RawDevice > > devices
 
std::vector< dev_index_offset_t > motorOffsets
 
std::unordered_map< std::type_index, std::vector< dev_index_offset_t > > sensorOffsets
 
std::unordered_map< std::type_index, int > connectedSensors
 
int totalAxes {0}
 
std::unique_ptr< FutureTaskFactorytaskFactory
 

Detailed Description

Some raw subdevices might control several axes. This class knows how to map YARP commands to the right controlled motor axis or sensor of the correct subdevice given one or more indices, and forwards the call either in a sequential or parallel manner (see FutureTask).

For example, given three raw subdevices that manage one, two and three axes, respectively, a YARP command that requests global index '2' (zero-based) must be mapped to the second axis of the second subdevice and conveniently forwarded.

Terminology:

Member Function Documentation

◆ getDevices()

const std::vector<std::unique_ptr<const RawDevice> >& roboticslab::DeviceMapper::getDevices ( ) const
inline
Returns
A vector of raw device smart pointers.

◆ getMotorDevice()

DeviceMapper::dev_index_t DeviceMapper::getMotorDevice ( int  globalAxis) const
Parameters
globalAxisThe requested global axis index.

Aimed for simple, single-joint motor commands. See example and terminology in class description.

Returns
A pack of the subdevice handle and the obtained local index.

◆ getMotorDevicesWithIndices()

std::vector< DeviceMapper::dev_group_t > DeviceMapper::getMotorDevicesWithIndices ( int  globalAxesCount,
const int *  globalAxes 
) const

Aimed for joint-group motor commands. See example and terminology in class description.

Returns
A vector of packs of subdevices, their requested local indices, and the associated parameter offsets.

◆ getMotorDevicesWithOffsets()

std::vector< DeviceMapper::dev_index_t > DeviceMapper::getMotorDevicesWithOffsets ( ) const

Aimed for full-mapping motor commands. See example and terminology in class description.

Returns
A vector of packs of subdevice handles and their offsets.

◆ getSensorArraySize()

template<typename T >
std::size_t roboticslab::DeviceMapper::getSensorArraySize ( sensor_size_fn< T >  fn,
std::size_t  index 
) const
inline
Returns
An integer value representing the sensor array size.

◆ getSensorDevice()

template<typename T >
dev_index_t roboticslab::DeviceMapper::getSensorDevice ( int  globalIndex) const
inline
Parameters
globalAxisThe requested global sensor index.
Template Parameters
TThe requested sensor type.
Returns
A pack of the subdevice handle and the obtained local index.

◆ getSensorOutput()

template<typename T , typename... T_out_params>
bool roboticslab::DeviceMapper::getSensorOutput ( sensor_output_fn< T, T_out_params... >  fn,
std::size_t  index,
T_out_params &...  params 
) const
inline
Returns
True whether everything went fine, false otherwise.

◆ getSensorStatus()

template<typename T , typename T_out >
T_out roboticslab::DeviceMapper::getSensorStatus ( sensor_status_fn< T, T_out >  fn,
std::size_t  index 
) const
inline
Returns
An integer value representing sensor status.

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