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
Rangefinder2DClient::device_position_theta
double device_position_theta
Definition: Rangefinder2DClient.h:99
Rangefinder2DClient::robot_frame_name
std::string robot_frame_name
Definition: Rangefinder2DClient.h:101
Rangefinder2DClient::getLastInputStamp
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
Definition: Rangefinder2DClient.cpp:463
Network.h
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
IRangefinder2D.h
LASER_TIMEOUT
const int LASER_TIMEOUT
Definition: Rangefinder2DClient.h:38
Rangefinder2DClient::local
std::string local
Definition: Rangefinder2DClient.h:90
Rangefinder2DClient::setScanLimits
bool setScanLimits(double min, double max) override
set the scan angular range.
Definition: Rangefinder2DClient.cpp:378
Vector.h
contains the definition of a Vector type
Rangefinder2DClient::inputPort
Rangefinder2DInputPortProcessor inputPort
Definition: Rangefinder2DClient.h:88
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Rangefinder2DClient::setHorizontalResolution
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
Definition: Rangefinder2DClient.cpp:405
Rangefinder2DClient::rpcPort
yarp::os::Port rpcPort
Definition: Rangefinder2DClient.h:89
Rangefinder2DClient::getHorizontalResolution
bool getHorizontalResolution(double &step) override
get the angular step between two measurments.
Definition: Rangefinder2DClient.cpp:390
Rangefinder2DClient::getDistanceRange
bool getDistanceRange(double &min, double &max) override
get the device detection range
Definition: Rangefinder2DClient.cpp:329
yarp::dev::IRangefinder2D
A generic interface for planar laser range finders.
Definition: IRangefinder2D.h:38
ControlBoardHelpers.h
Rangefinder2DInputPortProcessor::getLast
int getLast(yarp::dev::LaserScan2D &data, yarp::os::Stamp &stmp)
Definition: Rangefinder2DClient.cpp:116
Rangefinder2DClient::remote
std::string remote
Definition: Rangefinder2DClient.h:91
yarp::dev::LaserScan2D
Definition: LaserScan2D.h:28
Rangefinder2DClient::lastTs
yarp::os::Stamp lastTs
Definition: Rangefinder2DClient.h:92
yarp::dev::IRangefinder2D::Device_status
Device_status
Definition: IRangefinder2D.h:41
ControlBoardInterfaces.h
define control board standard interfaces
Rangefinder2DInputPortProcessor::resetStat
void resetStat()
Definition: Rangefinder2DClient.cpp:46
Rangefinder2DClient::scan_angle_min
double scan_angle_min
Definition: Rangefinder2DClient.h:95
yarp::sig::VectorOf< double >
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
LaserScan2D.h
Rangefinder2DClient::close
bool close() override
Close the DeviceDriver.
Definition: Rangefinder2DClient.cpp:295
PolyDriver.h
Rangefinder2DInputPortProcessor::onRead
void onRead(yarp::dev::LaserScan2D &v) override
Definition: Rangefinder2DClient.cpp:64
Rangefinder2DClient::setScanRate
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
Definition: Rangefinder2DClient.cpp:431
Rangefinder2DClient::scan_angle_max
double scan_angle_max
Definition: Rangefinder2DClient.h:96
Rangefinder2DInputPortProcessor::getIterations
int getIterations()
Definition: Rangefinder2DClient.cpp:146
BufferedPort.h
Rangefinder2DClient::device_position_y
double device_position_y
Definition: Rangefinder2DClient.h:98
Rangefinder2DClient
Rangefinder2DClient: The client side of any ILaserRangefinder2D capable device.
Definition: Rangefinder2DClient.h:86
Rangefinder2DInputPortProcessor::getStatus
yarp::dev::IRangefinder2D::Device_status getStatus()
Definition: Rangefinder2DClient.cpp:138
Rangefinder2DClient::getScanRate
bool getScanRate(double &rate) override
get the scan rate (scans per seconds)
Definition: Rangefinder2DClient.cpp:416
Rangefinder2DClient::laser_frame_name
std::string laser_frame_name
Definition: Rangefinder2DClient.h:100
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
Rangefinder2DClient::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: Rangefinder2DClient.cpp:173
Rangefinder2DInputPortProcessor::getData
bool getData(yarp::sig::Vector &data)
Definition: Rangefinder2DClient.cpp:130
Rangefinder2DClient::deviceId
std::string deviceId
Definition: Rangefinder2DClient.h:93
Rangefinder2DClient::getDeviceStatus
bool getDeviceStatus(Device_status &status) override
get the device status
Definition: Rangefinder2DClient.cpp:442
Rangefinder2DClient::getLaserMeasurement
bool getLaserMeasurement(std::vector< yarp::dev::LaserMeasurementData > &data) override
Get the device measurements.
Definition: Rangefinder2DClient.cpp:308
Rangefinder2DClient::setDistanceRange
bool setDistanceRange(double min, double max) override
set the device detection range.
Definition: Rangefinder2DClient.cpp:345
Rangefinder2DClient::getRawData
bool getRawData(yarp::sig::Vector &data) override
Get the device measurements.
Definition: Rangefinder2DClient.cpp:302
Rangefinder2DClient::getDeviceInfo
bool getDeviceInfo(std::string &device_info) override
get the device hardware charactestics
Definition: Rangefinder2DClient.cpp:448
Time.h
Rangefinder2DInputPortProcessor::getEstFrequency
void getEstFrequency(int &ite, double &av, double &min, double &max)
Definition: Rangefinder2DClient.cpp:155
Rangefinder2DInputPortProcessor::Rangefinder2DInputPortProcessor
Rangefinder2DInputPortProcessor()
Definition: Rangefinder2DClient.cpp:58
Rangefinder2DClient::getScanLimits
bool getScanLimits(double &min, double &max) override
get the scan angular range.
Definition: Rangefinder2DClient.cpp:362
Rangefinder2DClient::device_position_x
double device_position_x
Definition: Rangefinder2DClient.h:97
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
Rangefinder2DInputPortProcessor
Definition: Rangefinder2DClient.h:42