YARP
Yet Another Robot Platform
AnalogSensorClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_DEV_ANALOGSENSORCLIENT_ANALOGSENSORCLIENT_H
10 #define YARP_DEV_ANALOGSENSORCLIENT_ANALOGSENSORCLIENT_H
11 
12 
13 #include <yarp/os/Network.h>
14 #include <yarp/os/BufferedPort.h>
16 #include <yarp/dev/IAnalogSensor.h>
19 #include <yarp/sig/Vector.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/dev/PolyDriver.h>
22 
23 #include <mutex>
24 
25 
26 const int ANALOG_TIMEOUT=100; //ms
27 
28 
29 class InputPortProcessor : public yarp::os::BufferedPort<yarp::sig::Vector>
30 {
31  yarp::sig::Vector lastVector;
32  std::mutex mutex;
33  yarp::os::Stamp lastStamp;
34  double deltaT;
35  double deltaTMax;
36  double deltaTMin;
37  double prev;
38  double now;
39 
40  int state;
41  int count;
42 
43 public:
44 
45  inline void resetStat();
46 
48 
50  void onRead(yarp::sig::Vector &v) override;
51 
52  inline int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp);
53 
54  inline int getIterations();
55 
56  // time is in ms
57  void getEstFrequency(int &ite, double &av, double &min, double &max);
58 
59  int getState();
60 
61  int getChannels();
62 };
63 
94 {
95 protected:
98  std::string local;
99  std::string remote;
100  yarp::os::Stamp lastTs; //used by IPreciselyTimed
101  std::string robotName;
102  std::string deviceId;
103  std::string sensorType;
104  std::string portPrefix;
105 
106  void removeLeadingTrailingSlashesOnly(std::string &name);
107 
108 public:
109  AnalogSensorClient() = default;
114  ~AnalogSensorClient() override = default;
115 
116  /* DeviceDriver methods */
117  bool open(yarp::os::Searchable& config) override;
118  bool close() override;
119 
120  /* IAnalogSensor methods*/
121  int read(yarp::sig::Vector &out) override;
122 
123  /* Check the state value of a given channel.
124  * @param ch: channel number.
125  * @return status.
126  */
127  int getState(int ch) override;
128 
129  /* Get the number of channels of the sensor.
130  * @return number of channels (0 in case of errors).
131  */
132  int getChannels() override;
133 
134  /* Calibrates the whole sensor.
135  * @return status.
136  */
137  int calibrateSensor() override;
138 
139  /* Calibrates the whole sensor, using a vector of calibration values.
140  * @param value: a vector of calibration values.
141  * @return status.
142  */
143  int calibrateSensor(const yarp::sig::Vector& value) override;
144 
145  /* Calibrates one single channel.
146  * @param ch: channel number.
147  * @return status.
148  */
149  int calibrateChannel(int ch) override;
150 
151  /* Calibrates one single channel.
152  * @param ch: channel number.
153  * @param value: calibration value.
154  * @return status.
155  */
156  int calibrateChannel(int ch, double value) override;
157 
158  /* IPreciselyTimed methods */
164 };
165 
166 #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
The client side of any IAnalogSensor capable device.
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 & operator=(AnalogSensorClient &&)=delete
AnalogSensorClient(AnalogSensorClient &&)=delete
int calibrateChannel(int ch) override
Calibrates one single channel.
AnalogSensorClient & operator=(const 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.
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:38
A generic interface to sensors (gyro, a/d converters).
Definition: IAnalogSensor.h:31
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
A mini-server for network communication.
Definition: Port.h:50
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25