19YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSSERVER,
"yarp.device.multipleanalogsensorsserver")
100 return "MAS_WAITING_FOR_FIRST_READ";
103 return "MAS_UNKNOWN";
128 if (m_periodInS <= 0)
130 yCError(MULTIPLEANALOGSENSORSSERVER,
131 "Period parameter is present (%f) but it is not a positive integer, exiting.",
143 m_RPCPortName =
m_name +
"/rpc:o";
144 m_streamingPortName =
m_name +
"/measures:o";
158#define MAS_CALL_MEMBER_FN(object, ptrToMember) ((*object).*(ptrToMember))
160template<
typename Interface>
161bool MultipleAnalogSensorsServer::populateSensorsMetadata(Interface * wrappedDeviceInterface,
162 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
163 size_t (Interface::*getNrOfSensorsMethodPtr)() const,
164 bool (Interface::*getNameMethodPtr)(
size_t,
std::string&) const,
165 bool (Interface::*getFrameNameMethodPtr)(
size_t,
std::string&) const)
167 if (wrappedDeviceInterface)
169 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
170 metadataVector.resize(nrOfSensors);
171 for (
size_t i=0; i < nrOfSensors; i++)
173 std::string sensorName;
174 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
177 yCError(MULTIPLEANALOGSENSORSSERVER,
178 "Failure in reading name of sensor of type %s at index %zu.",
183 std::string frameName;
187 yCError(MULTIPLEANALOGSENSORSSERVER,
188 "Failure in reading frame name of sensor of type %s at index %zu.",
194 metadataVector[i].name = sensorName;
195 metadataVector[i].frameName = frameName;
196 metadataVector[i].additionalMetadata =
"";
202 metadataVector.resize(0);
207template<
typename Interface>
208bool MultipleAnalogSensorsServer::populateSensorsMetadataNoFrameName(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)
213 if (wrappedDeviceInterface)
215 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
216 metadataVector.resize(nrOfSensors);
217 for (
size_t i=0; i < nrOfSensors; i++)
219 std::string sensorName;
220 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
223 yCError(MULTIPLEANALOGSENSORSSERVER,
224 "Failure in reading name of sensor of type %s at index %zu.",
230 metadataVector[i].name = sensorName;
231 metadataVector[i].frameName =
"";
232 metadataVector[i].additionalMetadata =
"";
238 metadataVector.resize(0);
244bool MultipleAnalogSensorsServer::populateAllSensorsMetadata()
247 ok = ok && populateSensorsMetadata(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes",
251 ok = ok && populateSensorsMetadata(m_iThreeAxisLinearAccelerometers, m_sensorMetadata.
ThreeAxisLinearAccelerometers,
"ThreeAxisLinearAccelerometers",
255 ok = ok && populateSensorsMetadata(m_iThreeAxisAngularAccelerometers, m_sensorMetadata.
ThreeAxisAngularAccelerometers,
"ThreeAxisAngularAccelerometers",
259 ok = ok && populateSensorsMetadata(m_iThreeAxisMagnetometers, m_sensorMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers",
263 ok = ok && populateSensorsMetadata(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
"PositionSensors",
267 ok = ok && populateSensorsMetadata(m_iLinearVelocitySensors, m_sensorMetadata.
LinearVelocitySensors,
"LinearVelocitySensors",
271 ok = ok && populateSensorsMetadata(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
"OrientationSensors",
275 ok = ok && populateSensorsMetadata(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
"TemperatureSensors",
279 ok = ok && populateSensorsMetadata(m_iSixAxisForceTorqueSensors, m_sensorMetadata.
SixAxisForceTorqueSensors,
"SixAxisForceTorqueSensors",
283 ok = ok && populateSensorsMetadataNoFrameName(m_iContactLoadCellArrays, m_sensorMetadata.
ContactLoadCellArrays,
"ContactLoadCellArrays",
286 ok = ok && populateSensorsMetadataNoFrameName(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
"EncoderArrays",
289 ok = ok && populateSensorsMetadataNoFrameName(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
"ISkinPatches",
297template<
typename Interface>
298bool MultipleAnalogSensorsServer::resizeMeasureVectors(Interface* wrappedDeviceInterface,
299 const std::vector< SensorMetadata >& metadataVector,
300 std::vector< yarp::dev::SensorMeasurement >& streamingDataVector,
301 size_t (Interface::*getMeasureSizePtr)(
size_t) const)
303 if (wrappedDeviceInterface)
305 size_t nrOfSensors = metadataVector.size();
306 streamingDataVector.resize(nrOfSensors);
307 for (
size_t i=0; i < nrOfSensors; i++)
309 size_t measureSize =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureSizePtr)(i);
310 streamingDataVector[i].measurement.resize(measureSize, std::numeric_limits<double>::quiet_NaN());
318template<
typename Interface>
319bool MultipleAnalogSensorsServer::resizeMeasureVectors(Interface* wrappedDeviceInterface,
320 const std::vector< SensorMetadata >& metadataVector,
321 std::vector< yarp::dev::SensorMeasurement >& streamingDataVector,
324 if (wrappedDeviceInterface)
326 size_t nrOfSensors = metadataVector.size();
327 streamingDataVector.resize(nrOfSensors);
328 for (
size_t i=0; i < nrOfSensors; i++)
330 streamingDataVector[i].measurement.resize(measureSize, std::numeric_limits<double>::quiet_NaN());
341 ok = ok && resizeMeasureVectors(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
349 ok = ok && resizeMeasureVectors(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
353 ok = ok && resizeMeasureVectors(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
355 ok = ok && resizeMeasureVectors(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
361 ok = ok && resizeMeasureVectors(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
363 ok = ok && resizeMeasureVectors(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
373 yCError(MULTIPLEANALOGSENSORSSERVER,
"Null pointer passed to attach.");
379 poly->
view(m_iThreeAxisGyroscopes);
380 poly->
view(m_iThreeAxisLinearAccelerometers);
381 poly->
view(m_iThreeAxisAngularAccelerometers);
382 poly->
view(m_iThreeAxisMagnetometers);
383 poly->
view(m_iPositionSensors);
384 poly->
view(m_iLinearVelocitySensors);
385 poly->
view(m_iOrientationSensors);
386 poly->
view(m_iTemperatureSensors);
387 poly->
view(m_iSixAxisForceTorqueSensors);
388 poly->
view(m_iContactLoadCellArrays);
389 poly->
view(m_iEncoderArrays);
390 poly->
view(m_iSkinPatches);
394 bool ok = populateAllSensorsMetadata();
398 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in populateAllSensorsMetadata()");
404 ok = m_streamingPort.
open(m_streamingPortName);
407 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_streamingPortName.c_str());
415 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in attaching RPC port to thrift RPC interface.");
420 ok = m_rpcPort.
open(m_RPCPortName);
423 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_RPCPortName.c_str());
430 ok = ok && this->
start();
433 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in starting thread.");
438 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Attach complete");
451 m_streamingPort.
close();
453 yCDebug(MULTIPLEANALOGSENSORSSERVER,
"Detach complete");
459 return m_sensorMetadata;
462template<
typename Interface>
463bool MultipleAnalogSensorsServer::genericStreamData(Interface* wrappedDeviceInterface,
464 const std::vector< SensorMetadata >& metadataVector,
465 std::vector< typename yarp::dev::SensorMeasurement >& streamingDataVector,
467 bool (Interface::*getMeasureMethodPtr)(
size_t,
yarp::sig::Vector&, double&) const,
468 const char* sensorType)
470 if (wrappedDeviceInterface)
472 size_t nrOfSensors = metadataVector.size();
473 for (
size_t i=0; i < nrOfSensors; i++)
476 double& outputTimestamp = streamingDataVector[i].timestamp;
480 MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureMethodPtr)(i, outputBuffer, outputTimestamp);
483 yCError(MULTIPLEANALOGSENSORSSERVER,
484 "Failure in reading data from sensor %s of type %s with code %s, no data will be sent on the port.",
501 ok = resizeAllMeasureVectors(streamingData);
508 "ThreeAxisGyroscope");
514 "ThreeAxisLinearAccelerometer");
520 "ThreeAxisAngularAccelerometer");
526 "ThreeAxisMagnetometer");
528 ok = ok && genericStreamData(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
538 "LinearVelocitySensor");
540 ok = ok && genericStreamData(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
544 "OrientationSensor");
546 ok = ok && genericStreamData(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
550 "TemperatureSensor");
556 "SixAxisForceTorqueSensor");
562 "ContactLoadCellArrays");
564 ok = ok && genericStreamData(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
570 ok = ok && genericStreamData(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
580 m_streamingPort.
write();
#define MAS_CALL_MEMBER_FN(object, ptrToMember)
@ ThreeAxisAngularAccelerometers
@ ThreeAxisLinearAccelerometers
@ SixAxisForceTorqueSensors
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
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.
std::vector< SensorMeasurement > measurements
SensorMeasurements EncoderArrays
SensorMeasurements PositionSensors
SensorMeasurements SixAxisForceTorqueSensors
SensorMeasurements LinearVelocitySensors
SensorMeasurements ContactLoadCellArrays
SensorMeasurements SkinPatches
SensorMeasurements OrientationSensors
SensorMeasurements TemperatureSensors
SensorMeasurements ThreeAxisMagnetometers
SensorMeasurements ThreeAxisGyroscopes
SensorMeasurements ThreeAxisLinearAccelerometers
SensorMeasurements ThreeAxisAngularAccelerometers
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.