examples/NoEventsExample/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 #include <rtabmap/core/Rtabmap.h>
31 #include "MapBuilder.h"
32 #include <pcl/visualization/cloud_viewer.h>
33 #include <rtabmap/core/Odometry.h>
34 #include <QApplication>
35 #include <stdio.h>
36 
37 using namespace rtabmap;
38 
39 void showUsage()
40 {
41  printf("\nUsage:\n"
42  "rtabmap-noEventsExample camera_rate odom_update map_update calibration_dir calibration_name path_left_images path_right_images\n"
43  "Description:\n"
44  " camera_rate Rate (Hz) of the camera.\n"
45  " odom_update Do odometry update each X camera frames.\n"
46  " map_update Do map update each X odometry frames.\n"
47  "\n"
48  "Example:\n"
49  " (with images from \"https://github.com/introlab/rtabmap/wiki/Stereo-mapping#process-a-directory-of-stereo-images\") \n"
50  " $ rtabmap-noEventsExample 20 2 10 stereo_20Hz stereo_20Hz stereo_20Hz/left stereo_20Hz/right\n"
51  " Camera rate = 20 Hz\n"
52  " Odometry update rate = 10 Hz\n"
53  " Map update rate = 1 Hz\n");
54  exit(1);
55 }
56 
57 int main(int argc, char * argv[])
58 {
61 
62  if(argc < 8)
63  {
64  showUsage();
65  }
66 
67  int argIndex = 1;
68  int cameraRate = atoi(argv[argIndex++]);
69  if(cameraRate <= 0)
70  {
71  printf("camera_rate should be > 0\n");
72  showUsage();
73  }
74  int odomUpdate = atoi(argv[argIndex++]);
75  if(odomUpdate <= 0)
76  {
77  printf("odom_update should be > 0\n");
78  showUsage();
79  }
80  int mapUpdate = atoi(argv[argIndex++]);
81  if(mapUpdate <= 0)
82  {
83  printf("map_update should be > 0\n");
84  showUsage();
85  }
86 
87  printf("Camera rate = %d Hz\n", cameraRate);
88  printf("Odometry update rate = %d Hz\n", cameraRate/odomUpdate);
89  printf("Map update rate = %d Hz\n", (cameraRate/odomUpdate)/mapUpdate);
90 
91  std::string calibrationDir = argv[argIndex++];
92  std::string calibrationName = argv[argIndex++];
93  std::string pathLeftImages = argv[argIndex++];
94  std::string pathRightImages = argv[argIndex++];
95 
97  pathLeftImages,
98  pathRightImages,
99  false, // assume that images are already rectified
100  (float)cameraRate);
101 
102  if(camera.init(calibrationDir, calibrationName))
103  {
104  Odometry * odom = Odometry::create();
106  rtabmap.init();
107 
108  QApplication app(argc, argv);
109  MapBuilder mapBuilder;
110  mapBuilder.show();
111  QApplication::processEvents();
112 
114  int cameraIteration = 0;
115  int odometryIteration = 0;
116  printf("Press \"Space\" in the window to pause\n");
117  while(data.isValid() && mapBuilder.isVisible())
118  {
119  if(cameraIteration++ % odomUpdate == 0)
120  {
122  Transform pose = odom->process(data, &info);
123 
124  if(odometryIteration++ % mapUpdate == 0)
125  {
126  if(rtabmap.process(data, pose))
127  {
128  mapBuilder.processStatistics(rtabmap.getStatistics());
129  if(rtabmap.getLoopClosureId() > 0)
130  {
131  printf("Loop closure detected!\n");
132  }
133  }
134  }
135 
136  mapBuilder.processOdometry(data, pose, info);
137  }
138 
139  QApplication::processEvents();
140 
141  while(mapBuilder.isPaused() && mapBuilder.isVisible())
142  {
143  uSleep(100);
144  QApplication::processEvents();
145  }
146 
147  data = camera.takeImage();
148  }
149  delete odom;
150 
151  if(mapBuilder.isVisible())
152  {
153  printf("Processed all frames\n");
154  app.exec();
155  }
156  }
157  else
158  {
159  UERROR("Camera init failed!");
160  }
161 
162  return 0;
163 }
rtabmap::SensorData
Definition: SensorData.h:51
rtabmap::Odometry::create
static Odometry * create(const ParametersMap &parameters=ParametersMap())
Definition: Odometry.cpp:58
ULogger::kError
@ kError
Definition: ULogger.h:252
ULogger::kTypeConsole
@ kTypeConsole
Definition: ULogger.h:244
showUsage
void showUsage()
Definition: examples/NoEventsExample/main.cpp:39
MapBuilder::processOdometry
virtual void processOdometry(const rtabmap::OdometryEvent &odom)
Definition: LidarMapping/MapBuilder.h:129
ULogger::setLevel
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
CameraStereo.h
Odometry.h
rtabmap::SensorCapture::init
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
MapBuilder::processStatistics
virtual void processStatistics(const rtabmap::Statistics &stats)
Definition: LidarMapping/MapBuilder.h:201
app
QApplication * app
Definition: tools/DataRecorder/main.cpp:59
data
int data[]
rtabmap::CameraStereoImages
Definition: CameraStereoImages.h:39
main
int main(int argc, char *argv[])
Definition: examples/NoEventsExample/main.cpp:57
Rtabmap.h
rtabmap::Odometry::process
Transform process(SensorData &data, OdometryInfo *info=0)
Definition: Odometry.cpp:298
info
else if n * info
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::Transform
Definition: Transform.h:41
camera
Camera camera(Pose3(Rot3().retract(Vector3(0.1, 0.2, 0.3)), Point3(0, 5, 0)), Cal3Bundler0(1, 0, 0))
UThread.h
uSleep
void uSleep(unsigned int ms)
Definition: Posix/UThreadC.h:23
rtabmap::Odometry
Definition: Odometry.h:42
rtabmap::OdometryInfo
Definition: OdometryInfo.h:40
rtabmap::Rtabmap
Definition: Rtabmap.h:54
rtabmap
Definition: CameraARCore.cpp:35
UERROR
#define UERROR(...)
rtabmap::Camera::takeImage
SensorData takeImage(SensorCaptureInfo *info=0)
Definition: Camera.h:48
MapBuilder
Definition: LidarMapping/MapBuilder.h:52
MapBuilder::isPaused
bool isPaused() const
Definition: NoEventsExample/MapBuilder.h:81
MapBuilder.h


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