100 for (
unsigned int i = 0; i < v.
size(); i++) {
131 bool ok=in.
read(connection);
192bool AnalogWrapper::createPort(
const char* name,
int rate)
194 analogSensor_p=
nullptr;
195 analogPorts.resize(1);
196 analogPorts[0].offset = 0;
197 analogPorts[0].length = -1;
198 analogPorts[0].port_name = std::string(name);
204bool AnalogWrapper::createPorts(
const std::vector<AnalogPortEntry>&
_analogPorts,
int rate)
206 analogSensor_p=
nullptr;
223 analogSensor_p =
nullptr;
226void AnalogWrapper::setHandlers()
230 std::string rpcPortName =
analogPort.port_name;
231 rpcPortName +=
"/rpc:i";
233 handlers.push_back(
ash);
237void AnalogWrapper::removeHandlers()
269 if(
nullptr == analogSensor_p)
281 analogSensor_p =
nullptr;
282 for(
unsigned int i=0; i<analogPorts.size(); i++)
284 if (handlers[i] !=
nullptr) {
285 handlers[i]->setInterface(analogSensor_p);
294 for(
unsigned int i=0; i<analogPorts.size(); i++)
296 handlers[i]->setInterface(analogSensor_p);
306 analogSensor_p =
nullptr;
307 for(
unsigned int i=0; i<analogPorts.size(); i++)
309 handlers[i]->setInterface(analogSensor_p);
331 yCWarning(
ANALOGWRAPPER) <<
"'MultipleAnalogSensorsRemapper`+`MultipleAnalogSensorsServer`, `PoseStampedRosPublisher`, `WrenchStampedRosPublisher`,`IMURosPublisher`,etc.";
332 yCWarning(
ANALOGWRAPPER) <<
"The old device is no longer supported, and it will be deprecated in YARP 3.7 and removed in YARP 4.";
339 if (!config.
check(
"period"))
341 yCError(
ANALOGWRAPPER) <<
"AnalogWrapper: missing 'period' parameter. Check you configuration file\n";
346 _rate = config.
find(
"period").asInt32();
349 if (config.
check(
"deviceId"))
351 yCError(
ANALOGWRAPPER) <<
"AnalogWrapper: the parameter 'deviceId' has been removed, please use parameter 'name' instead. \n"
352 <<
"e.g. In the FT wrapper configuration files of your robot, replace '<param name=""deviceId""> left_arm </param>' \n"
353 <<
"with '/icub/left_arm/analog:o' ";
357 if (!config.
check(
"name"))
359 yCError(
ANALOGWRAPPER) <<
"AnalogWrapper: missing 'name' parameter. Check you configuration file; it must be like:\n"
360 " name: full name of the port, like /robotName/deviceId/sensorType:o";
365 streamingPortName = config.
find(
"name").asString();
368 if(!initialize_YARP(config) )
381 if(!params.
check(
"ports"))
384 if (Network::exists(streamingPortName +
"/rpc:i") || Network::exists(streamingPortName))
389 createPort((streamingPortName ).
c_str(), _rate );
391 if (!Network::exists(streamingPortName +
"/rpc:i")) {
408 std::vector<AnalogPortEntry>
tmpPorts;
411 for(
size_t k=0;
k<
ports->size();
k++)
415 if (parameters.
size()!=5)
417 yCError(
ANALOGWRAPPER) <<
"AnalogWrapper: check skin port parameters in part description, I was expecting "
418 <<
ports->get(
k).asString().c_str() <<
" followed by four integers";
423 if (Network::exists(streamingPortName +
"/" + std::string(
ports->get(
k).asString()) +
"/rpc:i")
424 || Network::exists(streamingPortName +
"/" + std::string(
ports->get(
k).asString())))
439 <<
ports->get(
k).asString().c_str() <<
" port parameters in part description";
447 tmpPorts[
k].port_name = streamingPortName+
"/" + std::string(
ports->get(
k).asString());
455 yCError(
ANALOGWRAPPER) <<
"AnalogWrapper: Total number of mapped taxels does not correspond to total taxels";
473 int first, last,
ret;
475 if (analogSensor_p!=
nullptr)
477 ret=analogSensor_p->
read(lastDataRead);
481 if (lastDataRead.
size()>0)
492 last = lastDataRead.
size()-1;
498 if(last>=(
int)lastDataRead.
size()){
500 <<
" Vector size expected to be at least "<<last<<
" whereas it is "<< lastDataRead.
size();
512 yCError(
ANALOGWRAPPER,
"AnalogWrapper: %s: vector size non valid: %lu", sensorId.c_str(),
static_cast<unsigned long> (lastDataRead.
size()));
const yarp::os::LogComponent & ANALOGWRAPPER()
#define DEFAULT_THREAD_PERIOD
define control board standard interfaces
constexpr yarp::conf::vocab32_t VOCAB_FAILED
constexpr yarp::conf::vocab32_t VOCAB_IANALOG
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE
constexpr yarp::conf::vocab32_t VOCAB_CALIBRATE_CHANNEL
static void handler(int sig)
A yarp port that output data read from an analog sensor.
AnalogPortEntry & operator=(const AnalogPortEntry &alt)
yarp::os::BufferedPort< yarp::sig::Vector > port
AnalogPortEntry()
A yarp port that output data read from an analog sensor.
Handler of the rpc port related to an analog sensor.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
AnalogServerHandler(const char *n)
Handler of the rpc port related to an analog sensor.
void setInterface(yarp::dev::IAnalogSensor *is)
bool _handleIAnalog(yarp::os::Bottle &cmd, yarp::os::Bottle &reply)
void threadRelease() override
Release method.
void attach(yarp::dev::IAnalogSensor *s)
bool threadInit() override
Initialization method.
~AnalogWrapper() override
void run() override
Loop function.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which analog sensor this thread has to read from.
bool detachAll() override
Detach the object (you must have first called attach).
A generic interface to sensors (gyro, a/d converters).
virtual int calibrateSensor()=0
Calibrates the whole sensor.
virtual int read(yarp::sig::Vector &out)=0
Read a vector from the sensor.
virtual int getChannels()=0
Get the number of channels of the sensor.
virtual int calibrateChannel(int ch)=0
Calibrates one single channel.
A container for a device driver.
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
An abstraction for a periodic thread.
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...
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
A mini-server for network communication.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void setReader(PortReader &reader) override
Set an external reader for port data.
void interrupt() override
Interrupt any current reads or writes attached to the port.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
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.
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.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list 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...
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
void resize(size_t size) override
Resize the vector.
VectorOf< T > subVector(unsigned int first, unsigned int last) const
Creates and returns a new vector, being the portion of the original vector defined by the first and l...
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.