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 
63 {
64 public:
67 
68  bool open(yarp::os::Searchable &params) override;
69  bool close() override;
71 
72  void setId(const std::string &id);
73  std::string getId();
74 
78  bool attachAll(const yarp::dev::PolyDriverList &p) override;
79  bool detachAll() override;
80 
82  void detach();
83 
84  bool threadInit() override;
85  void threadRelease() override;
86  void run() override;
87 
88 private:
89  yarp::dev::PolyDriver driver;
90  std::string partName;
91  std::string streamingPortName;
92  std::string rpcPortName;
93  yarp::os::Port rpcPort;
97  yarp::os::Stamp lastStateStamp;
98  double _period;
99  std::string sensorId;
100  double minAngle, maxAngle;
101  double minDistance, maxDistance;
102  double resolution;
103  bool isDeviceOwned;
104 
105  bool checkROSParams(yarp::os::Searchable &config);
106  bool initialize_ROS();
107  bool initialize_YARP(yarp::os::Searchable &config);
108  bool read(yarp::os::ConnectionReader& connection) override;
109 
110  // ROS data
111  ROSTopicUsageType useROS; // decide if open ROS topic or not
112  std::string frame_id; // name of the frame measures are referred to
113  std::string rosNodeName; // name of the rosNode
114  std::string rosTopicName; // name of the rosTopic
115  yarp::os::Node *rosNode; // add a ROS node
116  yarp::os::NetUint32 rosMsgCounter; // incremental counter in the ROS message
117  yarp::os::Publisher<yarp::rosmsg::sensor_msgs::LaserScan> rosPublisherPort; // Dedicated ROS topic publisher
118 };
119 
120 #endif // YARP_DEV_RANGEFINDER2DWRAPPER_RANGEFINDER2DWRAPPER_H
contains the definition of a Vector type
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:38
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:27
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
An interface for reading from a network connection.
The Node class.
Definition: Node.h:27
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:28
A mini-server for network communication.
Definition: Port.h:50
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
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
ROSTopicUsageType
Definition: yarpRosHelper.h:19