YARP
Yet Another Robot Platform
laserFromExternalPort.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #ifndef LASER_FROM_EXTERNAL_PORT_H
7 #define LASER_FROM_EXTERNAL_PORT_H
8 
10 #include <yarp/os/Semaphore.h>
11 #include <yarp/os/Port.h>
12 #include <yarp/os/BufferedPort.h>
13 #include <yarp/os/Stamp.h>
16 #include <yarp/dev/LaserScan2D.h>
18 #include <yarp/sig/Vector.h>
20 #include <yarp/dev/PolyDriver.h>
21 
22 #include <mutex>
23 #include <string>
24 #include <vector>
25 
26 typedef unsigned char byte;
27 
28 //---------------------------------------------------------------------------------------------------------------
30 {
33  BASE_IS_ZERO = 2
34 };
35 
36 class InputPortProcessor :
37  public yarp::os::BufferedPort<yarp::dev::LaserScan2D>
38 {
39  std::mutex m_port_mutex;
40  yarp::dev::LaserScan2D m_lastScan;
41  yarp::os::Stamp m_lastStamp;
42  bool m_contains_data;
43 
44 public:
46  yarp::os::BufferedPort<yarp::dev::LaserScan2D>(),
47  m_lastScan(alt.m_lastScan),
48  m_lastStamp(alt.m_lastStamp),
49  m_contains_data(alt.m_contains_data)
50  {
51  }
52 
55  void onRead(yarp::dev::LaserScan2D& v) override;
57 };
58 
67 {
68 protected:
70  std::vector <std::string> m_port_names;
71  std::vector<InputPortProcessor> m_input_ports;
72  std::vector <yarp::os::Stamp> m_last_stamp;
73  std::vector <yarp::dev::LaserScan2D> m_last_scan_data;
76 
77  std::vector <std::string> m_src_frame_id;
78  std::string m_dst_frame_id;
81 
83 
84 public:
85  LaserFromExternalPort(double period = 0.01) : Lidar2DDeviceBase(), PeriodicThread(period)
86  {
89  }
90 
92  {
93  }
94 
95  bool open(yarp::os::Searchable& config) override;
96  bool close() override;
97  bool threadInit() override;
98  void threadRelease() override;
99  void run() override;
100 
101 public:
102  //IRangefinder2D interface
103  bool setDistanceRange (double min, double max) override;
104  bool setScanLimits (double min, double max) override;
105  bool setHorizontalResolution (double step) override;
106  bool setScanRate (double rate) override;
107 
108 public:
109  //Lidar2DDeviceBase
110  bool acquireDataFromHW() override final;
111 };
112 
113 #endif
define control board standard interfaces
contains the definition of a Vector type
InputPortProcessor(const InputPortProcessor &alt)
void onRead(yarp::sig::Vector &v) override
int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp)
laserFromExternalPort: Documentation to be added
std::vector< InputPortProcessor > m_input_ports
bool close() override
Close the DeviceDriver.
std::vector< yarp::dev::LaserScan2D > m_last_scan_data
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool threadInit() override
Initialization method.
std::vector< std::string > m_src_frame_id
std::vector< yarp::os::Stamp > m_last_stamp
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
void calculate(yarp::dev::LaserScan2D scan, yarp::sig::Matrix m)
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
bool acquireDataFromHW() override final
This method should be implemented by the user, and contain the logic to grab data from the hardware.
bool setDistanceRange(double min, double max) override
set the device detection range.
yarp::sig::Vector m_empty_laser_data
yarp::dev::IFrameTransform * m_iTc
void run() override
Loop function.
LaserFromExternalPort(double period=0.01)
std::vector< std::string > m_port_names
void threadRelease() override
Release method.
bool setScanLimits(double min, double max) override
set the scan angular range.
yarp::dev::PolyDriver m_tc_driver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
Transform Interface.
The Lidar2DDeviceBase class.
A container for a device driver.
Definition: PolyDriver.h:23
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:60
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.
A base class for nested structures that can be searched.
Definition: Searchable.h:63
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:21
A class for a Matrix.
Definition: Matrix.h:39
unsigned char byte
@ BASE_IS_NAN
@ BASE_IS_ZERO
@ BASE_IS_INF
The main, catch-all namespace for YARP.
Definition: dirs.h:16