|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
21 YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSSERVER,
"yarp.device.multipleanalogsensorsserver")
33 if (!config.
check(
"name"))
35 yCError(MULTIPLEANALOGSENSORSSERVER,
"Missing name parameter, exiting.");
39 if (!config.
check(
"period"))
41 yCError(MULTIPLEANALOGSENSORSSERVER,
"Missing period parameter, exiting.");
47 yCError(MULTIPLEANALOGSENSORSSERVER,
"Period parameter is present but it is not an integer, exiting.");
51 m_periodInS = config.
find(
"period").
asInt32() / 1000.0;
55 yCError(MULTIPLEANALOGSENSORSSERVER,
56 "Period parameter is present (%f) but it is not a positive integer, exiting.",
70 m_RPCPortName = name +
"/rpc:o";
71 m_streamingPortName = name +
"/measures:o";
73 if (config.
check(
"subdevice"))
75 std::string subdeviceName = config.
find(
"subdevice").
asString();
79 driverConfig.setMonitor(config.getMonitor(), subdeviceName.c_str());
80 driverConfig.
put(
"device", subdeviceName);
82 if (!m_subdevice.
open(driverConfig))
84 yCError(MULTIPLEANALOGSENSORSSERVER,
"Opening subdevice failed.");
89 driverList.
push(&m_subdevice, subdeviceName.c_str());
93 yCError(MULTIPLEANALOGSENSORSSERVER,
"Attaching subdevice failed.");
97 yCInfo(MULTIPLEANALOGSENSORSSERVER,
98 "Subdevice \"%s\" successfully configured and attached.",
99 subdeviceName.c_str());
100 m_isDeviceOwned =
true;
112 ok &= m_subdevice.
close();
113 m_isDeviceOwned =
false;
121 #define MAS_CALL_MEMBER_FN(object, ptrToMember) ((*object).*(ptrToMember))
123 template<
typename Interface>
124 bool MultipleAnalogSensorsServer::populateSensorsMetadata(Interface * wrappedDeviceInterface,
125 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
126 size_t (Interface::*getNrOfSensorsMethodPtr)()
const,
127 bool (Interface::*getNameMethodPtr)(
size_t, std::string&)
const,
128 bool (Interface::*getFrameNameMethodPtr)(
size_t, std::string&)
const)
130 if (wrappedDeviceInterface)
132 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
133 metadataVector.resize(nrOfSensors);
134 for (
size_t i=0; i < nrOfSensors; i++)
136 std::string sensorName;
137 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
140 yCError(MULTIPLEANALOGSENSORSSERVER,
141 "Failure in reading name of sensor of type %s at index %zu.",
146 std::string frameName;
150 yCError(MULTIPLEANALOGSENSORSSERVER,
151 "Failure in reading frame name of sensor of type %s at index %zu.",
157 metadataVector[i].name = sensorName;
158 metadataVector[i].frameName = frameName;
159 metadataVector[i].additionalMetadata =
"";
165 metadataVector.resize(0);
170 template<
typename Interface>
171 bool MultipleAnalogSensorsServer::populateSensorsMetadataNoFrameName(Interface * wrappedDeviceInterface,
172 std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
173 size_t (Interface::*getNrOfSensorsMethodPtr)()
const,
174 bool (Interface::*getNameMethodPtr)(
size_t, std::string&)
const)
176 if (wrappedDeviceInterface)
178 size_t nrOfSensors =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNrOfSensorsMethodPtr)();
179 metadataVector.resize(nrOfSensors);
180 for (
size_t i=0; i < nrOfSensors; i++)
182 std::string sensorName;
183 bool ok =
MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getNameMethodPtr)(i, sensorName);
186 yCError(MULTIPLEANALOGSENSORSSERVER,
187 "Failure in reading name of sensor of type %s at index %zu.",
193 metadataVector[i].name = sensorName;
194 metadataVector[i].frameName =
"";
195 metadataVector[i].additionalMetadata =
"";
201 metadataVector.resize(0);
207 bool MultipleAnalogSensorsServer::populateAllSensorsMetadata()
210 ok = ok && populateSensorsMetadata(m_iThreeAxisGyroscopes, m_sensorMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes",
214 ok = ok && populateSensorsMetadata(m_iThreeAxisLinearAccelerometers, m_sensorMetadata.
ThreeAxisLinearAccelerometers,
"ThreeAxisLinearAccelerometers",
218 ok = ok && populateSensorsMetadata(m_iThreeAxisMagnetometers, m_sensorMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers",
222 ok = ok && populateSensorsMetadata(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
"PositionSensors",
226 ok = ok && populateSensorsMetadata(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
"OrientationSensors",
230 ok = ok && populateSensorsMetadata(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
"TemperatureSensors",
234 ok = ok && populateSensorsMetadata(m_iSixAxisForceTorqueSensors, m_sensorMetadata.
SixAxisForceTorqueSensors,
"SixAxisForceTorqueSensors",
238 ok = ok && populateSensorsMetadataNoFrameName(m_iContactLoadCellArrays, m_sensorMetadata.
ContactLoadCellArrays,
"ContactLoadCellArrays",
241 ok = ok && populateSensorsMetadataNoFrameName(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
"EncoderArrays",
244 ok = ok && populateSensorsMetadataNoFrameName(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
"ISkinPatches",
256 yCError(MULTIPLEANALOGSENSORSSERVER,
257 "This device only supports exposing a "
258 "single MultipleAnalogSensors device on YARP ports, but %d devices have been passed in attachAll.",
260 yCError(MULTIPLEANALOGSENSORSSERVER,
261 "Please use the multipleanalogsensorsremapper device to combine several device in a new device.");
268 yCError(MULTIPLEANALOGSENSORSSERVER,
"No device passed to attachAll, please pass a device to expose on YARP ports.");
277 yCError(MULTIPLEANALOGSENSORSSERVER,
"Null pointer passed to attachAll.");
283 poly->
view(m_iThreeAxisGyroscopes);
284 poly->
view(m_iThreeAxisLinearAccelerometers);
285 poly->
view(m_iThreeAxisMagnetometers);
286 poly->
view(m_iPositionSensors);
287 poly->
view(m_iOrientationSensors);
288 poly->
view(m_iTemperatureSensors);
289 poly->
view(m_iSixAxisForceTorqueSensors);
290 poly->
view(m_iContactLoadCellArrays);
291 poly->
view(m_iEncoderArrays);
292 poly->
view(m_iSkinPatches);
296 bool ok = populateAllSensorsMetadata();
305 ok = m_streamingPort.
open(m_streamingPortName);
308 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_streamingPortName.c_str());
316 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in attaching RPC port to thrift RPC interface.");
321 ok = m_rpcPort.
open(m_RPCPortName);
324 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in opening port named %s.", m_RPCPortName.c_str());
331 ok = ok && this->
start();
334 yCError(MULTIPLEANALOGSENSORSSERVER,
"Failure in starting thread.");
351 m_streamingPort.
close();
358 return m_sensorMetadata;
361 template<
typename Interface>
362 bool MultipleAnalogSensorsServer::genericStreamData(Interface* wrappedDeviceInterface,
363 const std::vector< SensorMetadata >& metadataVector,
364 std::vector< SensorMeasurement >& streamingDataVector,
366 bool (Interface::*getMeasureMethodPtr)(
size_t,
yarp::sig::Vector&,
double&)
const)
368 if (wrappedDeviceInterface)
370 size_t nrOfSensors = metadataVector.size();
371 streamingDataVector.resize(nrOfSensors);
372 for (
size_t i=0; i < nrOfSensors; i++)
375 double& outputTimestamp = streamingDataVector[i].timestamp;
377 MAS_CALL_MEMBER_FN(wrappedDeviceInterface, getMeasureMethodPtr)(i, outputBuffer, outputTimestamp);
381 yCError(MULTIPLEANALOGSENSORSSERVER,
382 "Failure in reading data from sensor %s, no data will be sent on the port.",
414 ok = ok && genericStreamData(m_iPositionSensors, m_sensorMetadata.
PositionSensors,
419 ok = ok && genericStreamData(m_iOrientationSensors, m_sensorMetadata.
OrientationSensors,
424 ok = ok && genericStreamData(m_iTemperatureSensors, m_sensorMetadata.
TemperatureSensors,
439 ok = ok && genericStreamData(m_iEncoderArrays, m_sensorMetadata.
EncoderArrays,
444 ok = ok && genericStreamData(m_iSkinPatches, m_sensorMetadata.
SkinPatches,
453 m_streamingPort.
write();
void close() override
Stop port activity.
std::vector< SensorMetadata > TemperatureSensors
virtual bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
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.
std::vector< SensorMeasurement > measurements
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void resize(size_t size) override
Resize the vector.
std::vector< SensorMetadata > ThreeAxisGyroscopes
A base class for nested structures that can be searched.
virtual yarp::dev::MAS_status getSkinPatchStatus(size_t sens_index) const =0
Get the status of the specified sensor.
SensorMeasurements TemperatureSensors
virtual bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the gyroscope.
std::vector< SensorMetadata > SkinPatches
SensorMeasurements SixAxisForceTorqueSensors
std::vector< SensorMetadata > SixAxisForceTorqueSensors
std::vector< SensorMetadata > PositionSensors
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
virtual bool getSkinPatchMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
#define YARP_LOG_COMPONENT(name,...)
virtual bool getPositionSensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
std::vector< SensorMetadata > ThreeAxisMagnetometers
bool view(T *&x)
Get an interface to the device driver.
bool attachAsServer(yarp::os::UnbufferedContactable &port)
Tag this WireLink as a server, receiving commands via the specified port.
virtual bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
virtual size_t getNrOfEncoderArrays() const =0
Get the number of encoder arrays exposed by this device.
virtual size_t getNrOfThreeAxisMagnetometers() const =0
Get the number of magnetometers exposed by this device.
bool open(const std::string &txt)
Construct and configure a device by its common name.
bool isRunning() const
Returns true when the thread is started, false otherwise.
virtual bool getEncoderArrayName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
void push(PolyDriver *p, const char *k)
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.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
SensorMeasurements ThreeAxisGyroscopes
virtual yarp::dev::MAS_status getPositionSensorStatus(size_t sens_index) const =0
Get the status 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 bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
SensorMeasurements EncoderArrays
SensorMeasurements ThreeAxisLinearAccelerometers
SensorMeasurements ContactLoadCellArrays
virtual bool getTemperatureSensorMeasure(size_t sens_index, double &out, double ×tamp) const =0
Get the last reading of the specified sensor.
virtual std::string asString() const
Get string value.
bool start()
Call this to start the thread.
A container for a device driver.
virtual size_t getNrOfTemperatureSensors() const =0
Get the number of temperature sensors exposed by this device.
bool close() override
Close the DeviceDriver.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
virtual yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
bool setPeriod(double period)
Set the (new) period of the thread.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool getOrientationSensorName(size_t sens_index, std::string &name) const =0
Get the name 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 getNrOfPositionSensors() const =0
Get the number of position sensors exposed by this device.
SensorMeasurements OrientationSensors
std::vector< SensorMetadata > ContactLoadCellArrays
virtual bool getThreeAxisMagnetometerMeasure(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 getThreeAxisGyroscopeStatus(size_t sens_index) const =0
Get the status of the specified sensor.
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 getSkinPatchName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
#define yCError(component,...)
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual yarp::dev::MAS_status getTemperatureSensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
std::vector< SensorMetadata > OrientationSensors
#define yCInfo(component,...)
SensorMeasurements PositionSensors
virtual bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
virtual bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
SensorMeasurements ThreeAxisMagnetometers
bool unprepare()
Give the last prepared object back to YARP without writing it.
virtual size_t getNrOfSixAxisForceTorqueSensors() const =0
Get the number of six axis force torque sensors exposed by this device.
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.
void close() override
Stop port activity.
virtual yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const =0
Get the status of the specified sensor.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
virtual size_t getNrOfOrientationSensors() const =0
Get the number of orientation sensors exposed by this device.
std::vector< SensorMetadata > ThreeAxisLinearAccelerometers
virtual size_t getNrOfThreeAxisGyroscopes() const =0
Get the number of three axis gyroscopes exposed by this sensor.
virtual yarp::dev::MAS_status getEncoderArrayStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual bool getTemperatureSensorName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const =0
Get the name of the specified sensor.
virtual yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const =0
Get the status of the specified sensor.
virtual size_t getNrOfSkinPatches() const =0
Get the number of skin patches 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 bool getPositionSensorName(size_t sens_index, std::string &name) const =0
Get the name 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 getEncoderArrayMeasure(size_t sens_index, yarp::sig::Vector &out, double ×tamp) const =0
Get the last reading of the specified sensor.
std::vector< SensorMetadata > EncoderArrays
virtual size_t getNrOfThreeAxisLinearAccelerometers() const =0
Get the number of three axis linear accelerometers exposed by this device.
virtual bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const =0
Get the name of the frame of the specified sensor.
A class for storing options and configuration information.
@ MAS_OK
The sensor is working correctly.
SensorMeasurements SkinPatches
virtual bool isInt32() const
Checks if value is a 32-bit integer.