YARP
Yet Another Robot Platform
Rangefinder2DWrapper.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #ifndef YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
7 #define YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
8 
9  //#include <list>
10 #include <vector>
11 #include <iostream>
12 #include <string>
13 #include <sstream>
14 
15 #include <yarp/os/Network.h>
16 #include <yarp/os/Port.h>
17 #include <yarp/os/BufferedPort.h>
18 #include <yarp/os/Bottle.h>
19 #include <yarp/os/Time.h>
20 #include <yarp/os/Property.h>
21 
22 #include <yarp/os/PeriodicThread.h>
23 #include <yarp/os/BufferedPort.h>
24 #include <yarp/os/Stamp.h>
25 
26 #include <yarp/sig/Vector.h>
27 
28 #include <yarp/dev/LaserScan2D.h>
30 #include <yarp/dev/PolyDriver.h>
31 #include <yarp/dev/DeviceDriver.h>
33 #include <yarp/dev/api.h>
35 
36 // ROS state publisher
37 #include <yarp/os/Node.h>
38 #include <yarp/os/Publisher.h>
41 
42 
43 #define DEFAULT_THREAD_PERIOD 0.02 //s
44 
55 {
56 public:
59 
60  bool open(yarp::os::Searchable &params) override;
61  bool close() override;
63 
64  void setId(const std::string &id);
65  std::string getId();
66 
70  bool attachAll(const yarp::dev::PolyDriverList &p) override;
71  bool detachAll() override;
72 
74  void detach();
75 
76  bool threadInit() override;
77  void threadRelease() override;
78  void run() override;
79 
80 private:
81  yarp::dev::PolyDriver driver;
82  std::string partName;
83  std::string streamingPortName;
84  std::string rpcPortName;
85  yarp::os::Port rpcPort;
89  yarp::os::Stamp lastStateStamp;
90  double _period;
91  std::string sensorId;
92  double minAngle, maxAngle;
93  double minDistance, maxDistance;
94  double resolution;
95  bool isDeviceOwned;
96 
97  bool checkROSParams(yarp::os::Searchable &config);
98  bool initialize_ROS();
99  bool initialize_YARP(yarp::os::Searchable &config);
100  bool read(yarp::os::ConnectionReader& connection) override;
101 
102  // ROS data
103  ROSTopicUsageType useROS; // decide if open ROS topic or not
104  std::string frame_id; // name of the frame measures are referred to
105  std::string rosNodeName; // name of the rosNode
106  std::string rosTopicName; // name of the rosTopic
107  yarp::os::Node *rosNode; // add a ROS node
108  yarp::os::NetUint32 rosMsgCounter; // incremental counter in the ROS message
109  yarp::os::Publisher<yarp::rosmsg::sensor_msgs::LaserScan> rosPublisherPort; // Dedicated ROS topic publisher
110 };
111 
112 #endif // YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
contains the definition of a Vector type
Rangefinder2DWrapper deprecated: Documentation to be added
bool detachAll() override
Detach the object (you must have first called attach).
bool close() override
Close the DeviceDriver.
void setId(const std::string &id)
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
bool threadInit() override
Initialization method.
void attach(yarp::dev::IRangefinder2D *s)
void threadRelease() override
Release method.
yarp::os::Bottle getOptions()
Rangefinder2DWrapper()
It reads the data from a rangefinder sensor and sends them on one port.
void run() override
Loop function.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
Interface for an object that can wrap/attach to to another.
A generic interface for planar laser range finders.
A container for a device driver.
Definition: PolyDriver.h:24
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
An interface for reading from a network connection.
The Node class.
Definition: Node.h:24
An abstraction for a periodic thread.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
A mini-server for network communication.
Definition: Port.h:47
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:30
ROSTopicUsageType
Definition: yarpRosHelper.h:16