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 
75 {
76 protected:
78  std::vector <std::string> m_port_names;
79  std::vector<InputPortProcessor> m_input_ports;
80  std::vector <yarp::os::Stamp> m_last_stamp;
81  std::vector <yarp::dev::LaserScan2D> m_last_scan_data;
84 
85  std::vector <std::string> m_src_frame_id;
86  std::string m_dst_frame_id;
89 
91 
92 public:
93  LaserFromExternalPort(double period = 0.01) : Lidar2DDeviceBase(), PeriodicThread(period)
94  {
97  }
98 
100  {
101  }
102 
103  bool open(yarp::os::Searchable& config) override;
104  bool close() override;
105  bool threadInit() override;
106  void threadRelease() override;
107  void run() override;
108 
109 public:
110  //IRangefinder2D interface
111  bool setDistanceRange (double min, double max) override;
112  bool setScanLimits (double min, double max) override;
113  bool setHorizontalResolution (double step) override;
114  bool setScanRate (double rate) override;
115 };
116 
117 #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)
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 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:38
Transform Interface.
The DLidarDeviceTemplate class.
A container for a device driver.
Definition: PolyDriver.h:27
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
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
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
A class for a Matrix.
Definition: Matrix.h:46
unsigned char byte
@ BASE_IS_NAN
@ BASE_IS_ZERO
@ BASE_IS_INF
The main, catch-all namespace for YARP.
Definition: environment.h:18