YARP
Yet Another Robot Platform
AnalogSensorClient.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_ANALOGSENSORCLIENT_ANALOGSENSORCLIENT_H
7#define YARP_DEV_ANALOGSENSORCLIENT_ANALOGSENSORCLIENT_H
8
9
10#include <yarp/os/Network.h>
16#include <yarp/sig/Vector.h>
17#include <yarp/os/Time.h>
18#include <yarp/dev/PolyDriver.h>
19
20#include <mutex>
21
22
23const int ANALOG_TIMEOUT=100; //ms
24
25
26class InputPortProcessor : public yarp::os::BufferedPort<yarp::sig::Vector>
27{
28 yarp::sig::Vector lastVector;
29 std::mutex mutex;
30 yarp::os::Stamp lastStamp;
31 double deltaT;
32 double deltaTMax;
33 double deltaTMin;
34 double prev;
35 double now;
36
37 int state;
38 int count;
39
40public:
41
42 inline void resetStat();
43
45
47 void onRead(yarp::sig::Vector &v) override;
48
49 inline int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp);
50
51 inline int getIterations();
52
53 // time is in ms
54 void getEstFrequency(int &ite, double &av, double &min, double &max);
55
56 int getState();
57
58 int getChannels();
59};
60
61/*
62 * The client side of any IAnalogSensor capable device.
63 * Still single thread! concurrent access is unsafe.
64 */
65
90{
91protected:
94 std::string local;
95 std::string remote;
96 yarp::os::Stamp lastTs; //used by IPreciselyTimed
97 std::string robotName;
98 std::string deviceId;
99 std::string sensorType;
100 std::string portPrefix;
101
102 void removeLeadingTrailingSlashesOnly(std::string &name);
103
104public:
110 ~AnalogSensorClient() override = default;
111
112 /* DeviceDriver methods */
113 bool open(yarp::os::Searchable& config) override;
114 bool close() override;
115
116 /* IAnalogSensor methods*/
117 int read(yarp::sig::Vector &out) override;
118
119 /* Check the state value of a given channel.
120 * @param ch: channel number.
121 * @return status.
122 */
123 int getState(int ch) override;
124
125 /* Get the number of channels of the sensor.
126 * @return number of channels (0 in case of errors).
127 */
128 int getChannels() override;
129
130 /* Calibrates the whole sensor.
131 * @return status.
132 */
133 int calibrateSensor() override;
134
135 /* Calibrates the whole sensor, using a vector of calibration values.
136 * @param value: a vector of calibration values.
137 * @return status.
138 */
139 int calibrateSensor(const yarp::sig::Vector& value) override;
140
141 /* Calibrates one single channel.
142 * @param ch: channel number.
143 * @return status.
144 */
145 int calibrateChannel(int ch) override;
146
147 /* Calibrates one single channel.
148 * @param ch: channel number.
149 * @param value: calibration value.
150 * @return status.
151 */
152 int calibrateChannel(int ch, double value) override;
153
154 /* IPreciselyTimed methods */
160};
161
162#endif // YARP_DEV_ANALOGSENSORCLIENT_ANALOGSENSORCLIENT_H
const int ANALOG_TIMEOUT
define control board standard interfaces
analog sensor interface
contains the definition of a Vector type
analogsensorclient deprecated: Device that reads an AnalogSensor (using the IAnalogSensor interface) ...
yarp::os::Stamp lastTs
void removeLeadingTrailingSlashesOnly(std::string &name)
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
bool close() override
Close the DeviceDriver.
~AnalogSensorClient() override=default
AnalogSensorClient(AnalogSensorClient &&)=delete
int calibrateChannel(int ch) override
Calibrates one single channel.
AnalogSensorClient & operator=(AnalogSensorClient &&)=delete
int calibrateSensor() override
Calibrates the whole sensor.
int read(yarp::sig::Vector &out) override
Read a vector from the sensor.
int getState(int ch) override
Check the state value of a given channel.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
AnalogSensorClient()=default
AnalogSensorClient(const AnalogSensorClient &)=delete
InputPortProcessor inputPort
yarp::os::Port rpcPort
int getChannels() override
Get the number of channels of the sensor.
AnalogSensorClient & operator=(const AnalogSensorClient &)=delete
void onRead(yarp::sig::Vector &v) override
int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp)
void getEstFrequency(int &ite, double &av, double &min, double &max)
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
A generic interface to sensors (gyro, a/d converters).
Definition: IAnalogSensor.h:27
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:60
A mini-server for network communication.
Definition: Port.h:46
A base class for nested structures that can be searched.
Definition: Searchable.h:63
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:21