RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
LidarVLP16.h
1/*
2Copyright (c) 2010-2022, Mathieu Labbe
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the names of its contributors may be used to endorse or promote products
13 derived from this software without specific prior written permission.
14
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
19DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*/
26#ifndef CORELIB_INCLUDE_RTABMAP_CORE_LIDAR_LIDARVLP16_H_
27#define CORELIB_INCLUDE_RTABMAP_CORE_LIDAR_LIDARVLP16_H_
28
29// Should be first on windows to avoid "WinSock.h has already been included" error
30#include <pcl/io/vlp_grabber.h>
31#include <boost/version.hpp>
32#include <boost/asio.hpp>
33
34#include <rtabmap/core/Lidar.h>
35#include <rtabmap/utilite/USemaphore.h>
36
37#include <thread>
38#include <atomic>
39
40// On Apple, closing pcl::HDLGrabber's UDP socket while its read thread is blocked
41// in receive_from returns EBADF, which pcl::HDLGrabber::readPacketsFromSocket()
42// rethrows uncaught in its own thread, aborting the process on shutdown. There we
43// run our own single-threaded UDP receive loop and own the socket lifecycle.
44// Other platforms use the base pcl::VLPGrabber path (which also avoids needing
45// boost::asio::io_context, absent from the Boost 1.65 on e.g. Ubuntu Bionic).
46// Comment this out to force the base path everywhere (e.g. A/B testing on macOS).
47#if defined(__APPLE__)
48#define RTABMAP_VLP16_USE_CUSTOM_SOCKET
49#endif
50
51namespace rtabmap {
52
53struct PointXYZIT {
54 float x;
55 float y;
56 float z;
57 float i;
58 float t;
59};
60
61class RTABMAP_CORE_EXPORT LidarVLP16 :public Lidar, public pcl::VLPGrabber {
62public:
64 const std::string& pcapFile,
65 bool organized = false,
66 bool stampLast = true,
67 float frameRate = 0.0f,
68 Transform localTransform = Transform::getIdentity());
70 const boost::asio::ip::address& ipAddress,
71 const std::uint16_t port = 2368,
72 bool organized = false,
73 bool useHostTime = true,
74 bool stampLast = true,
75 float frameRate = 0.0f,
76 Transform localTransform = Transform::getIdentity());
77 virtual ~LidarVLP16();
78
79 SensorData takeScan(SensorCaptureInfo * info = 0) {return takeData(info);}
80
81 virtual bool init(const std::string & calibrationFolder = ".", const std::string & cameraName = "") override;
82 virtual std::string getSerial() const override {return getName();}
83
84 void setOrganized(bool enable);
85
86#ifdef RTABMAP_VLP16_USE_CUSTOM_SOCKET
87 // Overridden only on Apple: in network mode we run our own UDP receive loop
88 // instead of pcl::HDLGrabber's, because on macOS/BSD closing the grabber's
89 // socket while its read thread is blocked in receive_from returns EBADF, a
90 // code that pcl::HDLGrabber::readPacketsFromSocket() rethrows uncaught (in
91 // its own thread), aborting the process on shutdown. Owning the socket lets
92 // us tear it down with the non-throwing receive_from overload. Like
93 // pcl::HDLGrabber, we bind to the given LOCAL interface address (to scope
94 // reception on a multi-homed host) and fall back to all interfaces (0.0.0.0)
95 // when it is unspecified or not a local address. In PCAP mode we delegate to
96 // the base grabber. On other platforms we inherit pcl::VLPGrabber directly.
97 virtual void start() override;
98 virtual void stop() override;
99 virtual bool isRunning() const override;
100#endif
101
102private:
103 void buildTimings(bool dualMode);
104 virtual void toPointClouds (HDLDataPacket *dataPacket) override;
105#ifdef RTABMAP_VLP16_USE_CUSTOM_SOCKET
106 void readPackets();
107#endif
108
109protected:
110 virtual SensorData captureData(SensorCaptureInfo * info = 0) override;
111
112private:
113 // timing offset lookup table
114 std::vector< std::vector<float> > timingOffsets_;
115 bool timingOffsetsDualMode_;
116 double startSweepTime_;
117 double startSweepTimeHost_;
118 bool organized_;
119 bool useHostTime_;
120 bool stampLast_;
121 SensorData lastScan_;
122 std::vector<std::vector<PointXYZIT> > accumulatedScans_;
123 USemaphore scanReady_;
124 UMutex lastScanMutex_;
125
126 // Own UDP receive path (network mode only).
127 bool networkMode_;
128 boost::asio::ip::address ipAddress_;
129 std::uint16_t port_;
130 bool receivedScan_; // set once the first scan is received
131#ifdef RTABMAP_VLP16_USE_CUSTOM_SOCKET
132 boost::asio::io_context ioContext_;
133 boost::asio::ip::udp::socket * socket_;
134 std::thread * readThread_;
135 std::atomic<bool> terminate_;
136#endif
137};
138
139} /* namespace rtabmap */
140
141#endif /* CORELIB_INCLUDE_RTABMAP_CORE_LIDAR_LIDARVLP16_H_ */
virtual SensorData captureData(SensorCaptureInfo *info=0) override
Pure virtual method to capture sensor data.
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="") override
Initializes the sensor.
virtual std::string getSerial() const override
Returns the sensor's serial number or unique identifier.
Definition LidarVLP16.h:82
Metadata structure for sensor data capture and processing.
Container class for all sensor data captured at a specific time.
Definition SensorData.h:97
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53