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;
110  AnalogSensorClient(const AnalogSensorClient&) = delete;
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
Network.h
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:68
AnalogSensorClient::operator=
AnalogSensorClient & operator=(const AnalogSensorClient &)=delete
Vector.h
InputPortProcessor::getChannels
int getChannels()
Definition: AnalogSensorClient.cpp:150
InputPortProcessor
Definition: AnalogSensorClient.h:29
IPreciselyTimed.h
yarp::dev::DeviceDriver
Definition: DeviceDriver.h:37
ControlBoardHelpers.h
AnalogSensorClient::getState
int getState(int ch) override
Check the state value of a given channel.
Definition: AnalogSensorClient.cpp:257
AnalogSensorClient::AnalogSensorClient
AnalogSensorClient()=default
InputPortProcessor::onRead
void onRead(yarp::sig::Vector &v) override
Callback method.
Definition: AnalogSensorClient.cpp:52
ControlBoardInterfaces.h
AnalogSensorClient::deviceId
std::string deviceId
Definition: AnalogSensorClient.h:102
InputPortProcessor::InputPortProcessor
InputPortProcessor()
Definition: AnalogSensorClient.cpp:46
AnalogSensorClient::rpcPort
yarp::os::Port rpcPort
Definition: AnalogSensorClient.h:97
yarp::sig::VectorOf< double >
yarp::os::Port
Definition: Port.h:49
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:63
AnalogSensorClient::getChannels
int getChannels() override
Get the number of channels of the sensor.
Definition: AnalogSensorClient.cpp:263
ANALOG_TIMEOUT
const int ANALOG_TIMEOUT
Definition: AnalogSensorClient.h:26
AnalogSensorClient::local
std::string local
Definition: AnalogSensorClient.h:98
AnalogSensorClient::sensorType
std::string sensorType
Definition: AnalogSensorClient.h:103
InputPortProcessor::getLast
int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp)
Definition: AnalogSensorClient.cpp:104
AnalogSensorClient
The client side of any IAnalogSensor capable device.
Definition: AnalogSensorClient.h:90
PolyDriver.h
InputPortProcessor::getEstFrequency
void getEstFrequency(int &ite, double &av, double &min, double &max)
Definition: AnalogSensorClient.cpp:127
AnalogSensorClient::close
bool close() override
Close the DeviceDriver.
Definition: AnalogSensorClient.cpp:245
InputPortProcessor::getIterations
int getIterations()
Definition: AnalogSensorClient.cpp:118
AnalogSensorClient::getLastInputStamp
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
Definition: AnalogSensorClient.cpp:310
AnalogSensorClient::calibrateSensor
int calibrateSensor() override
Calibrates the whole sensor.
Definition: AnalogSensorClient.cpp:268
yarp::dev::IAnalogSensor
Definition: IAnalogSensor.h:30
InputPortProcessor::getState
int getState()
Definition: AnalogSensorClient.cpp:145
BufferedPort.h
AnalogSensorClient::calibrateChannel
int calibrateChannel(int ch) override
Calibrates one single channel.
Definition: AnalogSensorClient.cpp:289
AnalogSensorClient::remote
std::string remote
Definition: AnalogSensorClient.h:99
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:24
AnalogSensorClient::removeLeadingTrailingSlashesOnly
void removeLeadingTrailingSlashesOnly(std::string &name)
Definition: AnalogSensorClient.cpp:162
AnalogSensorClient::lastTs
yarp::os::Stamp lastTs
Definition: AnalogSensorClient.h:100
AnalogSensorClient::~AnalogSensorClient
~AnalogSensorClient() override=default
InputPortProcessor::resetStat
void resetStat()
Definition: AnalogSensorClient.cpp:34
Time.h
AnalogSensorClient::read
int read(yarp::sig::Vector &out) override
Read a vector from the sensor.
Definition: AnalogSensorClient.cpp:252
IAnalogSensor.h
AnalogSensorClient::portPrefix
std::string portPrefix
Definition: AnalogSensorClient.h:104
AnalogSensorClient::robotName
std::string robotName
Definition: AnalogSensorClient.h:101
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:20
AnalogSensorClient::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: AnalogSensorClient.cpp:189
AnalogSensorClient::inputPort
InputPortProcessor inputPort
Definition: AnalogSensorClient.h:96