YARP
Yet Another Robot Platform
AnalogSensorClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 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 namespace yarp {
26  namespace dev {
27  class AnalogSensorClient;
28  }
29 }
30 
31 
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 
34 const int ANALOG_TIMEOUT=100; //ms
35 
36 
37 class InputPortProcessor : public yarp::os::BufferedPort<yarp::sig::Vector>
38 {
39  yarp::sig::Vector lastVector;
40  std::mutex mutex;
41  yarp::os::Stamp lastStamp;
42  double deltaT;
43  double deltaTMax;
44  double deltaTMin;
45  double prev;
46  double now;
47 
48  int state;
49  int count;
50 
51 public:
52 
53  inline void resetStat();
54 
55  InputPortProcessor();
56 
58  void onRead(yarp::sig::Vector &v) override;
59 
60  inline int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp);
61 
62  inline int getIterations();
63 
64  // time is in ms
65  void getEstFrequency(int &ite, double &av, double &min, double &max);
66 
67  int getState();
68 
69  int getChannels();
70 };
71 
77 #endif /*DOXYGEN_SHOULD_SKIP_THIS*/
78 
100  public IPreciselyTimed,
101  public IAnalogSensor
102 {
103 #ifndef DOXYGEN_SHOULD_SKIP_THIS
104 protected:
105  InputPortProcessor inputPort;
106  yarp::os::Port rpcPort;
107  std::string local;
108  std::string remote;
109  yarp::os::Stamp lastTs; //used by IPreciselyTimed
110  std::string robotName;
111  std::string deviceId;
112  std::string sensorType;
113  std::string portPrefix;
114 
115  void removeLeadingTrailingSlashesOnly(std::string &name);
116 #endif /*DOXYGEN_SHOULD_SKIP_THIS*/
117 
118 public:
119 
120  /* DeviceDriver methods */
121  bool open(yarp::os::Searchable& config) override;
122  bool close() override;
123 
124  /* IAnalogSensor methods*/
125  int read(yarp::sig::Vector &out) override;
126 
127  /* Check the state value of a given channel.
128  * @param ch: channel number.
129  * @return status.
130  */
131  int getState(int ch) override;
132 
133  /* Get the number of channels of the sensor.
134  * @return number of channels (0 in case of errors).
135  */
136  int getChannels() override;
137 
138  /* Calibrates the whole sensor.
139  * @return status.
140  */
141  int calibrateSensor() override;
142 
143  /* Calibrates the whole sensor, using a vector of calibration values.
144  * @param value: a vector of calibration values.
145  * @return status.
146  */
147  int calibrateSensor(const yarp::sig::Vector& value) override;
148 
149  /* Calibrates one single channel.
150  * @param ch: channel number.
151  * @return status.
152  */
153  int calibrateChannel(int ch) override;
154 
155  /* Calibrates one single channel.
156  * @param ch: channel number.
157  * @param value: calibration value.
158  * @return status.
159  */
160  int calibrateChannel(int ch, double value) override;
161 
162  /* IPreciselyTimed methods */
167  yarp::os::Stamp getLastInputStamp() override;
168 };
169 
170 #endif // YARP_DEV_ANALOGSENSORCLIENT_ANALOGSENSORCLIENT_H
Interface implemented by all device drivers.
Definition: DeviceDriver.h:37
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:516
A base class for nested structures that can be searched.
Definition: Searchable.h:68
A mini-server for network communication.
Definition: Port.h:49
Provides:
Definition: Vector.h:32
The main, catch-all namespace for YARP.
Definition: numeric.h:47
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition: Time.cpp:121
Device that reads an AnalogSensor (using the IAnalogSensor interface) from the YARP network...
define control board standard interfaces
contains the definition of a Vector type
A generic interface to sensors (gyro, a/d converters).
Definition: IAnalogSensor.h:32
analog sensor interface
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:24
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:63