18YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSSERVER,
"yarp.device.multipleanalogsensorsserver")
99 return "MAS_WAITING_FOR_FIRST_READ";
102 return "MAS_UNKNOWN";
127 if (m_periodInS <= 0)
129 yCError(MULTIPLEANALOGSENSORSSERVER,
130 "Period parameter is present (%f) but it is not a positive integer, exiting.",
142 m_RPCPortName =
m_name +
"/rpc:o";
143 m_streamingPortName =
m_name +
"/measures:o";
157#define MAS_CALL_MEMBER_FN(object, ptrToMember) ((*object).*(ptrToMember))
159template<
typename Interface>
160bool MultipleAnalogSensorsServer::populateSensorsMetadata(Interface * wrappedDeviceInterface,
161 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
162 size_t (Interface::*getNrOfSensorsMethodPtr)() const,
163 bool (Interface::*getNameMethodPtr)(
size_t,
std::string&) const,
164 bool (Interface::*getFrameNameMethodPtr)(
size_t,
std::string&) const)
166 if (wrappedDeviceInterface)
168 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
169 metadataVector.resize(nrOfSensors);
170 for (
size_t i=0; i < nrOfSensors; i++)
172 std::string sensorName;
173 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
176 yCError(MULTIPLEANALOGSENSORSSERVER,
177 "Failure in reading name of sensor of type %s at index %zu.",
182 std::string frameName;
186 yCError(MULTIPLEANALOGSENSORSSERVER,
187 "Failure in reading frame name of sensor of type %s at index %zu.",
193 metadataVector[i].name = sensorName;
194 metadataVector[i].frameName = frameName;
195 metadataVector[i].additionalMetadata =
"";
201 metadataVector.resize(0);
206template<
typename Interface>
207bool MultipleAnalogSensorsServer::populateSensorsMetadataNoFrameName(Interface * wrappedDeviceInterface,
208 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
209 size_t (Interface::*getNrOfSensorsMethodPtr)() const,
210 bool (Interface::*getNameMethodPtr)(
size_t,
std::string&) const)
212 if (wrappedDeviceInterface)
214 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
215 metadataVector.resize(nrOfSensors);
216 for (
size_t i=0; i < nrOfSensors; i++)
218 std::string sensorName;
219 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
222 yCError(MULTIPLEANALOGSENSORSSERVER,
223 "Failure in reading name of sensor of type %s at index %zu.",
229 metadataVector[i].name = sensorName;
230 metadataVector[i].frameName =
"";
231 metadataVector[i].additionalMetadata =
"";
237 metadataVector.resize(0);
243bool MultipleAnalogSensorsServer::populateAllSensorsMetadata()
246 ok = ok && populateSensorsMetadata(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes",
250 ok = ok && populateSensorsMetadata(m_iThreeAxisLinearAccelerometers, m_sensorMetadata.
ThreeAxisLinearAccelerometers,
"ThreeAxisLinearAccelerometers",
254 ok = ok && populateSensorsMetadata(m_iThreeAxisAngularAccelerometers, m_sensorMetadata.
ThreeAxisAngularAccelerometers,
"ThreeAxisAngularAccelerometers",
258 ok = ok && populateSensorsMetadata(m_iThreeAxisMagnetometers, m_sensorMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers",
262 ok = ok && populateSensorsMetadata(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
"PositionSensors",
266 ok = ok && populateSensorsMetadata(m_iLinearVelocitySensors, m_sensorMetadata.
LinearVelocitySensors,
"LinearVelocitySensors",
270 ok = ok && populateSensorsMetadata(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
"OrientationSensors",
274 ok = ok && populateSensorsMetadata(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
"TemperatureSensors",
278 ok = ok && populateSensorsMetadata(m_iSixAxisForceTorqueSensors, m_sensorMetadata.
SixAxisForceTorqueSensors,
"SixAxisForceTorqueSensors",
282 ok = ok && populateSensorsMetadataNoFrameName(m_iContactLoadCellArrays, m_sensorMetadata.
ContactLoadCellArrays,
"ContactLoadCellArrays",
285 ok = ok && populateSensorsMetadataNoFrameName(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
"EncoderArrays",
288 ok = ok && populateSensorsMetadataNoFrameName(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
"ISkinPatches",
296template<
typename Interface>
297bool MultipleAnalogSensorsServer::resizeMeasureVectors(Interface* wrappedDeviceInterface,
298 const std::vector< SensorMetadata >& metadataVector,
299 std::vector< SensorMeasurement >& streamingDataVector,
300 size_t (Interface::*getMeasureSizePtr)(
size_t) const)
302 if (wrappedDeviceInterface)
304 size_t nrOfSensors = metadataVector.size();
305 streamingDataVector.resize(nrOfSensors);
306 for (
size_t i=0; i < nrOfSensors; i++)
308 size_t measureSize =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureSizePtr)(i);
309 streamingDataVector[i].measurement.resize(measureSize, std::numeric_limits<double>::quiet_NaN());
317template<
typename Interface>
318bool MultipleAnalogSensorsServer::resizeMeasureVectors(Interface* wrappedDeviceInterface,
319 const std::vector< SensorMetadata >& metadataVector,
320 std::vector< SensorMeasurement >& streamingDataVector,
323 if (wrappedDeviceInterface)
325 size_t nrOfSensors = metadataVector.size();
326 streamingDataVector.resize(nrOfSensors);
327 for (
size_t i=0; i < nrOfSensors; i++)
329 streamingDataVector[i].measurement.resize(measureSize, std::numeric_limits<double>::quiet_NaN());
336bool MultipleAnalogSensorsServer::resizeAllMeasureVectors(
SensorStreamingData& streamingData)
340 ok = ok && resizeMeasureVectors(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
348 ok = ok && resizeMeasureVectors(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
352 ok = ok && resizeMeasureVectors(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
354 ok = ok && resizeMeasureVectors(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
360 ok = ok && resizeMeasureVectors(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
362 ok = ok && resizeMeasureVectors(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
372 yCError(MULTIPLEANALOGSENSORSSERVER,
"Null pointer passed to attach.");
378 poly->
view(m_iThreeAxisGyroscopes);
379 poly->
view(m_iThreeAxisLinearAccelerometers);
380 poly->
view(m_iThreeAxisAngularAccelerometers);
381 poly->
view(m_iThreeAxisMagnetometers);
382 poly->
view(m_iPositionSensors);
383 poly->
view(m_iLinearVelocitySensors);
384 poly->
view(m_iOrientationSensors);
385 poly->
view(m_iTemperatureSensors);
386 poly->
view(m_iSixAxisForceTorqueSensors);
387 poly->
view(m_iContactLoadCellArrays);
388 poly->
view(m_iEncoderArrays);
389 poly->
view(m_iSkinPatches);
393 bool ok = populateAllSensorsMetadata();
397 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in populateAllSensorsMetadata()");
403 ok = m_streamingPort.
open(m_streamingPortName);
406 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_streamingPortName.c_str());
414 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in attaching RPC port to thrift RPC interface.");
419 ok = m_rpcPort.
open(m_RPCPortName);
422 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_RPCPortName.c_str());
429 ok = ok && this->
start();
432 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in starting thread.");
437 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Attach complete");
450 m_streamingPort.
close();
452 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Detach complete");
458 return m_sensorMetadata;
461template<
typename Interface>
462bool MultipleAnalogSensorsServer::genericStreamData(Interface* wrappedDeviceInterface,
463 const std::vector< SensorMetadata >& metadataVector,
464 std::vector< SensorMeasurement >& streamingDataVector,
466 bool (Interface::*getMeasureMethodPtr)(
size_t,
yarp::sig::Vector&, double&) const,
467 const char* sensorType)
469 if (wrappedDeviceInterface)
471 size_t nrOfSensors = metadataVector.size();
472 for (
size_t i=0; i < nrOfSensors; i++)
475 double& outputTimestamp = streamingDataVector[i].timestamp;
479 MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureMethodPtr)(i, outputBuffer, outputTimestamp);
482 yCError(MULTIPLEANALOGSENSORSSERVER,
483 "Failure in reading data from sensor %s of type %s with code %s, no data will be sent on the port.",
500 ok = resizeAllMeasureVectors(streamingData);
507 "ThreeAxisGyroscope");
513 "ThreeAxisLinearAccelerometer");
519 "ThreeAxisAngularAccelerometer");
525 "ThreeAxisMagnetometer");
527 ok = ok && genericStreamData(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
537 "LinearVelocitySensor");
539 ok = ok && genericStreamData(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
543 "OrientationSensor");
545 ok = ok && genericStreamData(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
549 "TemperatureSensor");
555 "SixAxisForceTorqueSensor");
561 "ContactLoadCellArrays");
563 ok = ok && genericStreamData(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
569 ok = ok && genericStreamData(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
579 m_streamingPort.
write();
#define MAS_CALL_MEMBER_FN(object, ptrToMember)
@ ThreeAxisAngularAccelerometers
@ ThreeAxisLinearAccelerometers
@ SixAxisForceTorqueSensors
std::vector< SensorMeasurement > measurements
std::vector< SensorMetadata > SkinPatches
std::vector< SensorMetadata > ContactLoadCellArrays
std::vector< SensorMetadata > ThreeAxisAngularAccelerometers
std::vector< SensorMetadata > EncoderArrays
std::vector< SensorMetadata > PositionSensors
std::vector< SensorMetadata > ThreeAxisGyroscopes
std::vector< SensorMetadata > ThreeAxisLinearAccelerometers
std::vector< SensorMetadata > LinearVelocitySensors
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 ThreeAxisAngularAccelerometers
SensorMeasurements ContactLoadCellArrays
SensorMeasurements LinearVelocitySensors
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 getLinearVelocitySensorMeasure(size_t sens_index, yarp::sig::Vector &xyz, double ×tamp) const =0
Get the last reading of the linear velocity sensor as x y z.
virtual bool getLinearVelocitySensorName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual size_t getNrOfLinearVelocitySensors() const =0
Get the number of linear velocity sensors exposed by this device.
virtual yarp::dev::MAS_status getLinearVelocitySensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getLinearVelocitySensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame 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 getThreeAxisAngularAccelerometerStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getThreeAxisAngularAccelerometerFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getThreeAxisAngularAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual size_t getNrOfThreeAxisAngularAccelerometers() const =0
Get the number of three axis angular accelerometers exposed by this device.
virtual bool getThreeAxisAngularAccelerometerName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
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.
A container for a device driver.
bool detachAll() final
Detach the object (you must have first called attach).
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 base class for nested structures that can be searched.
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 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.