YARP
Yet Another Robot Platform
fakeLaser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef FAKE_LASER_H
11 #define FAKE_LASER_H
12 
13 
14 #include <yarp/os/PeriodicThread.h>
15 #include <yarp/os/BufferedPort.h>
20 #include <yarp/dev/MapGrid2D.h>
21 #include <yarp/dev/PolyDriver.h>
22 #include <yarp/sig/Vector.h>
23 
24 #include <mutex>
25 #include <random>
26 #include <string>
27 
62 {
63 protected:
66 
70 
71  double m_period;
76 
77  //this is the position of the localized robot in the map
78  double m_robot_loc_x;
79  double m_robot_loc_y;
80  double m_robot_loc_t;
81 
82  std::random_device* m_rd;
83  std::mt19937* m_gen;
84  std::uniform_real_distribution<>* m_dis;
85  double m_const_value=1;
86 
87 public:
88  FakeLaser(double period = 0.02) : PeriodicThread(period),
91  m_loc_port(nullptr),
92  m_pLoc(nullptr),
93  m_iLoc(nullptr),
94  m_robot_loc_x(0.0),
95  m_robot_loc_y(0.0),
96  m_robot_loc_t(0.0)
97  {
98  //default parameters
99  m_min_distance = 0.1; //m
100  m_max_distance = 8.0; //m
101  m_min_angle = 0; //degrees
102  m_max_angle = 360; //degrees
103  m_resolution = 1.0; //degrees
104 
105  //noise generator
106  m_rd = new std::random_device;
107  m_gen = new std::mt19937((*m_rd)());
108  m_dis = new std::uniform_real_distribution<>(0, 0.01);
109  }
110 
112  {
113  delete m_rd;
114  delete m_gen;
115  delete m_dis;
116  m_rd = 0;
117  m_gen = 0;
118  m_dis = 0;
119  if (m_loc_port)
120  {
121  delete m_loc_port;
122  m_loc_port = 0;
123  }
124  if (m_pLoc)
125  {
126  delete m_pLoc;
127  m_pLoc = 0;
128  }
129  }
130 
131  bool open(yarp::os::Searchable& config) override;
132  bool close() override;
133  bool threadInit() override;
134  void threadRelease() override;
135  void run() override;
136 
137 private:
138  double checkStraightLine(yarp::dev::Nav2D::XYCell src, yarp::dev::Nav2D::XYCell dst);
139 
140 public:
141  //IRangefinder2D interface
142  bool setDistanceRange (double min, double max) override;
143  bool setScanLimits (double min, double max) override;
144  bool setHorizontalResolution (double step) override;
145  bool setScanRate (double rate) override;
146 
147 };
148 
149 #endif
define control board standard interfaces
contains the definition of a map type
contains the definition of a Vector type
fakeLaser : fake sensor device driver for testing purposes and reference for IRangefinder2D devices.
Definition: fakeLaser.h:62
double m_robot_loc_y
Definition: fakeLaser.h:79
FakeLaser(double period=0.02)
Definition: fakeLaser.h:88
yarp::dev::PolyDriver * m_pLoc
Definition: fakeLaser.h:74
std::mt19937 * m_gen
Definition: fakeLaser.h:83
double m_robot_loc_x
Definition: fakeLaser.h:78
double m_period
Definition: fakeLaser.h:71
void run() override
Loop function.
Definition: fakeLaser.cpp:216
yarp::dev::Nav2D::MapGrid2D m_map
Definition: fakeLaser.h:72
bool setDistanceRange(double min, double max) override
set the device detection range.
Definition: fakeLaser.cpp:172
double m_robot_loc_t
Definition: fakeLaser.h:80
@ USE_CONSTANT_VALUE
Definition: fakeLaser.h:64
@ NO_OBSTACLES
Definition: fakeLaser.h:64
@ USE_MAPFILE
Definition: fakeLaser.h:64
@ USE_PATTERN
Definition: fakeLaser.h:64
yarp::dev::Nav2D::ILocalization2D * m_iLoc
Definition: fakeLaser.h:75
~FakeLaser()
Definition: fakeLaser.h:111
localization_mode_t m_loc_mode
Definition: fakeLaser.h:69
bool threadInit() override
Initialization method.
Definition: fakeLaser.cpp:206
yarp::os::BufferedPort< yarp::os::Bottle > * m_loc_port
Definition: fakeLaser.h:73
yarp::dev::PolyDriver driver
Definition: fakeLaser.h:67
std::random_device * m_rd
Definition: fakeLaser.h:82
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: fakeLaser.cpp:37
test_mode_t m_test_mode
Definition: fakeLaser.h:68
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
Definition: fakeLaser.cpp:198
bool setScanLimits(double min, double max) override
set the scan angular range.
Definition: fakeLaser.cpp:181
std::uniform_real_distribution * m_dis
Definition: fakeLaser.h:84
bool close() override
Close the DeviceDriver.
Definition: fakeLaser.cpp:158
void threadRelease() override
Release method.
Definition: fakeLaser.cpp:375
localization_mode_t
Definition: fakeLaser.h:65
@ LOC_NOT_SET
Definition: fakeLaser.h:65
@ LOC_FROM_CLIENT
Definition: fakeLaser.h:65
@ LOC_FROM_PORT
Definition: fakeLaser.h:65
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
Definition: fakeLaser.cpp:190
double m_const_value
Definition: fakeLaser.h:85
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
The DLidarDeviceTemplate class.
ILocalization2D interface.
A container for a device driver.
Definition: PolyDriver.h:27
An abstraction for a periodic thread.
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No)
Constructor.
void step()
Call this to "step" the thread rather than starting it.
A base class for nested structures that can be searched.
Definition: Searchable.h:69