YARP
Yet Another Robot Platform
Rangefinder2DWrapper.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 YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
20 #define YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
21 
22  //#include <list>
23 #include <vector>
24 #include <iostream>
25 #include <string>
26 #include <sstream>
27 
28 #include <yarp/os/Network.h>
29 #include <yarp/os/Port.h>
30 #include <yarp/os/BufferedPort.h>
31 #include <yarp/os/Bottle.h>
32 #include <yarp/os/Time.h>
33 #include <yarp/os/Property.h>
34 
35 #include <yarp/os/PeriodicThread.h>
36 #include <yarp/os/BufferedPort.h>
37 #include <yarp/os/Stamp.h>
38 
39 #include <yarp/sig/Vector.h>
40 
41 #include <yarp/dev/LaserScan2D.h>
43 #include <yarp/dev/PolyDriver.h>
44 #include <yarp/dev/DeviceDriver.h>
46 #include <yarp/dev/api.h>
48 
49 // ROS state publisher
50 #include <yarp/os/Node.h>
51 #include <yarp/os/Publisher.h>
54 
55 
56 #define DEFAULT_THREAD_PERIOD 0.02 //s
57 
68 {
69 public:
72 
73  bool open(yarp::os::Searchable &params) override;
74  bool close() override;
76 
77  void setId(const std::string &id);
78  std::string getId();
79 
83  bool attachAll(const yarp::dev::PolyDriverList &p) override;
84  bool detachAll() override;
85 
87  void detach();
88 
89  bool threadInit() override;
90  void threadRelease() override;
91  void run() override;
92 
93 private:
94  yarp::dev::PolyDriver driver;
95  std::string partName;
96  std::string streamingPortName;
97  std::string rpcPortName;
98  yarp::os::Port rpcPort;
102  yarp::os::Stamp lastStateStamp;
103  double _period;
104  std::string sensorId;
105  double minAngle, maxAngle;
106  double minDistance, maxDistance;
107  double resolution;
108  bool isDeviceOwned;
109 
110  bool checkROSParams(yarp::os::Searchable &config);
111  bool initialize_ROS();
112  bool initialize_YARP(yarp::os::Searchable &config);
113  bool read(yarp::os::ConnectionReader& connection) override;
114 
115  // ROS data
116  ROSTopicUsageType useROS; // decide if open ROS topic or not
117  std::string frame_id; // name of the frame measures are referred to
118  std::string rosNodeName; // name of the rosNode
119  std::string rosTopicName; // name of the rosTopic
120  yarp::os::Node *rosNode; // add a ROS node
121  yarp::os::NetUint32 rosMsgCounter; // incremental counter in the ROS message
122  yarp::os::Publisher<yarp::rosmsg::sensor_msgs::LaserScan> rosPublisherPort; // Dedicated ROS topic publisher
123 };
124 
125 #endif // YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Network.h
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
Rangefinder2DWrapper::detachAll
bool detachAll() override
Detach the object (you must have first called attach).
Definition: Rangefinder2DWrapper.cpp:245
Port.h
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Rangefinder2DWrapper::getId
std::string getId()
Definition: Rangefinder2DWrapper.cpp:464
Rangefinder2DWrapper::getOptions
yarp::os::Bottle getOptions()
yarp::dev::IRangefinder2D
A generic interface for planar laser range finders.
Definition: IRangefinder2D.h:38
Rangefinder2DWrapper::open
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Definition: Rangefinder2DWrapper.cpp:470
yarp::os::Publisher< yarp::rosmsg::sensor_msgs::LaserScan >
yarp::dev::PolyDriverList
Definition: PolyDriverList.h:22
yarpRosHelper.h
Rangefinder2DWrapper::attach
void attach(yarp::dev::IRangefinder2D *s)
Definition: Rangefinder2DWrapper.cpp:255
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort< yarp::dev::LaserScan2D >
LaserScan2D.h
Rangefinder2DWrapper::~Rangefinder2DWrapper
~Rangefinder2DWrapper()
Definition: Rangefinder2DWrapper.cpp:61
Rangefinder2DWrapper::detach
void detach()
Definition: Rangefinder2DWrapper.cpp:260
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
Property.h
ROSTopicUsageType
ROSTopicUsageType
Definition: yarpRosHelper.h:19
PolyDriver.h
Rangefinder2DWrapper::setId
void setId(const std::string &id)
Definition: Rangefinder2DWrapper.cpp:459
yarp::os::NetUint32
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
Stamp.h
Rangefinder2DWrapper::attachAll
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
Definition: Rangefinder2DWrapper.cpp:200
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
Node.h
yarp::os::Node
The Node class.
Definition: Node.h:27
Rangefinder2DWrapper::Rangefinder2DWrapper
Rangefinder2DWrapper()
It reads the data from a rangefinder sensor and sends them on one port.
Definition: Rangefinder2DWrapper.cpp:41
BufferedPort.h
IMultipleWrapper.h
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
PeriodicThread.h
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
Rangefinder2DWrapper::threadInit
bool threadInit() override
Initialization method.
Definition: Rangefinder2DWrapper.cpp:454
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
Rangefinder2DWrapper::close
bool close() override
Close the DeviceDriver.
Definition: Rangefinder2DWrapper.cpp:635
Publisher.h
yarp::dev::IMultipleWrapper
Interface for an object that can wrap/attach to to another.
Definition: IMultipleWrapper.h:30
Rangefinder2DWrapper::threadRelease
void threadRelease() override
Release method.
Definition: Rangefinder2DWrapper.cpp:554
Time.h
Rangefinder2DWrapper
Rangefinder2DWrapper: Documentation to be added
Definition: Rangefinder2DWrapper.h:68
api.h
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
Bottle.h
Rangefinder2DWrapper::run
void run() override
Loop function.
Definition: Rangefinder2DWrapper.cpp:562
DeviceDriver.h