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 
96  CameraStereoImages camera(
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 
113  SensorData data = camera.takeImage();
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  {
121  OdometryInfo info;
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 }
bool isPaused() const
void processStatistics(const rtabmap::Statistics &stats)
void processOdometry(const SensorData &data, Transform pose, const rtabmap::OdometryInfo &odom)
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")
void init(const ParametersMap &parameters, const std::string &databasePath="", bool loadDatabaseParameters=false)
Definition: Rtabmap.cpp:292
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
int main(int argc, char *argv[])
Transform process(SensorData &data, OdometryInfo *info=0)
Definition: Odometry.cpp:278
bool isValid() const
Definition: SensorData.h:137
SensorData takeImage(CameraInfo *info=0)
Definition: Camera.cpp:72
static Odometry * create(const ParametersMap &parameters=ParametersMap())
Definition: Odometry.cpp:54
int getLoopClosureId() const
Definition: Rtabmap.h:127
const Statistics & getStatistics() const
Definition: Rtabmap.cpp:699
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
bool process(const SensorData &data, Transform odomPose, const cv::Mat &odomCovariance=cv::Mat::eye(6, 6, CV_64FC1), const std::vector< float > &odomVelocity=std::vector< float >(), const std::map< std::string, float > &externalStats=std::map< std::string, float >())
Main loop of rtabmap.
Definition: Rtabmap.cpp:992
void uSleep(unsigned int ms)
QApplication * app
#define UERROR(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:59