18YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSSERVER,
"yarp.device.multipleanalogsensorsserver")
91 return "MAS_WAITING_FOR_FIRST_READ";
115 if (!config.
check(
"name"))
117 yCError(MULTIPLEANALOGSENSORSSERVER,
"Missing name parameter, exiting.");
121 if (!config.
check(
"period"))
123 yCError(MULTIPLEANALOGSENSORSSERVER,
"Missing period parameter, exiting.");
127 if (!config.
find(
"period").isInt32())
129 yCError(MULTIPLEANALOGSENSORSSERVER,
"Period parameter is present but it is not an integer, exiting.");
133 m_periodInS = config.
find(
"period").asInt32() / 1000.0;
135 if (m_periodInS <= 0)
137 yCError(MULTIPLEANALOGSENSORSSERVER,
138 "Period parameter is present (%f) but it is not a positive integer, exiting.",
143 std::string name = config.
find(
"name").asString();
152 m_RPCPortName = name +
"/rpc:o";
153 m_streamingPortName = name +
"/measures:o";
155 if (config.
check(
"subdevice"))
157 std::string subdeviceName = config.
find(
"subdevice").asString();
161 driverConfig.setMonitor(config.getMonitor(), subdeviceName.c_str());
162 driverConfig.
put(
"device", subdeviceName);
164 if (!m_subdevice.
open(driverConfig))
166 yCError(MULTIPLEANALOGSENSORSSERVER,
"Opening subdevice failed.");
171 driverList.
push(&m_subdevice, subdeviceName.c_str());
175 yCError(MULTIPLEANALOGSENSORSSERVER,
"Attaching subdevice failed.");
179 yCInfo(MULTIPLEANALOGSENSORSSERVER,
180 "Subdevice \"%s\" successfully configured and attached.",
181 subdeviceName.c_str());
182 m_isDeviceOwned =
true;
185 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Open complete");
195 ok &= m_subdevice.
close();
196 m_isDeviceOwned =
false;
199 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Close complete");
205#define MAS_CALL_MEMBER_FN(object, ptrToMember) ((*object).*(ptrToMember))
207template<
typename Interface>
208bool MultipleAnalogSensorsServer::populateSensorsMetadata(Interface * wrappedDeviceInterface,
209 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
210 size_t (Interface::*getNrOfSensorsMethodPtr)() const,
211 bool (Interface::*getNameMethodPtr)(
size_t,
std::string&) const,
212 bool (Interface::*getFrameNameMethodPtr)(
size_t,
std::string&) const)
214 if (wrappedDeviceInterface)
216 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
217 metadataVector.resize(nrOfSensors);
218 for (
size_t i=0; i < nrOfSensors; i++)
220 std::string sensorName;
221 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
224 yCError(MULTIPLEANALOGSENSORSSERVER,
225 "Failure in reading name of sensor of type %s at index %zu.",
230 std::string frameName;
234 yCError(MULTIPLEANALOGSENSORSSERVER,
235 "Failure in reading frame name of sensor of type %s at index %zu.",
241 metadataVector[i].name = sensorName;
242 metadataVector[i].frameName = frameName;
243 metadataVector[i].additionalMetadata =
"";
249 metadataVector.resize(0);
254template<
typename Interface>
255bool MultipleAnalogSensorsServer::populateSensorsMetadataNoFrameName(Interface * wrappedDeviceInterface,
256 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
257 size_t (Interface::*getNrOfSensorsMethodPtr)() const,
258 bool (Interface::*getNameMethodPtr)(
size_t,
std::string&) const)
260 if (wrappedDeviceInterface)
262 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
263 metadataVector.resize(nrOfSensors);
264 for (
size_t i=0; i < nrOfSensors; i++)
266 std::string sensorName;
267 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
270 yCError(MULTIPLEANALOGSENSORSSERVER,
271 "Failure in reading name of sensor of type %s at index %zu.",
277 metadataVector[i].name = sensorName;
278 metadataVector[i].frameName =
"";
279 metadataVector[i].additionalMetadata =
"";
285 metadataVector.resize(0);
291bool MultipleAnalogSensorsServer::populateAllSensorsMetadata()
294 ok = ok && populateSensorsMetadata(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes",
298 ok = ok && populateSensorsMetadata(m_iThreeAxisLinearAccelerometers, m_sensorMetadata.
ThreeAxisLinearAccelerometers,
"ThreeAxisLinearAccelerometers",
302 ok = ok && populateSensorsMetadata(m_iThreeAxisMagnetometers, m_sensorMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers",
306 ok = ok && populateSensorsMetadata(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
"PositionSensors",
310 ok = ok && populateSensorsMetadata(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
"OrientationSensors",
314 ok = ok && populateSensorsMetadata(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
"TemperatureSensors",
318 ok = ok && populateSensorsMetadata(m_iSixAxisForceTorqueSensors, m_sensorMetadata.
SixAxisForceTorqueSensors,
"SixAxisForceTorqueSensors",
322 ok = ok && populateSensorsMetadataNoFrameName(m_iContactLoadCellArrays, m_sensorMetadata.
ContactLoadCellArrays,
"ContactLoadCellArrays",
325 ok = ok && populateSensorsMetadataNoFrameName(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
"EncoderArrays",
328 ok = ok && populateSensorsMetadataNoFrameName(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
"ISkinPatches",
336template<
typename Interface>
337bool MultipleAnalogSensorsServer::resizeMeasureVectors(Interface* wrappedDeviceInterface,
338 const std::vector< SensorMetadata >& metadataVector,
339 std::vector< SensorMeasurement >& streamingDataVector,
340 size_t (Interface::*getMeasureSizePtr)(
size_t) const)
342 if (wrappedDeviceInterface)
344 size_t nrOfSensors = metadataVector.size();
345 streamingDataVector.resize(nrOfSensors);
346 for (
size_t i=0; i < nrOfSensors; i++)
348 size_t measureSize =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureSizePtr)(i);
349 streamingDataVector[i].measurement.resize(measureSize, std::numeric_limits<double>::quiet_NaN());
357template<
typename Interface>
358bool MultipleAnalogSensorsServer::resizeMeasureVectors(Interface* wrappedDeviceInterface,
359 const std::vector< SensorMetadata >& metadataVector,
360 std::vector< SensorMeasurement >& streamingDataVector,
363 if (wrappedDeviceInterface)
365 size_t nrOfSensors = metadataVector.size();
366 streamingDataVector.resize(nrOfSensors);
367 for (
size_t i=0; i < nrOfSensors; i++)
369 streamingDataVector[i].measurement.resize(measureSize, std::numeric_limits<double>::quiet_NaN());
376bool MultipleAnalogSensorsServer::resizeAllMeasureVectors(
SensorStreamingData& streamingData)
380 ok = ok && resizeMeasureVectors(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
386 ok = ok && resizeMeasureVectors(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
388 ok = ok && resizeMeasureVectors(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
390 ok = ok && resizeMeasureVectors(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
396 ok = ok && resizeMeasureVectors(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
398 ok = ok && resizeMeasureVectors(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
409 yCError(MULTIPLEANALOGSENSORSSERVER,
410 "This device only supports exposing a "
411 "single MultipleAnalogSensors device on YARP ports, but %d devices have been passed in attachAll.",
413 yCError(MULTIPLEANALOGSENSORSSERVER,
414 "Please use the multipleanalogsensorsremapper device to combine several device in a new device.");
421 yCError(MULTIPLEANALOGSENSORSSERVER,
"No device passed to attachAll, please pass a device to expose on YARP ports.");
430 yCError(MULTIPLEANALOGSENSORSSERVER,
"Null pointer passed to attachAll.");
436 poly->
view(m_iThreeAxisGyroscopes);
437 poly->
view(m_iThreeAxisLinearAccelerometers);
438 poly->
view(m_iThreeAxisMagnetometers);
439 poly->
view(m_iPositionSensors);
440 poly->
view(m_iOrientationSensors);
441 poly->
view(m_iTemperatureSensors);
442 poly->
view(m_iSixAxisForceTorqueSensors);
443 poly->
view(m_iContactLoadCellArrays);
444 poly->
view(m_iEncoderArrays);
445 poly->
view(m_iSkinPatches);
449 bool ok = populateAllSensorsMetadata();
453 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in populateAllSensorsMetadata()");
459 ok = m_streamingPort.
open(m_streamingPortName);
462 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_streamingPortName.c_str());
470 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in attaching RPC port to thrift RPC interface.");
475 ok = m_rpcPort.
open(m_RPCPortName);
478 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_RPCPortName.c_str());
485 ok = ok && this->
start();
488 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in starting thread.");
493 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Attach complete");
506 m_streamingPort.
close();
508 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Detach complete");
514 return m_sensorMetadata;
517template<
typename Interface>
518bool MultipleAnalogSensorsServer::genericStreamData(Interface* wrappedDeviceInterface,
519 const std::vector< SensorMetadata >& metadataVector,
520 std::vector< SensorMeasurement >& streamingDataVector,
522 bool (Interface::*getMeasureMethodPtr)(
size_t,
yarp::sig::Vector&, double&) const,
523 const char* sensorType)
525 if (wrappedDeviceInterface)
527 size_t nrOfSensors = metadataVector.size();
528 for (
size_t i=0; i < nrOfSensors; i++)
531 double& outputTimestamp = streamingDataVector[i].timestamp;
535 MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureMethodPtr)(i, outputBuffer, outputTimestamp);
538 yCError(MULTIPLEANALOGSENSORSSERVER,
539 "Failure in reading data from sensor %s of type %s with code %s, no data will be sent on the port.",
556 ok = resizeAllMeasureVectors(streamingData);
563 "ThreeAxisGyroscope");
569 "ThreeAxisLinearAccelerometer");
575 "ThreeAxisMagnetometer");
577 ok = ok && genericStreamData(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
583 ok = ok && genericStreamData(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
587 "OrientationSensor");
589 ok = ok && genericStreamData(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
593 "TemperatureSensor");
599 "SixAxisForceTorqueSensor");
605 "ContactLoadCellArrays");
607 ok = ok && genericStreamData(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
613 ok = ok && genericStreamData(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
623 m_streamingPort.
write();
#define MAS_CALL_MEMBER_FN(object, ptrToMember)
@ ThreeAxisLinearAccelerometers
@ SixAxisForceTorqueSensors
std::vector< SensorMeasurement > measurements
std::vector< SensorMetadata > SkinPatches
std::vector< SensorMetadata > ContactLoadCellArrays
std::vector< SensorMetadata > EncoderArrays
std::vector< SensorMetadata > PositionSensors
std::vector< SensorMetadata > ThreeAxisGyroscopes
std::vector< SensorMetadata > ThreeAxisLinearAccelerometers
std::vector< SensorMetadata > ThreeAxisMagnetometers
std::vector< SensorMetadata > OrientationSensors
std::vector< SensorMetadata > SixAxisForceTorqueSensors
std::vector< SensorMetadata > TemperatureSensors
SensorMeasurements EncoderArrays
SensorMeasurements ThreeAxisLinearAccelerometers
SensorMeasurements PositionSensors
SensorMeasurements OrientationSensors
SensorMeasurements ThreeAxisMagnetometers
SensorMeasurements ThreeAxisGyroscopes
SensorMeasurements SixAxisForceTorqueSensors
SensorMeasurements SkinPatches
SensorMeasurements ContactLoadCellArrays
SensorMeasurements TemperatureSensors
bool view(T *&x)
Get an interface to the device driver.
virtual bool getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual size_t getEncoderArraySize(size_t sens_index) const =0
Get the size of the specified encoder array.
virtual size_t getNrOfEncoderArrays() const =0
Get the number of encoder arrays exposed by this device.
virtual yarp::dev::MAS_status getEncoderArrayStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getEncoderArrayName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getOrientationSensorName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfOrientationSensors() const =0
Get the number of orientation sensors exposed by this device.
virtual bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double ×tamp) const =0
Get the last reading of the orientation sensor as roll pitch yaw.
virtual bool getPositionSensorMeasure(size_t sens_index, yarp::sig::Vector &xyz, double ×tamp) const =0
Get the last reading of the position sensor as x y z.
virtual bool getPositionSensorName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfPositionSensors() const =0
Get the number of position sensors exposed by this device.
virtual yarp::dev::MAS_status getPositionSensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getPositionSensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual size_t getNrOfSixAxisForceTorqueSensors() const =0
Get the number of six axis force torque sensors exposed by this device.
virtual yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getSixAxisForceTorqueSensorName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual bool getSkinPatchName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfSkinPatches() const =0
Get the number of skin patches exposed by this device.
virtual size_t getSkinPatchSize(size_t sens_index) const =0
Get the size of the specified skin patch.
virtual yarp::dev::MAS_status getSkinPatchStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getSkinPatchMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual bool getTemperatureSensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getTemperatureSensorName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual yarp::dev::MAS_status getTemperatureSensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getTemperatureSensorMeasure(size_t sens_index, double &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual size_t getNrOfTemperatureSensors() const =0
Get the number of temperature sensors exposed by this device.
virtual yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfThreeAxisGyroscopes() const =0
Get the number of three axis gyroscopes exposed by this sensor.
virtual bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the gyroscope.
virtual bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfThreeAxisLinearAccelerometers() const =0
Get the number of three axis linear accelerometers exposed by this device.
virtual bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfThreeAxisMagnetometers() const =0
Get the number of magnetometers exposed by this device.
virtual yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
void push(PolyDriver *p, const char *k)
A container for a device driver.
bool close() override
Close the DeviceDriver.
bool open(const std::string &txt)
Construct and configure a device by its common name.
void close() override
Stop port activity.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
bool unprepare()
Give the last prepared object back to YARP without writing it.
bool setPeriod(double period)
Set the (new) period of the thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
bool attachAsServer(yarp::os::UnbufferedContactable &port)
Tag this WireLink as a server, receiving commands via the specified port.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
void resize(size_t size) override
Resize the vector.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.
@ MAS_UNKNOWN
The sensor is in an unknown state.
@ MAS_TIMEOUT
The sensor is read through the network, and the latest measurement was received before an implementat...
@ MAS_ERROR
The sensor is in generic error state.
@ MAS_WAITING_FOR_FIRST_READ
The sensor is read through the network, and the device is waiting to receive the first measurement.
@ MAS_OK
The sensor is working correctly.
@ MAS_OVF
The sensor reached an overflow.
The main, catch-all namespace for YARP.