tools/LidarViewer/main.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, 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 name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 // Should be first on windows to avoid "WinSock.h has already been included" error
29 #include <pcl/io/hdl_grabber.h>
30 #include <pcl/io/vlp_grabber.h>
31 
32 #include "rtabmap/core/util2d.h"
33 #include "rtabmap/core/util3d.h"
36 #include "rtabmap/utilite/UMath.h"
37 #include "rtabmap/utilite/UFile.h"
40 #include <pcl/visualization/cloud_viewer.h>
41 #include <stdio.h>
42 #include <signal.h>
43 
44 #include <pcl/point_cloud.h>
45 #include <pcl/point_types.h>
46 #include <pcl/common/time.h> //fps calculations
47 #include <pcl/visualization/point_cloud_color_handlers.h>
48 #include <pcl/visualization/cloud_viewer.h>
49 #include <pcl/visualization/image_viewer.h>
50 #include <pcl/console/parse.h>
52 
53 using namespace pcl;
54 using namespace pcl::console;
55 using namespace pcl::visualization;
56 
57 void showUsage()
58 {
59  printf("\nUsage:\n"
60  "rtabmap-lidar_viewer IP PORT driver\n"
61  " driver Driver number to use: 0=VLP16 (default IP and port are 192.168.1.201 2368)\n");
62  exit(1);
63 }
64 
65 // catch ctrl-c
66 bool running = true;
67 void sighandler(int sig)
68 {
69  printf("\nSignal %d caught...\n", sig);
70  running = false;
71 }
72 
73 int main(int argc, char * argv[])
74 {
77  //ULogger::setPrintTime(false);
78  //ULogger::setPrintWhere(false);
79 
80  int driver = 0;
81  std::string ip;
82  int port = 2368;
83  if(argc < 4)
84  {
85  showUsage();
86  }
87  else
88  {
89  ip = argv[1];
90  port = uStr2Int(argv[2]);
91  driver = atoi(argv[3]);
92  if(driver < 0 || driver > 0)
93  {
94  UERROR("driver should be 0.");
95  showUsage();
96  }
97  }
98  printf("Using driver %d (ip=%s port=%d)\n", driver, ip.c_str(), port);
99 
100  rtabmap::LidarVLP16 * lidar = 0;
101  if(driver == 0)
102  {
103  lidar = new rtabmap::LidarVLP16(boost::asio::ip::address_v4::from_string(ip), port);
104  }
105  else
106  {
107  UFATAL("");
108  }
109 
110  if(!lidar->init())
111  {
112  printf("Lidar init failed! Please select another driver (see \"--help\").\n");
113  delete lidar;
114  exit(1);
115  }
116 
117  pcl::visualization::CloudViewer * viewer = new pcl::visualization::CloudViewer("cloud");
118 
119  // to catch the ctrl-c
120  signal(SIGABRT, &sighandler);
121  signal(SIGTERM, &sighandler);
122  signal(SIGINT, &sighandler);
123 
124  rtabmap::SensorData data = lidar->takeScan();
125  while(!data.laserScanRaw().empty() && (viewer==0 || !viewer->wasStopped()) && running)
126  {
127  pcl::PointCloud<pcl::PointXYZI>::Ptr cloud = rtabmap::util3d::laserScanToPointCloudI(data.laserScanRaw(), data.laserScanRaw().localTransform());
128  viewer->showCloud(cloud, "cloud");
129  printf("Scan size: %ld points\n", cloud->size());
130 
131  int c = cv::waitKey(10); // wait 10 ms or for key stroke
132  if(c == 27)
133  break; // if ESC, break and quit
134 
135  data = lidar->takeScan();
136  }
137  printf("Closing...\n");
138  if(viewer)
139  {
140  delete viewer;
141  }
142  delete lidar;
143  return 0;
144 }
rtabmap::SensorData
Definition: SensorData.h:51
pcl
Definition: CameraOpenni.h:47
LidarVLP16.h
c
Scalar Scalar * c
UDirectory.h
ULogger::kTypeConsole
@ kTypeConsole
Definition: ULogger.h:244
ULogger::setLevel
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
rtabmap::LidarVLP16::init
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="") override
Definition: LidarVLP16.cpp:132
pcl::visualization
Definition: CloudViewer.h:65
util3d.h
UMath.h
Basic mathematics functions.
UFATAL
#define UFATAL(...)
rtabmap::LidarVLP16::takeScan
SensorData takeScan(SensorCaptureInfo *info=0)
Definition: LidarVLP16.h:63
data
int data[]
util3d_transforms.h
UConversion.h
Some conversion functions.
showUsage
void showUsage()
Definition: tools/LidarViewer/main.cpp:57
ULogger::kInfo
@ kInfo
Definition: ULogger.h:252
rtabmap_netvlad.argv
argv
Definition: rtabmap_netvlad.py:15
ULogger::setType
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
rtabmap::util3d::laserScanToPointCloudI
pcl::PointCloud< pcl::PointXYZI >::Ptr RTABMAP_CORE_EXPORT laserScanToPointCloudI(const LaserScan &laserScan, const Transform &transform=Transform(), float intensity=0.0f)
Definition: util3d.cpp:2349
rtabmap::LidarVLP16
Definition: LidarVLP16.h:45
ULogger.h
ULogger class and convenient macros.
util2d.h
uStr2Int
int UTILITE_EXPORT uStr2Int(const std::string &str)
Definition: UConversion.cpp:125
running
bool running
Definition: tools/LidarViewer/main.cpp:66
sighandler
void sighandler(int sig)
Definition: tools/LidarViewer/main.cpp:67
main
int main(int argc, char *argv[])
Definition: tools/LidarViewer/main.cpp:73
UFile.h
UERROR
#define UERROR(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:12