YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
LaserFromRosTopic.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#ifndef LASER_FROM_ROS_TOPIC_H
7#define LASER_FROM_ROS_TOPIC_H
8
10#include <yarp/os/Semaphore.h>
11#include <yarp/os/Port.h>
12#include <yarp/os/Subscriber.h>
14#include <yarp/os/Stamp.h>
18#include <yarp/sig/Vector.h>
20#include <yarp/dev/PolyDriver.h>
21
22 // ROS state publisher
23#include <yarp/os/Node.h>
24#include <yarp/os/Subscriber.h>
25#include <yarp/rosmsg/sensor_msgs/LaserScan.h>
26#include <yarp/rosmsg/impl/yarpRosHelper.h>
27
28#include <mutex>
29#include <string>
30#include <vector>
31
32// Compatibility with both YARP 3.9 and 3.10
33// See https://github.com/robotology/yarp/pull/3130
34#if __has_include (<yarp/dev/LaserScan2D.h>)
35
36// YARP 3.9 case
38
39namespace yarp {
40namespace sig {
41typedef yarp::dev::LaserScan2D LaserScan2D;
42}
43}
44
45#else
46
47// YARP 3.10 case
49
50#endif
51
52
53typedef unsigned char byte;
54
55//---------------------------------------------------------------------------------------------------------------
62
64 public yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>
65{
66 std::mutex m_port_mutex;
67 yarp::sig::LaserScan2D m_lastScan;
68 yarp::os::Stamp m_lastStamp;
69 bool m_contains_data;
70
71public:
73 yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>(),
74 m_lastScan(alt.m_lastScan),
75 m_lastStamp(alt.m_lastStamp),
76 m_contains_data(alt.m_contains_data)
77 {
78 }
79
81 using yarp::os::Subscriber<yarp::rosmsg::sensor_msgs::LaserScan>::onRead;
82 virtual void onRead(yarp::rosmsg::sensor_msgs::LaserScan& v) override;
84};
85
94{
95protected:
97 std::vector <std::string> m_port_names;
99 std::vector<InputPortProcessor> m_input_ports;
100 std::vector <yarp::os::Stamp> m_last_stamp;
101 std::vector <yarp::sig::LaserScan2D> m_last_scan_data;
104
105 std::vector <std::string> m_src_frame_id;
106 std::string m_dst_frame_id;
109
111
112public:
118
120 {
121 }
122
123 bool open(yarp::os::Searchable& config) override;
124 bool close() override;
125 bool threadInit() override;
126 void threadRelease() override;
127 void run() override;
128
129public:
130 //IRangefinder2D interface
131 bool setDistanceRange (double min, double max) override;
132 bool setScanLimits (double min, double max) override;
133 bool setHorizontalResolution (double step) override;
134 bool setScanRate (double rate) override;
135
136public:
137 //Lidar2DDeviceBase
138 bool acquireDataFromHW() override final;
139};
140
141#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 getLast(yarp::sig::LaserScan2D &data, yarp::os::Stamp &stmp)
virtual void onRead(yarp::rosmsg::sensor_msgs::LaserScan &v) override
laserFromRosTopic: Documentation to be added
void calculate(yarp::sig::LaserScan2D scan, yarp::sig::Matrix m)
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
std::vector< std::string > m_port_names
bool setHorizontalResolution(double step) override
get the angular step between two measurements (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
bool acquireDataFromHW() override final
This method should be implemented by the user, and contain the logic to grab data from the hardware.
std::vector< yarp::sig::LaserScan2D > m_last_scan_data
void threadRelease() override
Release method.
std::vector< std::string > m_src_frame_id
yarp::dev::IFrameTransform * m_iTc
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
Interface implemented by all device drivers.
Transform Interface.
The Lidar2DDeviceBase class.
A container for a device driver.
Definition PolyDriver.h:23
The Node class.
Definition Node.h:23
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:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
A port specialized for reading data of a constant type published on a topic.
Definition Subscriber.h:22
Subscriber(const std::string &name="")
Constructor.
Definition Subscriber.h:31
A class for a Matrix.
Definition Matrix.h:39
The main, catch-all namespace for YARP.
Definition dirs.h:16