YARP
Yet Another Robot Platform
Rangefinder2DClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef YARP_DEV_RANGEFINDER2DCLIENT_RANGEFINDER2DCLIENT_H
20 #define YARP_DEV_RANGEFINDER2DCLIENT_RANGEFINDER2DCLIENT_H
21 
22 
23 #include <yarp/os/Network.h>
24 #include <yarp/os/BufferedPort.h>
29 #include <yarp/dev/LaserScan2D.h>
30 #include <yarp/sig/Vector.h>
31 #include <yarp/os/Time.h>
32 #include <yarp/dev/PolyDriver.h>
33 
34 #include <mutex>
35 
36 
37 #define DEFAULT_THREAD_PERIOD 20 //ms
38 const int LASER_TIMEOUT=100; //ms
39 
41  public yarp::os::BufferedPort<yarp::dev::LaserScan2D>
42 {
43  yarp::dev::LaserScan2D lastScan;
44  std::mutex mutex;
45  yarp::os::Stamp lastStamp;
46  double deltaT;
47  double deltaTMax;
48  double deltaTMin;
49  double prev;
50  double now;
51 
52  int state;
53  int count;
54 
55 public:
56 
57  inline void resetStat();
58 
60 
62  void onRead(yarp::dev::LaserScan2D&v) override;
63 
64  inline int getLast(yarp::dev::LaserScan2D &data, yarp::os::Stamp &stmp);
65 
66  inline int getIterations();
67 
68  // time is in ms
69  void getEstFrequency(int &ite, double &av, double &min, double &max);
70 
71  bool getData(yarp::sig::Vector &data);
73 
74 };
75 
86 {
87 protected:
90  std::string local;
91  std::string remote;
92  yarp::os::Stamp lastTs; //used by IPreciselyTimed
93  std::string deviceId;
94 
100  std::string laser_frame_name;
101  std::string robot_frame_name;
102 
103 public:
104 
105  /* DevideDriver methods */
106  bool open(yarp::os::Searchable& config) override;
107  bool close() override;
108 
109 
110  /* IPreciselyTimed methods */
116 
122  bool getLaserMeasurement(std::vector<yarp::dev::LaserMeasurementData> &data) override;
123 
129  bool getRawData(yarp::sig::Vector &data) override;
130 
136  bool getDeviceStatus(Device_status &status) override;
137 
144  bool getDistanceRange(double& min, double& max) override;
145 
152  bool setDistanceRange(double min, double max) override;
153 
160  bool getScanLimits(double& min, double& max) override;
161 
168  bool setScanLimits(double min, double max) override;
169 
175  bool getHorizontalResolution(double& step) override;
176 
182  bool setHorizontalResolution(double step) override;
183 
189  bool getScanRate(double& rate) override;
190 
196  bool setScanRate(double rate) override;
197 
203  bool getDeviceInfo(std::string &device_info) override;
204 
205 };
206 
207 #endif // YARP_DEV_RANGEFINDER2DCLIENT_RANGEFINDER2DCLIENT_H
define control board standard interfaces
const int LASER_TIMEOUT
contains the definition of a Vector type
The client side of any ILaserRangefinder2D capable device.
bool setDistanceRange(double min, double max) override
set the device detection range.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getHorizontalResolution(double &step) override
get the angular step between two measurments.
bool getScanRate(double &rate) override
get the scan rate (scans per seconds)
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
bool close() override
Close the DeviceDriver.
yarp::os::Stamp lastTs
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
bool setScanLimits(double min, double max) override
set the scan angular range.
bool getDistanceRange(double &min, double &max) override
get the device detection range
bool getLaserMeasurement(std::vector< yarp::dev::LaserMeasurementData > &data) override
Get the device measurements.
bool getDeviceStatus(Device_status &status) override
get the device status
bool getRawData(yarp::sig::Vector &data) override
Get the device measurements.
Rangefinder2DInputPortProcessor inputPort
bool getDeviceInfo(std::string &device_info) override
get the device hardware charactestics
bool getScanLimits(double &min, double &max) override
get the scan angular range.
bool getData(yarp::sig::Vector &data)
void getEstFrequency(int &ite, double &av, double &min, double &max)
int getLast(yarp::dev::LaserScan2D &data, yarp::os::Stamp &stmp)
void onRead(yarp::dev::LaserScan2D &v) override
yarp::dev::IRangefinder2D::Device_status getStatus()
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A generic interface for planar laser range finders.
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