YARP
Yet Another Robot Platform
laserFromExternalPort.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 LASER_FROM_EXTERNAL_PORT_H
20 #define LASER_FROM_EXTERNAL_PORT_H
21 
22 #include <yarp/os/PeriodicThread.h>
23 #include <yarp/os/Semaphore.h>
24 #include <yarp/os/Port.h>
25 #include <yarp/os/BufferedPort.h>
26 #include <yarp/os/Stamp.h>
29 #include <yarp/dev/LaserScan2D.h>
31 #include <yarp/sig/Vector.h>
33 #include <yarp/dev/PolyDriver.h>
34 
35 #include <mutex>
36 #include <string>
37 #include <vector>
38 
39 typedef unsigned char byte;
40 
41 //---------------------------------------------------------------------------------------------------------------
43 {
46  BASE_IS_ZERO = 2
47 };
48 
49 class InputPortProcessor :
50  public yarp::os::BufferedPort<yarp::dev::LaserScan2D>
51 {
52  std::mutex m_port_mutex;
53  yarp::dev::LaserScan2D m_lastScan;
54  yarp::os::Stamp m_lastStamp;
55  bool m_contains_data;
56 
57 public:
59  yarp::os::BufferedPort<yarp::dev::LaserScan2D>(),
60  m_lastScan(alt.m_lastScan),
61  m_lastStamp(alt.m_lastStamp),
62  m_contains_data(alt.m_contains_data)
63  {
64  }
65 
68  void onRead(yarp::dev::LaserScan2D& v) override;
70 };
71 
80 {
81 protected:
83  std::vector <std::string> m_port_names;
84  std::vector<InputPortProcessor> m_input_ports;
85  std::vector <yarp::os::Stamp> m_last_stamp;
86  std::vector <yarp::dev::LaserScan2D> m_last_scan_data;
89 
90  std::vector <std::string> m_src_frame_id;
91  std::string m_dst_frame_id;
94 
96 
97 public:
98  LaserFromExternalPort(double period = 0.01) : Lidar2DDeviceBase(), PeriodicThread(period)
99  {
102  }
103 
105  {
106  }
107 
108  bool open(yarp::os::Searchable& config) override;
109  bool close() override;
110  bool threadInit() override;
111  void threadRelease() override;
112  void run() override;
113 
114 public:
115  //IRangefinder2D interface
116  bool setDistanceRange (double min, double max) override;
117  bool setScanLimits (double min, double max) override;
118  bool setHorizontalResolution (double step) override;
119  bool setScanRate (double rate) override;
120 };
121 
122 #endif
LaserFromExternalPort::m_last_scan_data
std::vector< yarp::dev::LaserScan2D > m_last_scan_data
Definition: laserFromExternalPort.h:86
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
IRangefinder2D.h
Vector.h
contains the definition of a Vector type
LaserFromExternalPort::m_port_names
std::vector< std::string > m_port_names
Definition: laserFromExternalPort.h:83
Lidar2DDeviceBase.h
LaserFromExternalPort::threadRelease
void threadRelease() override
Release method.
Definition: laserFromExternalPort.cpp:461
InputPortProcessor
Definition: AnalogSensorClient.h:30
Port.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::dev::Lidar2DDeviceBase::Lidar2DDeviceBase
Lidar2DDeviceBase()
Definition: Lidar2DDeviceBase.cpp:96
LaserFromExternalPort::m_input_ports
std::vector< InputPortProcessor > m_input_ports
Definition: laserFromExternalPort.h:84
LaserFromExternalPort::run
void run() override
Loop function.
Definition: laserFromExternalPort.cpp:397
yarp::os::PeriodicThread::PeriodicThread
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No)
Constructor.
Definition: PeriodicThread.cpp:271
LaserFromExternalPort::m_option_override_limits
bool m_option_override_limits
Definition: laserFromExternalPort.h:82
yarp::dev::LaserScan2D
Definition: LaserScan2D.h:28
InputPortProcessor::onRead
void onRead(yarp::sig::Vector &v) override
Definition: AnalogSensorClient.cpp:52
ControlBoardInterfaces.h
define control board standard interfaces
yarp::dev::IFrameTransform
Transform Interface.
Definition: IFrameTransform.h:33
LaserFromExternalPort
laserFromExternalPort: Documentation to be added
Definition: laserFromExternalPort.h:80
yarp::dev::Lidar2DDeviceBase
The DLidarDeviceTemplate class.
Definition: Lidar2DDeviceBase.h:33
InputPortProcessor::InputPortProcessor
InputPortProcessor()
yarp::sig::VectorOf< double >
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
LaserFromExternalPort::m_empty_laser_data
yarp::sig::Vector m_empty_laser_data
Definition: laserFromExternalPort.h:92
LaserScan2D.h
LaserFromExternalPort::setHorizontalResolution
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
Definition: laserFromExternalPort.cpp:298
LaserFromExternalPort::calculate
void calculate(yarp::dev::LaserScan2D scan, yarp::sig::Matrix m)
Definition: laserFromExternalPort.cpp:324
LaserFromExternalPort::LaserFromExternalPort
LaserFromExternalPort(double period=0.01)
Definition: laserFromExternalPort.h:98
InputPortProcessor::getLast
int getLast(yarp::sig::Vector &data, yarp::os::Stamp &stmp)
Definition: AnalogSensorClient.cpp:104
PolyDriver.h
LaserFromExternalPort::m_src_frame_id
std::vector< std::string > m_src_frame_id
Definition: laserFromExternalPort.h:90
BASE_IS_ZERO
@ BASE_IS_ZERO
Definition: laserFromExternalPort.h:46
Stamp.h
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
LaserFromExternalPort::m_tc_driver
yarp::dev::PolyDriver m_tc_driver
Definition: laserFromExternalPort.h:87
InputPortProcessor::InputPortProcessor
InputPortProcessor(const InputPortProcessor &alt)
Definition: laserFromExternalPort.h:58
LaserFromExternalPort::m_iTc
yarp::dev::IFrameTransform * m_iTc
Definition: laserFromExternalPort.h:88
BASE_IS_NAN
@ BASE_IS_NAN
Definition: laserFromExternalPort.h:44
BASE_IS_INF
@ BASE_IS_INF
Definition: laserFromExternalPort.h:45
Semaphore.h
BufferedPort.h
LaserFromExternalPort::m_last_stamp
std::vector< yarp::os::Stamp > m_last_stamp
Definition: laserFromExternalPort.h:85
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
LaserFromExternalPort::threadInit
bool threadInit() override
Initialization method.
Definition: laserFromExternalPort.cpp:314
LaserFromExternalPort::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: laserFromExternalPort.cpp:113
PeriodicThread.h
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
LaserFromExternalPort::close
bool close() override
Close the DeviceDriver.
Definition: laserFromExternalPort.cpp:266
yarp::os::BufferedPort< yarp::sig::Vector >::BufferedPort
BufferedPort()
Constructor.
Definition: BufferedPort-inl.h:17
LaserFromExternalPort::m_base_type
base_enum m_base_type
Definition: laserFromExternalPort.h:93
LaserFromExternalPort::setDistanceRange
bool setDistanceRange(double min, double max) override
set the device detection range.
Definition: laserFromExternalPort.cpp:281
LaserFromExternalPort::~LaserFromExternalPort
~LaserFromExternalPort()
Definition: laserFromExternalPort.h:104
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
byte
unsigned char byte
Definition: laserFromExternalPort.h:39
yarp::os::PeriodicThread::step
void step()
Call this to "step" the thread rather than starting it.
Definition: PeriodicThread.cpp:306
LaserFromExternalPort::setScanRate
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
Definition: laserFromExternalPort.cpp:305
base_enum
base_enum
Definition: laserFromExternalPort.h:43
IFrameTransform.h
LaserFromExternalPort::m_dst_frame_id
std::string m_dst_frame_id
Definition: laserFromExternalPort.h:91
LaserFromExternalPort::setScanLimits
bool setScanLimits(double min, double max) override
set the scan angular range.
Definition: laserFromExternalPort.cpp:289
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46