YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
AnalogWrapper.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_ANALOGWRAPPER_ANALOGWRAPPER_H
7#define YARP_DEV_ANALOGWRAPPER_ANALOGWRAPPER_H
8
9 //#include <list>
10#include <vector>
11#include <iostream>
12#include <string>
13#include <sstream>
14
15#include <yarp/os/Network.h>
16#include <yarp/os/Port.h>
18#include <yarp/os/Bottle.h>
19#include <yarp/os/Time.h>
20#include <yarp/os/Property.h>
21
24#include <yarp/os/Stamp.h>
25
26#include <yarp/sig/Vector.h>
27
29#include <yarp/dev/PolyDriver.h>
32#include <yarp/dev/api.h>
33
34
35#define DEFAULT_THREAD_PERIOD 20 //ms
36
38class AnalogPortEntry;
39
125{
126public:
128
129 AnalogWrapper(const AnalogWrapper&) = delete;
133
134 ~AnalogWrapper() override;
135
136 bool open(yarp::os::Searchable &params) override;
137 bool close() override;
139
143 bool attachAll(const yarp::dev::PolyDriverList &p) override;
144 bool detachAll() override;
145
147 void detach();
148
149 bool threadInit() override;
150 void threadRelease() override;
151 void run() override;
152
153private:
154 std::string streamingPortName;
155 std::string rpcPortName;
156 yarp::dev::IAnalogSensor *analogSensor_p{nullptr}; // the analog sensor to read from
157 std::vector<AnalogPortEntry> analogPorts; // the list of output ports
158 std::vector<AnalogServerHandler*> handlers; // the list of rpc port handlers
159 yarp::os::Stamp lastStateStamp; // the last reading time stamp
160 yarp::sig::Vector lastDataRead; // the last vector of data read from the attached IAnalogSensor
161 int _rate{DEFAULT_THREAD_PERIOD};
162 std::string sensorId;
163
164 bool initialize_YARP(yarp::os::Searchable &config);
165 void setHandlers();
166 void removeHandlers();
167
168 // Function used when there is only one output port
169 bool createPort(const char* name, int rate=20);
170 // Function used when one or more output ports are specified
171 bool createPorts(const std::vector<AnalogPortEntry>& _analogPorts, int rate=20);
172};
173
174#endif // YARP_DEV_ANALOGWRAPPER_ANALOGWRAPPER_H
#define DEFAULT_THREAD_PERIOD
analog sensor interface
contains the definition of a Vector type
A yarp port that output data read from an analog sensor.
Handler of the rpc port related to an analog sensor.
analogServer deprecated: Device that expose an AnalogSensor (using the IAnalogSensor interface) on th...
void threadRelease() override
Release method.
void attach(yarp::dev::IAnalogSensor *s)
bool threadInit() override
Initialization method.
~AnalogWrapper() override
AnalogWrapper(AnalogWrapper &&)=delete
void run() override
Loop function.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
AnalogWrapper(const AnalogWrapper &)=delete
bool close() override
Close the DeviceDriver.
AnalogWrapper & operator=(AnalogWrapper &&)=delete
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).
yarp::os::Bottle getOptions()
AnalogWrapper & operator=(const AnalogWrapper &)=delete
Interface implemented by all device drivers.
A generic interface to sensors (gyro, a/d converters).
Interface for an object that can wrap/attach to to another.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21