YARP
Yet Another Robot Platform
LaserFromRosTopic.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_ROS_TOPIC_H
20 #define LASER_FROM_ROS_TOPIC_H
21 
22 #include <yarp/os/PeriodicThread.h>
23 #include <yarp/os/Semaphore.h>
24 #include <yarp/os/Port.h>
25 #include <yarp/os/Subscriber.h>
26 #include <yarp/os/BufferedPort.h>
27 #include <yarp/os/Stamp.h>
30 #include <yarp/dev/LaserScan2D.h>
32 #include <yarp/sig/Vector.h>
34 #include <yarp/dev/PolyDriver.h>
35 
36  // ROS state publisher
37 #include <yarp/os/Node.h>
38 #include <yarp/os/Subscriber.h>
41 
42 #include <mutex>
43 #include <string>
44 #include <vector>
45 
46 typedef unsigned char byte;
47 
48 //---------------------------------------------------------------------------------------------------------------
50 {
53  BASE_IS_ZERO = 2
54 };
55 
56 class InputPortProcessor :
57  public yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>
58 {
59  std::mutex m_port_mutex;
60  yarp::dev::LaserScan2D m_lastScan;
61  yarp::os::Stamp m_lastStamp;
62  bool m_contains_data;
63 
64 public:
66  yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>(),
67  m_lastScan(alt.m_lastScan),
68  m_lastStamp(alt.m_lastStamp),
69  m_contains_data(alt.m_contains_data)
70  {
71  }
72 
75  virtual void onRead(yarp::rosmsg::sensor_msgs::LaserScan& v) override;
77 };
78 
82 {
83 protected:
85  std::vector <std::string> m_port_names;
87  std::vector<InputPortProcessor> m_input_ports;
88  std::vector <yarp::os::Stamp> m_last_stamp;
89  std::vector <yarp::dev::LaserScan2D> m_last_scan_data;
92 
93  std::vector <std::string> m_src_frame_id;
94  std::string m_dst_frame_id;
97 
99 
100 public:
101  LaserFromRosTopic(double period = 0.01) : Lidar2DDeviceBase(), PeriodicThread(period)
102  {
105  }
106 
108  {
109  }
110 
111  bool open(yarp::os::Searchable& config) override;
112  bool close() override;
113  bool threadInit() override;
114  void threadRelease() override;
115  void run() override;
116 
117 public:
118  //IRangefinder2D interface
119  bool setDistanceRange (double min, double max) override;
120  bool setScanLimits (double min, double max) override;
121  bool setHorizontalResolution (double step) override;
122  bool setScanRate (double rate) override;
123 };
124 
125 #endif
define control board standard interfaces
unsigned char byte
@ BASE_IS_NAN
@ BASE_IS_ZERO
@ BASE_IS_INF
contains the definition of a Vector type
InputPortProcessor(const InputPortProcessor &alt)
void onRead(yarp::sig::Vector &v) override
void getLast(yarp::dev::LaserScan2D &data, yarp::os::Stamp &stmp)
std::vector< yarp::dev::LaserScan2D > m_last_scan_data
bool close() override
Close the DeviceDriver.
std::vector< InputPortProcessor > m_input_ports
bool setDistanceRange(double min, double max) override
set the device detection range.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
std::vector< yarp::os::Stamp > m_last_stamp
void calculate(yarp::dev::LaserScan2D scan, yarp::sig::Matrix m)
std::vector< std::string > m_port_names
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
void run() override
Loop function.
yarp::os::Node * m_ros_node
yarp::dev::PolyDriver m_tc_driver
LaserFromRosTopic(double period=0.01)
bool setScanLimits(double min, double max) override
set the scan angular range.
bool threadInit() override
Initialization method.
yarp::sig::Vector m_empty_laser_data
void threadRelease() override
Release method.
std::vector< std::string > m_src_frame_id
yarp::dev::IFrameTransform * m_iTc
std::string m_dst_frame_id
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
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
The Node class.
Definition: Node.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
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
A port specialized for reading data of a constant type published on a topic.
Definition: Subscriber.h:26
Subscriber(const std::string &name="")
Constructor.
Definition: Subscriber.h:35
A class for a Matrix.
Definition: Matrix.h:46
yarp::rosmsg::sensor_msgs::LaserScan LaserScan
Definition: LaserScan.h:24
The main, catch-all namespace for YARP.
Definition: environment.h:18