YARP
Yet Another Robot Platform
MultipleAnalogSensorsRemapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 
10 #ifndef YARP_DEV_MULTIPLEANALOGSENSORSREMAPPER_MULTIPLEANALOGSENSORSREMAPPER_H
11 #define YARP_DEV_MULTIPLEANALOGSENSORSREMAPPER_MULTIPLEANALOGSENSORSREMAPPER_H
12 
15 
16 #include <vector>
17 #include <map>
18 
19 
24 {
35 };
36 
100 {
101 private:
102  bool m_verbose{false};
103 
104  bool parseOptions(const yarp::os::Property& prop);
105 
106  // Map from remapped indices to underlyng subdevice indices
107  class SensorInSubDevice
108  {
109  public:
110  SensorInSubDevice(): subDevice(0), indexInSubDevice(0)
111  {}
112  SensorInSubDevice(size_t p_subDevice, size_t p_indexInSubDevice):
113  subDevice(p_subDevice), indexInSubDevice(p_indexInSubDevice) {}
114 
115  size_t subDevice;
116  size_t indexInSubDevice;
117  };
118 
119  std::vector< std::vector<std::string> > m_remappedSensors;
120  std::vector< std::vector<SensorInSubDevice> > m_indicesMap;
121 
122  std::vector<yarp::dev::IThreeAxisGyroscopes*> m_iThreeAxisGyroscopes;
123  std::vector<yarp::dev::IThreeAxisLinearAccelerometers*> m_iThreeAxisLinearAccelerometers;
124  std::vector<yarp::dev::IThreeAxisMagnetometers*> m_iThreeAxisMagnetometers;
125  std::vector<yarp::dev::IOrientationSensors*> m_iOrientationSensors;
126  std::vector<yarp::dev::ITemperatureSensors*> m_iTemperatureSensors;
127  std::vector<yarp::dev::ISixAxisForceTorqueSensors*> m_iSixAxisForceTorqueSensors;
128  std::vector<yarp::dev::IContactLoadCellArrays*> m_iContactLoadCellArrays;
129  std::vector<yarp::dev::IEncoderArrays*> m_iEncoderArrays;
130  std::vector<yarp::dev::ISkinPatches*> m_iSkinPatches;
131  std::vector<yarp::dev::IPositionSensors*> m_iPositionSensors;
132 
133 
134  // Templated methods to streamline of the function implementation for all the different sensors
135  // This part is complicated, but is useful to avoid a huge code duplication
136  // To understand this code, make sure that you are familiar with:
137  // * Method templates ( http://en.cppreference.com/w/cpp/language/member_template )
138  // * Pointer to method functions ( http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_member_functions )
139  template<typename Interface>
140  yarp::dev::MAS_status genericGetStatus(const MAS_SensorType sensorType,
141  size_t& sens_index,
142  const std::vector<Interface *>& subDeviceVec,
143  yarp::dev::MAS_status (Interface::*methodPtr)(size_t) const) const;
144  template<typename Interface>
145  bool genericGetName(const MAS_SensorType sensorType,
146  size_t& sens_index, std::string &name,
147  const std::vector<Interface *>& subDeviceVec,
148  bool (Interface::*methodPtr)(size_t, std::string&) const) const;
149  template<typename Interface>
150  bool genericGetFrameName(const MAS_SensorType sensorType,
151  size_t& sens_index, std::string &name,
152  const std::vector<Interface *>& subDeviceVec,
153  bool (Interface::*methodPtr)(size_t, std::string&) const) const;
154  template<typename Interface>
155  bool genericGetMeasure(const MAS_SensorType sensorType,
156  size_t& sens_index, yarp::sig::Vector& out, double& timestamp,
157  const std::vector<Interface *>& subDeviceVec,
158  bool (Interface::*methodPtr)(size_t, yarp::sig::Vector&, double&) const) const;
159  template<typename Interface>
160  size_t genericGetSize(const MAS_SensorType sensorType,
161  size_t& sens_index,
162  const std::vector<Interface *>& subDeviceVec,
163  size_t (Interface::*methodPtr)(size_t) const) const;
164 
165  template<typename Interface>
166  bool genericAttachAll(const MAS_SensorType sensorType,
167  std::vector<Interface *>& subDeviceVec,
168  const yarp::dev::PolyDriverList &polylist,
169  bool (Interface::*getNameMethodPtr)(size_t, std::string&) const,
170  size_t (Interface::*getNrOfSensorsMethodPtr)() const);
171 
172 public:
173  /* DeviceDriver methods */
174  bool open(yarp::os::Searchable& config) override;
175  bool close() override;
176 
178  bool attachAll(const yarp::dev::PolyDriverList &p) override;
179  bool detachAll() override;
180 
181  /* IThreeAxisGyroscopes methods */
182  size_t getNrOfThreeAxisGyroscopes() const override;
183  yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override;
184  bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override;
185  bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override;
186  bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
187 
188  /* IThreeAxisLinearAccelerometers methods */
189  size_t getNrOfThreeAxisLinearAccelerometers() const override;
190  yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override;
191  bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override;
192  bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override;
193  bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
194 
195  /* IThreeAxisMagnetometers methods */
196  size_t getNrOfThreeAxisMagnetometers() const override;
197  yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override;
198  bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override;
199  bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override;
200  bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
201 
202  /* IOrientationSensors methods */
203  size_t getNrOfOrientationSensors() const override;
204  yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override;
205  bool getOrientationSensorName(size_t sens_index, std::string &name) const override;
206  bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override;
207  bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector& rpy, double& timestamp) const override;
208 
209  /* ITemperatureSensors methods */
210  size_t getNrOfTemperatureSensors() const override;
211  yarp::dev::MAS_status getTemperatureSensorStatus(size_t sens_index) const override;
212  bool getTemperatureSensorName(size_t sens_index, std::string &name) const override;
213  bool getTemperatureSensorFrameName(size_t sens_index, std::string &frameName) const override;
214  bool getTemperatureSensorMeasure(size_t sens_index, double& out, double& timestamp) const override;
215  bool getTemperatureSensorMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
216 
217  /* ISixAxisForceTorqueSensors */
218  size_t getNrOfSixAxisForceTorqueSensors() const override;
219  yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sens_index) const override;
220  bool getSixAxisForceTorqueSensorName(size_t sens_index, std::string &name) const override;
221  bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frame) const override;
222  bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
223 
224  /* IContactLoadCellArrays */
225  size_t getNrOfContactLoadCellArrays() const override;
226  yarp::dev::MAS_status getContactLoadCellArrayStatus(size_t sens_index) const override;
227  bool getContactLoadCellArrayName(size_t sens_index, std::string &name) const override;
228  bool getContactLoadCellArrayMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
229  size_t getContactLoadCellArraySize(size_t sens_index) const override;
230 
231  /* IEncoderArrays */
232  size_t getNrOfEncoderArrays() const override;
233  yarp::dev::MAS_status getEncoderArrayStatus(size_t sens_index) const override;
234  bool getEncoderArrayName(size_t sens_index, std::string &name) const override;
235  bool getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
236  size_t getEncoderArraySize(size_t sens_index) const override;
237 
238  /* ISkinPatches */
239  size_t getNrOfSkinPatches() const override;
240  yarp::dev::MAS_status getSkinPatchStatus(size_t sens_index) const override;
241  bool getSkinPatchName(size_t sens_index, std::string &name) const override;
242  bool getSkinPatchMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
243  size_t getSkinPatchSize(size_t sens_index) const override;
244 
245  /* IPositionSensors methods */
246  size_t getNrOfPositionSensors() const override;
247  yarp::dev::MAS_status getPositionSensorStatus(size_t sens_index) const override;
248  bool getPositionSensorName(size_t sens_index, std::string& name) const override;
249  bool getPositionSensorFrameName(size_t sens_index, std::string& frameName) const override;
250  bool getPositionSensorMeasure(size_t sens_index, yarp::sig::Vector& xyz, double& timestamp) const override;
251 };
252 
253 
254 #endif
MAS_SensorType
Internal identifier of the type of sensors.
@ ThreeAxisLinearAccelerometers
multipleanalogsensorsremapper : device that takes a list of sensor from multiple analog sensors devic...
size_t getNrOfEncoderArrays() const override
Get the number of encoder arrays exposed by this device.
bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
size_t getContactLoadCellArraySize(size_t sens_index) const override
Get the size of the specified contact load cell array.
size_t getNrOfSkinPatches() const override
Get the number of skin patches exposed by this device.
size_t getNrOfThreeAxisLinearAccelerometers() const override
Get the number of three axis linear accelerometers exposed by this device.
bool getTemperatureSensorMeasure(size_t sens_index, double &out, double &timestamp) const override
Get the last reading of the specified sensor.
bool getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
bool close() override
Close the DeviceDriver.
bool getContactLoadCellArrayMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool detachAll() override
Detach the object (you must have first called attach).
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool attachAll(const yarp::dev::PolyDriverList &p) override
MultipeWrapper methods.
bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
size_t getNrOfOrientationSensors() const override
Get the number of orientation sensors exposed by this device.
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the gyroscope.
size_t getNrOfPositionSensors() const override
Get the number of position sensors exposed by this device.
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::MAS_status getPositionSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
size_t getNrOfThreeAxisGyroscopes() const override
Get the number of three axis gyroscopes exposed by this sensor.
bool getPositionSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
size_t getEncoderArraySize(size_t sens_index) const override
Get the size of the specified encoder array.
bool getPositionSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getContactLoadCellArrayName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
size_t getNrOfThreeAxisMagnetometers() const override
Get the number of magnetometers exposed by this device.
yarp::dev::MAS_status getSkinPatchStatus(size_t sens_index) const override
Get the status of the specified sensor.
size_t getNrOfContactLoadCellArrays() const override
Get the number of contact load cell array exposed by this device.
yarp::dev::MAS_status getEncoderArrayStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getTemperatureSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
bool getPositionSensorMeasure(size_t sens_index, yarp::sig::Vector &xyz, double &timestamp) const override
Get the last reading of the position sensor as x y z.
yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
size_t getNrOfTemperatureSensors() const override
Get the number of temperature sensors exposed by this device.
bool getTemperatureSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
yarp::dev::MAS_status getContactLoadCellArrayStatus(size_t sens_index) const override
Get the status of the specified sensor.
yarp::dev::MAS_status getTemperatureSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getSkinPatchMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
size_t getNrOfSixAxisForceTorqueSensors() const override
Get the number of six axis force torque sensors exposed by this device.
bool getSixAxisForceTorqueSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
size_t getSkinPatchSize(size_t sens_index) const override
Get the size of the specified skin patch.
bool getEncoderArrayName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getSkinPatchName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
Get the status of the specified sensor.
bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frame) const override
Get the name of the frame of the specified sensor.
bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double &timestamp) const override
Get the last reading of the orientation sensor as roll pitch yaw.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Device interface to one or multiple contact load cell arrays.
Device interface to one or multiple arrays of encoders.
Interface for an object that can wrap/attach to to another.
Device interface to one or multiple orientation sensors, such as IMUs with on board estimation algori...
Device interface to one or multiple position sensors, such as UWB localization sensors.
Device interface to one or multiple six axis force torque sensor.
Device interface to one or more groups (patches) of tactile sensors (skin).
Device interface to one or multiple temperature sensors.
Device interface to one or multiple three axis gyroscopes.
Device interface to one or multiple three axis linear accelerometers.
Device interface to one or multiple three axis magnetometers.
A class for storing options and configuration information.
Definition: Property.h:37
A base class for nested structures that can be searched.
Definition: Searchable.h:69
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.