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>
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  Transform opticalRotation(0,0,1,0, -1,0,0,0, 0,-1,0,0);
97  CameraStereoImages camera(
98  pathLeftImages,
99  pathRightImages,
100  false, // assume that images are already rectified
101  (float)cameraRate,
102  opticalRotation);
103 
104  if(camera.init(calibrationDir, calibrationName))
105  {
106  OdometryF2M odom;
108  rtabmap.init();
109 
110  QApplication app(argc, argv);
111  MapBuilder mapBuilder;
112  mapBuilder.show();
113  QApplication::processEvents();
114 
115  SensorData data = camera.takeImage();
116  int cameraIteration = 0;
117  int odometryIteration = 0;
118  printf("Press \"Space\" in the window to pause\n");
119  while(data.isValid() && mapBuilder.isVisible())
120  {
121  if(cameraIteration++ % odomUpdate == 0)
122  {
123  OdometryInfo info;
124  Transform pose = odom.process(data, &info);
125 
126  if(odometryIteration++ % mapUpdate == 0)
127  {
128  if(rtabmap.process(data, pose))
129  {
130  mapBuilder.processStatistics(rtabmap.getStatistics());
131  if(rtabmap.getLoopClosureId() > 0)
132  {
133  printf("Loop closure detected!\n");
134  }
135  }
136  }
137 
138  mapBuilder.processOdometry(data, pose, info);
139  }
140 
141  QApplication::processEvents();
142 
143  while(mapBuilder.isPaused() && mapBuilder.isVisible())
144  {
145  uSleep(100);
146  QApplication::processEvents();
147  }
148 
149  data = camera.takeImage();
150  }
151 
152  if(mapBuilder.isVisible())
153  {
154  printf("Processed all frames\n");
155  app.exec();
156  }
157  }
158  else
159  {
160  UERROR("Camera init failed!");
161  }
162 
163  return 0;
164 }
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="")
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
static rtabmap::Transform opticalRotation(1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,-1.0f, 0.0f)
int main(int argc, char *argv[])
Transform process(SensorData &data, OdometryInfo *info=0)
Definition: Odometry.cpp:235
bool isValid() const
Definition: SensorData.h:134
SensorData takeImage(CameraInfo *info=0)
Definition: Camera.cpp:67
int getLoopClosureId() const
Definition: Rtabmap.h:103
const Statistics & getStatistics() const
Definition: Rtabmap.cpp:631
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:897
static RTABMapApp app
void init(const ParametersMap &parameters, const std::string &databasePath="")
Definition: Rtabmap.cpp:282
void uSleep(unsigned int ms)
#define UERROR(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31