21 YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSREMAPPER,
"yarp.device.multipleanalogsensorsremapper")
35 return "ThreeAxisGyroscopes";
38 return "ThreeAxisLinearAccelerometers";
41 return "ThreeAxisMagnetometers";
44 return "OrientationSensors";
47 return "TemperatureSensors";
50 return "SixAxisForceTorqueSensors";
53 return "ContactLoadCellArrays";
56 return "EncoderArrays";
62 return "PositionSensors";
66 return "MAS_getTagFromEnum_notExpectedEnum";
81 m_verbose = (prop.
check(
"verbose",
"if present, give detailed output"));
84 yCInfo(MULTIPLEANALOGSENSORSREMAPPER,
"Running with verbose output\n");
87 if(!parseOptions(prop))
100 bool keyExists = prop.
check(key);
103 if (!propList && keyExists)
105 yCError(MULTIPLEANALOGSENSORSREMAPPER) <<
"Error parsing parameters: if present " << key <<
" should be followed by a list of strings.\n";
109 if (!propList && !keyExists)
111 vectorOfStrings.resize(0);
115 vectorOfStrings.resize(propList->
size());
116 for (
size_t ax=0; ax < propList->
size(); ax++)
118 vectorOfStrings[ax] = propList->
get(ax).
asString();
124 bool MultipleAnalogSensorsRemapper::parseOptions(
const Property& prop)
137 yCError(MULTIPLEANALOGSENSORSREMAPPER) << optionName <<
"should be followed by a list of string.";
147 #define MAS_CALL_MEMBER_FN(object, ptrToMember) ((*object).*(ptrToMember))
150 template<
typename Interface>
151 bool MultipleAnalogSensorsRemapper::genericAttachAll(
const MAS_SensorType sensorType,
152 std::vector<Interface *>& subDeviceVec,
154 bool (Interface::*getNameMethodPtr)(
size_t, std::string&)
const,
155 size_t (Interface::*getNrOfSensorsMethodPtr)()
const)
157 std::map<std::string, SensorInSubDevice> sensorLocationMap;
159 subDeviceVec.resize(polylist.
size());
161 for(
int p=0; p<polylist.
size(); p++)
164 polylist[p]->poly->view(subDeviceVec[p]);
168 size_t nrOfSensorsInSubDevice =
MAS_CALL_MEMBER_FN(subDeviceVec[p], getNrOfSensorsMethodPtr)();
169 for (
size_t s=0; s < nrOfSensorsInSubDevice; s++)
175 yCError(MULTIPLEANALOGSENSORSREMAPPER) <<
"Failure in getting a name in the device " << polylist[p]->key;
180 if (sensorLocationMap.find(name) != sensorLocationMap.end())
182 SensorInSubDevice deviceWithSameName = sensorLocationMap.find(name)->second;
183 yCError(MULTIPLEANALOGSENSORSREMAPPER)
184 <<
"Sensor ambiguity: sensor with name"
186 <<
"present on both device"
188 << polylist[deviceWithSameName.subDevice]->key;
192 sensorLocationMap[name] = SensorInSubDevice(p, s);
198 std::vector<SensorInSubDevice>& sensIndicesMap = m_indicesMap[
static_cast<size_t>(sensorType)];
199 sensIndicesMap.resize(m_remappedSensors[sensorType].size());
200 for(
size_t i=0; i < m_remappedSensors[sensorType].size(); i++)
202 std::string name = m_remappedSensors[sensorType][i];
203 if (sensorLocationMap.find(name) == sensorLocationMap.end())
205 yCError(MULTIPLEANALOGSENSORSREMAPPER) <<
"Impossible to find sensor name" << name <<
", exiting.";
209 sensIndicesMap[i] = sensorLocationMap.find(name)->second;
222 &IThreeAxisGyroscopes::getThreeAxisGyroscopeName, &IThreeAxisGyroscopes::getNrOfThreeAxisGyroscopes);
224 &IThreeAxisLinearAccelerometers::getThreeAxisLinearAccelerometerName, &IThreeAxisLinearAccelerometers::getNrOfThreeAxisLinearAccelerometers);
226 &IThreeAxisMagnetometers::getThreeAxisMagnetometerName, &IThreeAxisMagnetometers::getNrOfThreeAxisMagnetometers);
227 ok = ok && genericAttachAll(
PositionSensors, m_iPositionSensors, polylist,
228 &IPositionSensors::getPositionSensorName, &IPositionSensors::getNrOfPositionSensors);
230 &IOrientationSensors::getOrientationSensorName, &IOrientationSensors::getNrOfOrientationSensors);
232 &ITemperatureSensors::getTemperatureSensorName, &ITemperatureSensors::getNrOfTemperatureSensors);
234 &ISixAxisForceTorqueSensors::getSixAxisForceTorqueSensorName, &ISixAxisForceTorqueSensors::getNrOfSixAxisForceTorqueSensors);
236 &IContactLoadCellArrays::getContactLoadCellArrayName, &IContactLoadCellArrays::getNrOfContactLoadCellArrays);
237 ok = ok && genericAttachAll(
EncoderArrays, m_iEncoderArrays, polylist,
238 &IEncoderArrays::getEncoderArrayName, &IEncoderArrays::getNrOfEncoderArrays);
239 ok = ok && genericAttachAll(
SkinPatches, m_iSkinPatches, polylist,
240 &ISkinPatches::getSkinPatchName, &ISkinPatches::getNrOfSkinPatches);
247 m_iThreeAxisGyroscopes.resize(0);
248 m_iThreeAxisLinearAccelerometers.resize(0);
249 m_iThreeAxisMagnetometers.resize(0);
250 m_iPositionSensors.resize(0);
251 m_iOrientationSensors.resize(0);
252 m_iTemperatureSensors.resize(0);
253 m_iSixAxisForceTorqueSensors.resize(0);
254 m_iContactLoadCellArrays.resize(0);
255 m_iEncoderArrays.resize(0);
256 m_iSkinPatches.resize(0);
257 m_indicesMap.resize(0);
262 template<
typename Interface>
265 const std::vector<Interface *>& subDeviceVec,
266 MAS_status (Interface::*methodPtr)(
size_t)
const)
const
268 size_t nrOfAvailableSensors = m_indicesMap[sensorType].size();
269 if (sens_index >= nrOfAvailableSensors)
273 yCError(MULTIPLEANALOGSENSORSREMAPPER,
"genericGetStatus sens_index %zu out of range of available sensors (%zu).", sens_index, nrOfAvailableSensors);
278 SensorInSubDevice subDeviceSensor = m_indicesMap[sensorType][sens_index];
279 return MAS_CALL_MEMBER_FN(subDeviceVec[subDeviceSensor.subDevice], methodPtr)(subDeviceSensor.indexInSubDevice);
282 template<
typename Interface>
283 bool MultipleAnalogSensorsRemapper::genericGetName(
const MAS_SensorType sensorType,
284 size_t& sens_index, std::string &name,
285 const std::vector<Interface *>& subDeviceVec,
286 bool (Interface::*methodPtr)(
size_t, std::string &)
const)
const
288 size_t nrOfAvailableSensors = m_indicesMap[sensorType].size();
289 if (sens_index >= nrOfAvailableSensors)
293 yCError(MULTIPLEANALOGSENSORSREMAPPER,
"genericGetName sens_index %zu out of range of available sensors (%zu).", sens_index, nrOfAvailableSensors);
298 SensorInSubDevice subDeviceSensor = m_indicesMap[sensorType][sens_index];
299 return MAS_CALL_MEMBER_FN(subDeviceVec[subDeviceSensor.subDevice], methodPtr)(subDeviceSensor.indexInSubDevice, name);
302 template<
typename Interface>
303 bool MultipleAnalogSensorsRemapper::genericGetFrameName(
const MAS_SensorType sensorType,
304 size_t& sens_index, std::string &name,
305 const std::vector<Interface *>& subDeviceVec,
306 bool (Interface::*methodPtr)(
size_t, std::string &)
const)
const
308 size_t nrOfAvailableSensors = m_indicesMap[sensorType].size();
309 if (sens_index >= nrOfAvailableSensors)
313 yCError(MULTIPLEANALOGSENSORSREMAPPER,
"genericGetFrameName sens_index %zu out of range of available sensors (%zu).", sens_index, nrOfAvailableSensors);
318 SensorInSubDevice subDeviceSensor = m_indicesMap[sensorType][sens_index];
319 return MAS_CALL_MEMBER_FN(subDeviceVec[subDeviceSensor.subDevice], methodPtr)(subDeviceSensor.indexInSubDevice, name);
323 template<
typename Interface>
324 bool MultipleAnalogSensorsRemapper::genericGetMeasure(
const MAS_SensorType sensorType,
326 const std::vector<Interface *>& subDeviceVec,
329 size_t nrOfAvailableSensors = m_indicesMap[sensorType].size();
330 if (sens_index >= nrOfAvailableSensors)
334 yCError(MULTIPLEANALOGSENSORSREMAPPER,
"genericGetMeasure sens_index %zu out of range of available sensors (%zu).", sens_index, nrOfAvailableSensors);
339 SensorInSubDevice subDeviceSensor = m_indicesMap[sensorType][sens_index];
340 return MAS_CALL_MEMBER_FN(subDeviceVec[subDeviceSensor.subDevice], methodPtr)(subDeviceSensor.indexInSubDevice, out, timestamp);
343 template<
typename Interface>
344 size_t MultipleAnalogSensorsRemapper::genericGetSize(
const MAS_SensorType sensorType,
346 const std::vector<Interface *>& subDeviceVec,
347 size_t (Interface::*methodPtr)(
size_t)
const)
const
349 size_t nrOfAvailableSensors = m_indicesMap[sensorType].size();
350 if (sens_index >= nrOfAvailableSensors)
354 yCError(MULTIPLEANALOGSENSORSREMAPPER,
"genericGetSize sens_index %zu out of range of available sensors (%zu).", sens_index, nrOfAvailableSensors);
359 SensorInSubDevice subDeviceSensor = m_indicesMap[sensorType][sens_index];
360 return MAS_CALL_MEMBER_FN(subDeviceVec[subDeviceSensor.subDevice], methodPtr)(subDeviceSensor.indexInSubDevice);
401 return genericGetStatus(
ThreeAxisGyroscopes, sens_index, m_iThreeAxisGyroscopes, &IThreeAxisGyroscopes::getThreeAxisGyroscopeStatus);
406 return genericGetName(
ThreeAxisGyroscopes, sens_index, name, m_iThreeAxisGyroscopes, &IThreeAxisGyroscopes::getThreeAxisGyroscopeName);
411 return genericGetFrameName(
ThreeAxisGyroscopes, sens_index, frameName, m_iThreeAxisGyroscopes, &IThreeAxisGyroscopes::getThreeAxisGyroscopeFrameName);
416 return genericGetMeasure(
ThreeAxisGyroscopes, sens_index, out, timestamp, m_iThreeAxisGyroscopes, &IThreeAxisGyroscopes::getThreeAxisGyroscopeMeasure);
426 return genericGetStatus(
ThreeAxisLinearAccelerometers, sens_index, m_iThreeAxisLinearAccelerometers, &IThreeAxisLinearAccelerometers::getThreeAxisLinearAccelerometerStatus);
431 return genericGetName(
ThreeAxisLinearAccelerometers, sens_index, name, m_iThreeAxisLinearAccelerometers, &IThreeAxisLinearAccelerometers::getThreeAxisLinearAccelerometerName);
436 return genericGetFrameName(
ThreeAxisLinearAccelerometers, sens_index, frameName, m_iThreeAxisLinearAccelerometers, &IThreeAxisLinearAccelerometers::getThreeAxisLinearAccelerometerFrameName);
441 return genericGetMeasure(
ThreeAxisLinearAccelerometers, sens_index, out, timestamp, m_iThreeAxisLinearAccelerometers, &IThreeAxisLinearAccelerometers::getThreeAxisLinearAccelerometerMeasure);
451 return genericGetStatus(
ThreeAxisMagnetometers, sens_index, m_iThreeAxisMagnetometers, &IThreeAxisMagnetometers::getThreeAxisMagnetometerStatus);
456 return genericGetName(
ThreeAxisMagnetometers, sens_index, name, m_iThreeAxisMagnetometers, &IThreeAxisMagnetometers::getThreeAxisMagnetometerName);
461 return genericGetFrameName(
ThreeAxisMagnetometers, sens_index, frameName, m_iThreeAxisMagnetometers, &IThreeAxisMagnetometers::getThreeAxisMagnetometerFrameName);
466 return genericGetMeasure(
ThreeAxisMagnetometers, sens_index, out, timestamp, m_iThreeAxisMagnetometers, &IThreeAxisMagnetometers::getThreeAxisMagnetometerMeasure);
476 return genericGetStatus(
PositionSensors, sens_index, m_iPositionSensors, &IPositionSensors::getPositionSensorStatus);
481 return genericGetName(
PositionSensors, sens_index, name, m_iPositionSensors, &IPositionSensors::getPositionSensorName);
486 return genericGetFrameName(
PositionSensors, sens_index, frameName, m_iPositionSensors, &IPositionSensors::getPositionSensorFrameName);
491 return genericGetMeasure(
PositionSensors, sens_index, out, timestamp, m_iPositionSensors, &IPositionSensors::getPositionSensorMeasure);
501 return genericGetStatus(
OrientationSensors, sens_index, m_iOrientationSensors, &IOrientationSensors::getOrientationSensorStatus);
506 return genericGetName(
OrientationSensors, sens_index, name, m_iOrientationSensors, &IOrientationSensors::getOrientationSensorName);
511 return genericGetFrameName(
OrientationSensors, sens_index, frameName, m_iOrientationSensors, &IOrientationSensors::getOrientationSensorFrameName);
516 return genericGetMeasure(
OrientationSensors, sens_index, out, timestamp, m_iOrientationSensors, &IOrientationSensors::getOrientationSensorMeasureAsRollPitchYaw);
526 return genericGetStatus(
TemperatureSensors, sens_index, m_iTemperatureSensors, &ITemperatureSensors::getTemperatureSensorStatus);
531 return genericGetName(
TemperatureSensors, sens_index, name, m_iTemperatureSensors, &ITemperatureSensors::getTemperatureSensorName);
536 return genericGetFrameName(
TemperatureSensors, sens_index, frameName, m_iTemperatureSensors, &ITemperatureSensors::getTemperatureSensorFrameName);
541 return genericGetMeasure(
TemperatureSensors, sens_index, out, timestamp, m_iTemperatureSensors, &ITemperatureSensors::getTemperatureSensorMeasure);
547 bool ok = genericGetMeasure(
TemperatureSensors, sens_index, dummy, timestamp, m_iTemperatureSensors, &ITemperatureSensors::getTemperatureSensorMeasure);
559 return genericGetStatus(
SixAxisForceTorqueSensors, sens_index, m_iSixAxisForceTorqueSensors, &ISixAxisForceTorqueSensors::getSixAxisForceTorqueSensorStatus);
564 return genericGetName(
SixAxisForceTorqueSensors, sens_index, name, m_iSixAxisForceTorqueSensors, &ISixAxisForceTorqueSensors::getSixAxisForceTorqueSensorName);
569 return genericGetFrameName(
SixAxisForceTorqueSensors, sens_index, frameName, m_iSixAxisForceTorqueSensors, &ISixAxisForceTorqueSensors::getSixAxisForceTorqueSensorFrameName);
574 return genericGetMeasure(
SixAxisForceTorqueSensors, sens_index, out, timestamp, m_iSixAxisForceTorqueSensors, &ISixAxisForceTorqueSensors::getSixAxisForceTorqueSensorMeasure);
584 return genericGetStatus(
ContactLoadCellArrays, sens_index, m_iContactLoadCellArrays, &IContactLoadCellArrays::getContactLoadCellArrayStatus);
589 return genericGetName(
ContactLoadCellArrays, sens_index, name, m_iContactLoadCellArrays, &IContactLoadCellArrays::getContactLoadCellArrayName);
594 return genericGetMeasure(
ContactLoadCellArrays, sens_index, out, timestamp, m_iContactLoadCellArrays, &IContactLoadCellArrays::getContactLoadCellArrayMeasure);
599 return genericGetSize(
ContactLoadCellArrays, sens_index, m_iContactLoadCellArrays, &IContactLoadCellArrays::getContactLoadCellArraySize);
609 return genericGetStatus(
EncoderArrays, sens_index, m_iEncoderArrays, &IEncoderArrays::getEncoderArrayStatus);
614 return genericGetName(
EncoderArrays, sens_index, name, m_iEncoderArrays, &IEncoderArrays::getEncoderArrayName);
619 return genericGetMeasure(
EncoderArrays, sens_index, out, timestamp, m_iEncoderArrays, &IEncoderArrays::getEncoderArrayMeasure);
624 return genericGetSize(
EncoderArrays, sens_index, m_iEncoderArrays, &IEncoderArrays::getEncoderArraySize);
634 return genericGetStatus(
SkinPatches, sens_index, m_iSkinPatches, &ISkinPatches::getSkinPatchStatus);
639 return genericGetName(
SkinPatches, sens_index, name, m_iSkinPatches, &ISkinPatches::getSkinPatchName);
644 return genericGetMeasure(
SkinPatches, sens_index, out, timestamp, m_iSkinPatches, &ISkinPatches::getSkinPatchMeasure);
649 return genericGetSize(
SkinPatches, sens_index, m_iSkinPatches, &ISkinPatches::getSkinPatchSize);