18 YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSSERVER,
"yarp.device.multipleanalogsensorsserver")
30 if (!config.
check(
"name"))
32 yCError(MULTIPLEANALOGSENSORSSERVER,
"Missing name parameter, exiting.");
36 if (!config.
check(
"period"))
38 yCError(MULTIPLEANALOGSENSORSSERVER,
"Missing period parameter, exiting.");
44 yCError(MULTIPLEANALOGSENSORSSERVER,
"Period parameter is present but it is not an integer, exiting.");
48 m_periodInS = config.
find(
"period").
asInt32() / 1000.0;
52 yCError(MULTIPLEANALOGSENSORSSERVER,
53 "Period parameter is present (%f) but it is not a positive integer, exiting.",
67 m_RPCPortName = name +
"/rpc:o";
68 m_streamingPortName = name +
"/measures:o";
70 if (config.
check(
"subdevice"))
72 std::string subdeviceName = config.
find(
"subdevice").
asString();
76 driverConfig.setMonitor(config.getMonitor(), subdeviceName.c_str());
77 driverConfig.
put(
"device", subdeviceName);
79 if (!m_subdevice.
open(driverConfig))
81 yCError(MULTIPLEANALOGSENSORSSERVER,
"Opening subdevice failed.");
86 driverList.
push(&m_subdevice, subdeviceName.c_str());
90 yCError(MULTIPLEANALOGSENSORSSERVER,
"Attaching subdevice failed.");
94 yCInfo(MULTIPLEANALOGSENSORSSERVER,
95 "Subdevice \"%s\" successfully configured and attached.",
96 subdeviceName.c_str());
97 m_isDeviceOwned =
true;
109 ok &= m_subdevice.
close();
110 m_isDeviceOwned =
false;
118 #define MAS_CALL_MEMBER_FN(object, ptrToMember) ((*object).*(ptrToMember))
120 template<
typename Interface>
121 bool MultipleAnalogSensorsServer::populateSensorsMetadata(Interface * wrappedDeviceInterface,
122 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
123 size_t (Interface::*getNrOfSensorsMethodPtr)()
const,
124 bool (Interface::*getNameMethodPtr)(
size_t, std::string&)
const,
125 bool (Interface::*getFrameNameMethodPtr)(
size_t, std::string&)
const)
127 if (wrappedDeviceInterface)
129 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
130 metadataVector.resize(nrOfSensors);
131 for (
size_t i=0; i < nrOfSensors; i++)
133 std::string sensorName;
134 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
137 yCError(MULTIPLEANALOGSENSORSSERVER,
138 "Failure in reading name of sensor of type %s at index %zu.",
143 std::string frameName;
147 yCError(MULTIPLEANALOGSENSORSSERVER,
148 "Failure in reading frame name of sensor of type %s at index %zu.",
154 metadataVector[i].name = sensorName;
155 metadataVector[i].frameName = frameName;
156 metadataVector[i].additionalMetadata =
"";
162 metadataVector.resize(0);
167 template<
typename Interface>
168 bool MultipleAnalogSensorsServer::populateSensorsMetadataNoFrameName(Interface * wrappedDeviceInterface,
169 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
170 size_t (Interface::*getNrOfSensorsMethodPtr)()
const,
171 bool (Interface::*getNameMethodPtr)(
size_t, std::string&)
const)
173 if (wrappedDeviceInterface)
175 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
176 metadataVector.resize(nrOfSensors);
177 for (
size_t i=0; i < nrOfSensors; i++)
179 std::string sensorName;
180 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
183 yCError(MULTIPLEANALOGSENSORSSERVER,
184 "Failure in reading name of sensor of type %s at index %zu.",
190 metadataVector[i].name = sensorName;
191 metadataVector[i].frameName =
"";
192 metadataVector[i].additionalMetadata =
"";
198 metadataVector.resize(0);
204 bool MultipleAnalogSensorsServer::populateAllSensorsMetadata()
207 ok = ok && populateSensorsMetadata(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes",
211 ok = ok && populateSensorsMetadata(m_iThreeAxisLinearAccelerometers, m_sensorMetadata.
ThreeAxisLinearAccelerometers,
"ThreeAxisLinearAccelerometers",
215 ok = ok && populateSensorsMetadata(m_iThreeAxisMagnetometers, m_sensorMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers",
219 ok = ok && populateSensorsMetadata(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
"PositionSensors",
223 ok = ok && populateSensorsMetadata(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
"OrientationSensors",
227 ok = ok && populateSensorsMetadata(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
"TemperatureSensors",
231 ok = ok && populateSensorsMetadata(m_iSixAxisForceTorqueSensors, m_sensorMetadata.
SixAxisForceTorqueSensors,
"SixAxisForceTorqueSensors",
235 ok = ok && populateSensorsMetadataNoFrameName(m_iContactLoadCellArrays, m_sensorMetadata.
ContactLoadCellArrays,
"ContactLoadCellArrays",
238 ok = ok && populateSensorsMetadataNoFrameName(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
"EncoderArrays",
241 ok = ok && populateSensorsMetadataNoFrameName(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
"ISkinPatches",
253 yCError(MULTIPLEANALOGSENSORSSERVER,
254 "This device only supports exposing a "
255 "single MultipleAnalogSensors device on YARP ports, but %d devices have been passed in attachAll.",
257 yCError(MULTIPLEANALOGSENSORSSERVER,
258 "Please use the multipleanalogsensorsremapper device to combine several device in a new device.");
265 yCError(MULTIPLEANALOGSENSORSSERVER,
"No device passed to attachAll, please pass a device to expose on YARP ports.");
274 yCError(MULTIPLEANALOGSENSORSSERVER,
"Null pointer passed to attachAll.");
280 poly->
view(m_iThreeAxisGyroscopes);
281 poly->
view(m_iThreeAxisLinearAccelerometers);
282 poly->
view(m_iThreeAxisMagnetometers);
283 poly->
view(m_iPositionSensors);
284 poly->
view(m_iOrientationSensors);
285 poly->
view(m_iTemperatureSensors);
286 poly->
view(m_iSixAxisForceTorqueSensors);
287 poly->
view(m_iContactLoadCellArrays);
288 poly->
view(m_iEncoderArrays);
289 poly->
view(m_iSkinPatches);
293 bool ok = populateAllSensorsMetadata();
302 ok = m_streamingPort.
open(m_streamingPortName);
305 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_streamingPortName.c_str());
313 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in attaching RPC port to thrift RPC interface.");
318 ok = m_rpcPort.
open(m_RPCPortName);
321 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_RPCPortName.c_str());
328 ok = ok && this->
start();
331 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in starting thread.");
348 m_streamingPort.
close();
355 return m_sensorMetadata;
358 template<
typename Interface>
359 bool MultipleAnalogSensorsServer::genericStreamData(Interface* wrappedDeviceInterface,
360 const std::vector< SensorMetadata >& metadataVector,
361 std::vector< SensorMeasurement >& streamingDataVector,
363 bool (Interface::*getMeasureMethodPtr)(
size_t,
yarp::sig::Vector&,
double&)
const)
365 if (wrappedDeviceInterface)
367 size_t nrOfSensors = metadataVector.size();
368 streamingDataVector.resize(nrOfSensors);
369 for (
size_t i=0; i < nrOfSensors; i++)
372 double& outputTimestamp = streamingDataVector[i].timestamp;
374 MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureMethodPtr)(i, outputBuffer, outputTimestamp);
378 yCError(MULTIPLEANALOGSENSORSSERVER,
379 "Failure in reading data from sensor %s, no data will be sent on the port.",
411 ok = ok && genericStreamData(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
416 ok = ok && genericStreamData(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
421 ok = ok && genericStreamData(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
436 ok = ok && genericStreamData(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
441 ok = ok && genericStreamData(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
450 m_streamingPort.
write();
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 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 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 Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
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.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual std::string asString() const
Get string value.
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 YARP_LOG_COMPONENT(name,...)
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.
@ MAS_OK
The sensor is working correctly.