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 
87 {
88 protected:
90  std::vector <std::string> m_port_names;
92  std::vector<InputPortProcessor> m_input_ports;
93  std::vector <yarp::os::Stamp> m_last_stamp;
94  std::vector <yarp::dev::LaserScan2D> m_last_scan_data;
97 
98  std::vector <std::string> m_src_frame_id;
99  std::string m_dst_frame_id;
102 
104 
105 public:
106  LaserFromRosTopic(double period = 0.01) : Lidar2DDeviceBase(), PeriodicThread(period)
107  {
110  }
111 
113  {
114  }
115 
116  bool open(yarp::os::Searchable& config) override;
117  bool close() override;
118  bool threadInit() override;
119  void threadRelease() override;
120  void run() override;
121 
122 public:
123  //IRangefinder2D interface
124  bool setDistanceRange (double min, double max) override;
125  bool setScanLimits (double min, double max) override;
126  bool setHorizontalResolution (double step) override;
127  bool setScanRate (double rate) override;
128 };
129 
130 #endif
LaserFromRosTopic::setScanRate
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
Definition: LaserFromRosTopic.cpp:326
LaserFromRosTopic::m_empty_laser_data
yarp::sig::Vector m_empty_laser_data
Definition: LaserFromRosTopic.h:100
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
IRangefinder2D.h
LaserScan.h
Vector.h
contains the definition of a Vector type
Subscriber.h
byte
unsigned char byte
Definition: LaserFromRosTopic.h:46
Lidar2DDeviceBase.h
InputPortProcessor
Definition: AnalogSensorClient.h:30
Port.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
BASE_IS_ZERO
@ BASE_IS_ZERO
Definition: LaserFromRosTopic.h:53
yarp::dev::Lidar2DDeviceBase::Lidar2DDeviceBase
Lidar2DDeviceBase()
Definition: Lidar2DDeviceBase.cpp:96
LaserFromRosTopic::m_iTc
yarp::dev::IFrameTransform * m_iTc
Definition: LaserFromRosTopic.h:96
yarp::os::PeriodicThread::PeriodicThread
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No)
Constructor.
Definition: PeriodicThread.cpp:271
yarp::dev::LaserScan2D
Definition: LaserScan2D.h:28
LaserFromRosTopic::m_base_type
base_enum m_base_type
Definition: LaserFromRosTopic.h:101
LaserFromRosTopic::m_option_override_limits
bool m_option_override_limits
Definition: LaserFromRosTopic.h:89
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
yarpRosHelper.h
yarp::dev::Lidar2DDeviceBase
The DLidarDeviceTemplate class.
Definition: Lidar2DDeviceBase.h:33
InputPortProcessor::InputPortProcessor
InputPortProcessor()
LaserFromRosTopic::m_tc_driver
yarp::dev::PolyDriver m_tc_driver
Definition: LaserFromRosTopic.h:95
yarp::sig::VectorOf< double >
LaserScan2D.h
sensor_msgs::LaserScan
yarp::rosmsg::sensor_msgs::LaserScan LaserScan
Definition: LaserScan.h:24
LaserFromRosTopic::m_src_frame_id
std::vector< std::string > m_src_frame_id
Definition: LaserFromRosTopic.h:98
LaserFromRosTopic::setDistanceRange
bool setDistanceRange(double min, double max) override
set the device detection range.
Definition: LaserFromRosTopic.cpp:302
BASE_IS_INF
@ BASE_IS_INF
Definition: LaserFromRosTopic.h:52
LaserFromRosTopic::close
bool close() override
Close the DeviceDriver.
Definition: LaserFromRosTopic.cpp:286
LaserFromRosTopic::run
void run() override
Loop function.
Definition: LaserFromRosTopic.cpp:418
LaserFromRosTopic::threadRelease
void threadRelease() override
Release method.
Definition: LaserFromRosTopic.cpp:482
PolyDriver.h
Stamp.h
LaserFromRosTopic::m_dst_frame_id
std::string m_dst_frame_id
Definition: LaserFromRosTopic.h:99
LaserFromRosTopic::setHorizontalResolution
bool setHorizontalResolution(double step) override
get the angular step between two measurments (if available)
Definition: LaserFromRosTopic.cpp:319
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
LaserFromRosTopic::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: LaserFromRosTopic.cpp:131
InputPortProcessor::InputPortProcessor
InputPortProcessor(const InputPortProcessor &alt)
Definition: LaserFromRosTopic.h:65
Node.h
InputPortProcessor::getLast
void getLast(yarp::dev::LaserScan2D &data, yarp::os::Stamp &stmp)
yarp::os::Node
The Node class.
Definition: Node.h:27
LaserFromRosTopic::m_port_names
std::vector< std::string > m_port_names
Definition: LaserFromRosTopic.h:90
LaserFromRosTopic::m_last_stamp
std::vector< yarp::os::Stamp > m_last_stamp
Definition: LaserFromRosTopic.h:93
Semaphore.h
BufferedPort.h
LaserFromRosTopic::m_input_ports
std::vector< InputPortProcessor > m_input_ports
Definition: LaserFromRosTopic.h:92
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
LaserFromRosTopic::LaserFromRosTopic
LaserFromRosTopic(double period=0.01)
Definition: LaserFromRosTopic.h:106
PeriodicThread.h
BASE_IS_NAN
@ BASE_IS_NAN
Definition: LaserFromRosTopic.h:51
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
LaserFromRosTopic
laserFromRosTopic: Documentation to be added
Definition: LaserFromRosTopic.h:87
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::Subscriber
A port specialized for reading data of a constant type published on a topic.
Definition: Subscriber.h:26
LaserFromRosTopic::threadInit
bool threadInit() override
Initialization method.
Definition: LaserFromRosTopic.cpp:335
yarp::os::PeriodicThread::step
void step()
Call this to "step" the thread rather than starting it.
Definition: PeriodicThread.cpp:306
yarp::rosmsg::sensor_msgs::LaserScan
Definition: LaserScan.h:59
LaserFromRosTopic::m_ros_node
yarp::os::Node * m_ros_node
Definition: LaserFromRosTopic.h:91
LaserFromRosTopic::m_last_scan_data
std::vector< yarp::dev::LaserScan2D > m_last_scan_data
Definition: LaserFromRosTopic.h:94
sensor_msgs
Definition: BatteryState.h:22
LaserFromRosTopic::setScanLimits
bool setScanLimits(double min, double max) override
set the scan angular range.
Definition: LaserFromRosTopic.cpp:310
base_enum
base_enum
Definition: laserFromExternalPort.h:43
IFrameTransform.h
LaserFromRosTopic::~LaserFromRosTopic
~LaserFromRosTopic()
Definition: LaserFromRosTopic.h:112
LaserFromRosTopic::calculate
void calculate(yarp::dev::LaserScan2D scan, yarp::sig::Matrix m)
Definition: LaserFromRosTopic.cpp:345
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46