YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeLaser.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef FAKE_LASER_H
8#define FAKE_LASER_H
9
10
17#include <yarp/dev/MapGrid2D.h>
18#include <yarp/dev/PolyDriver.h>
19#include <yarp/sig/Vector.h>
20
21#include <mutex>
22#include <random>
23#include <string>
24
26
49{
50protected:
53
56
62
63 //this is the position of the localized robot in the map
67
68 std::random_device* m_rd;
69 std::mt19937* m_gen;
70 std::uniform_real_distribution<>* m_dis;
71
73
74public:
75 FakeLaser(double period = 0.02) : PeriodicThread(period),
78 m_loc_port(nullptr),
79 m_pLoc(nullptr),
80 m_iLoc(nullptr),
81 m_robot_loc_x(0.0),
82 m_robot_loc_y(0.0),
83 m_robot_loc_t(0.0)
84 {
85 //default parameters
86 m_min_distance = 0.1; //m
87 m_max_distance = 8.0; //m
88 m_min_angle = 0; //degrees
89 m_max_angle = 360; //degrees
90 m_resolution = 1.0; //degrees
91 m_scan_rate = period; //s
92
93 //noise generator
94 m_rd = new std::random_device;
95 m_gen = new std::mt19937((*m_rd)());
96 m_dis = new std::uniform_real_distribution<>(0, 0.01);
97 }
98
100 {
101 delete m_rd;
102 delete m_gen;
103 delete m_dis;
104 m_rd = 0;
105 m_gen = 0;
106 m_dis = 0;
107 if (m_loc_port)
108 {
109 delete m_loc_port;
110 m_loc_port = 0;
111 }
112 if (m_pLoc)
113 {
114 delete m_pLoc;
115 m_pLoc = 0;
116 }
117 }
118
119 bool open(yarp::os::Searchable& config) override;
120 bool close() override;
121 bool threadInit() override;
122 void threadRelease() override;
123 void run() override;
124
125private:
126 void drawStraightLine(yarp::dev::Nav2D::XYCell src, yarp::dev::Nav2D::XYCell dst);
127 void wall_the_robot(double siz = 1.0, double dist = 1.0);
128 void obst_the_robot(double siz = 1.0, double dist = 1.0);
129 void trap_the_robot(double siz = 1.0);
130 void free_the_robot();
131
132 double checkStraightLine(yarp::dev::Nav2D::XYCell src, yarp::dev::Nav2D::XYCell dst);
133 bool LiangBarsky_clip(int edgeLeft, int edgeRight, int edgeTop, int edgeBottom,
135 yarp::dev::Nav2D::XYCell& src_clipped, yarp::dev::Nav2D::XYCell& dst_clipped);
136
137public:
138 //IRangefinder2D interface
139 yarp::dev::ReturnValue setDistanceRange (double min, double max) override;
140 yarp::dev::ReturnValue setScanLimits (double min, double max) override;
142 yarp::dev::ReturnValue setScanRate (double rate) override;
143
144public:
145 //Lidar2DDeviceBase
146 bool acquireDataFromHW() override final;
147
148public:
149 bool read(yarp::os::ConnectionReader& connection) override;
150};
151
152#endif
define control board standard interfaces
contains the definition of a map type
contains the definition of a Vector type
This class is the parameters parser for class FakeLaser.
fakeLaser : fake sensor device driver for testing purposes and reference for IRangefinder2D devices.
Definition FakeLaser.h:49
double m_robot_loc_y
Definition FakeLaser.h:65
FakeLaser(double period=0.02)
Definition FakeLaser.h:75
yarp::dev::PolyDriver * m_pLoc
Definition FakeLaser.h:60
std::mt19937 * m_gen
Definition FakeLaser.h:69
double m_robot_loc_x
Definition FakeLaser.h:64
yarp::dev::ReturnValue setScanRate(double rate) override
set the scan rate (scans per seconds)
void run() override
Loop function.
yarp::dev::Nav2D::MapGrid2D m_map
Definition FakeLaser.h:58
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
double m_robot_loc_t
Definition FakeLaser.h:66
@ USE_CONSTANT_VALUE
Definition FakeLaser.h:51
@ NO_OBSTACLES
Definition FakeLaser.h:51
@ USE_SQUARE_TRAP
Definition FakeLaser.h:51
@ USE_MAPFILE
Definition FakeLaser.h:51
@ USE_PATTERN
Definition FakeLaser.h:51
bool acquireDataFromHW() override final
This method should be implemented by the user, and contain the logic to grab data from the hardware.
yarp::dev::Nav2D::ILocalization2D * m_iLoc
Definition FakeLaser.h:61
yarp::dev::ReturnValue setScanLimits(double min, double max) override
set the scan angular range.
localization_mode_t m_loc_mode
Definition FakeLaser.h:55
bool threadInit() override
Initialization method.
yarp::dev::ReturnValue setDistanceRange(double min, double max) override
set the device detection range.
yarp::os::BufferedPort< yarp::os::Bottle > * m_loc_port
Definition FakeLaser.h:59
std::random_device * m_rd
Definition FakeLaser.h:68
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition FakeLaser.cpp:32
test_mode_t m_test_mode
Definition FakeLaser.h:54
yarp::dev::ReturnValue setHorizontalResolution(double step) override
get the angular step between two measurements (if available)
std::uniform_real_distribution * m_dis
Definition FakeLaser.h:70
bool close() override
Close the DeviceDriver.
void threadRelease() override
Release method.
yarp::dev::Nav2D::MapGrid2D m_originally_loaded_map
Definition FakeLaser.h:57
localization_mode_t
Definition FakeLaser.h:52
@ LOC_NOT_SET
Definition FakeLaser.h:52
@ LOC_FROM_CLIENT
Definition FakeLaser.h:52
@ LOC_FROM_PORT
Definition FakeLaser.h:52
yarp::os::Port m_rpcPort
Definition FakeLaser.h:72
Interface implemented by all device drivers.
The Lidar2DDeviceBase class.
ILocalization2D interface.
A container for a device driver.
Definition PolyDriver.h:23
A mini-server for performing network communication in the background.
An abstraction for a periodic thread.
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No, PeriodicThreadClock clockAccuracy=PeriodicThreadClock::Relative)
Constructor.
void step()
Call this to "step" the thread rather than starting it.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A mini-server for network communication.
Definition Port.h:46
A base class for nested structures that can be searched.
Definition Searchable.h:31
The main, catch-all namespace for YARP.
Definition dirs.h:16