examples/WifiMapping/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/Odometry.h>
29 #include "rtabmap/core/Rtabmap.h"
36 #include <QApplication>
37 #include <stdio.h>
38 
39 #include "MapBuilderWifi.h"
40 
41 #include "WifiThread.h"
42 
43 void showUsage()
44 {
45  printf("\nUsage:\n"
46  "rtabmap-wifi_mapping [options]\n"
47  "Options:\n"
48  " -i \"name\" Wifi interface name (e.g. \"eth0\"). Only required on Linux.\n"
49  " -m Enable mirroring of the camera image.\n"
50  " -d # Driver number to use: 0=OpenNI-PCL, 1=OpenNI2, 2=Freenect, 3=OpenNI-CV, 4=OpenNI-CV-ASUS, 5=Freenect2, 6=ZED SDK, 7=RealSense, 8=RealSense2 9=Kinect for Azure SDK 10=MYNT EYE S\n\n");
51  exit(1);
52 }
53 
54 using namespace rtabmap;
55 int main(int argc, char * argv[])
56 {
59 
60  std::string interfaceName = "wlan0";
61  int driver = 0;
62  bool mirroring = false;
63 
64  // parse options
65  for(int i = 1; i<argc; ++i)
66  {
67  if(strcmp(argv[i], "-i") == 0)
68  {
69  ++i;
70  if(i < argc)
71  {
72  interfaceName = argv[i];
73  }
74  else
75  {
76  showUsage();
77  }
78  continue;
79  }
80  if(strcmp(argv[i], "-m") == 0)
81  {
82  mirroring = true;
83  continue;
84  }
85  if(strcmp(argv[i], "-d") == 0)
86  {
87  ++i;
88  if(i < argc)
89  {
90  driver = atoi(argv[i]);
91  if(driver < 0 || driver > 8)
92  {
93  UERROR("driver should be between 0 and 8.");
94  showUsage();
95  }
96  }
97  else
98  {
99  showUsage();
100  }
101  continue;
102  }
103 
104  UERROR("Option \"%s\" not recognized!", argv[i]);
105  showUsage();
106  }
107 
108  // Here is the pipeline that we will use:
109  // CameraOpenni -> "CameraEvent" -> OdometryThread -> "OdometryEvent" -> RtabmapThread -> "RtabmapEvent"
110 
111  // Create the OpenNI camera, it will send a CameraEvent at the rate specified.
112  // Set transform to camera so z is up, y is left and x going forward
113  Camera * camera = 0;
114  Transform opticalRotation(0,0,1,0, -1,0,0,0, 0,-1,0,0);
115  if(driver == 1)
116  {
118  {
119  UERROR("Not built with OpenNI2 support...");
120  exit(-1);
121  }
122  camera = new CameraOpenNI2("", CameraOpenNI2::kTypeColorDepth, 0, opticalRotation);
123  }
124  else if(driver == 2)
125  {
127  {
128  UERROR("Not built with Freenect support...");
129  exit(-1);
130  }
131  camera = new CameraFreenect(0, CameraFreenect::kTypeColorDepth, 0, opticalRotation);
132  }
133  else if(driver == 3)
134  {
136  {
137  UERROR("Not built with OpenNI from OpenCV support...");
138  exit(-1);
139  }
140  camera = new CameraOpenNICV(false, 0, opticalRotation);
141  }
142  else if(driver == 4)
143  {
145  {
146  UERROR("Not built with OpenNI from OpenCV support...");
147  exit(-1);
148  }
149  camera = new CameraOpenNICV(true, 0, opticalRotation);
150  }
151  else if (driver == 5)
152  {
154  {
155  UERROR("Not built with Freenect2 support...");
156  exit(-1);
157  }
158  camera = new CameraFreenect2(0, CameraFreenect2::kTypeColor2DepthSD, 0, opticalRotation);
159  }
160  else if (driver == 6)
161  {
163  {
164  UERROR("Not built with ZED SDK support...");
165  exit(-1);
166  }
167  camera = new CameraStereoZed(0, 2, 1, 1, 100, false, 0, opticalRotation);
168  }
169  else if (driver == 7)
170  {
172  {
173  UERROR("Not built with RealSense support...");
174  exit(-1);
175  }
176  camera = new CameraRealSense(0, 0, 0, false, 0, opticalRotation);
177  }
178  else if (driver == 8)
179  {
181  {
182  UERROR("Not built with RealSense2 support...");
183  exit(-1);
184  }
185  camera = new CameraRealSense2("", 0, opticalRotation);
186  }
187  else if (driver == 9)
188  {
190  {
191  UERROR("Not built with Kinect for Azure SDK support...");
192  exit(-1);
193  }
194  camera = new rtabmap::CameraK4A(1);
195  }
196  else if (driver == 10)
197  {
199  {
200  UERROR("Not built with Mynt Eye S support...");
201  exit(-1);
202  }
203  camera = new rtabmap::CameraMyntEye();
204  }
205  else
206  {
207  camera = new rtabmap::CameraOpenni("", 0, opticalRotation);
208  }
209 
210 
211  if(!camera->init())
212  {
213  UERROR("Camera init failed! Try another camera driver.");
214  showUsage();
215  exit(1);
216  }
217  CameraThread cameraThread(camera);
218  if(mirroring)
219  {
220  cameraThread.setMirroringEnabled(true);
221  }
222 
223  // GUI stuff, there the handler will receive RtabmapEvent and construct the map
224  // We give it the camera so the GUI can pause/resume the camera
225  QApplication app(argc, argv);
226  MapBuilderWifi mapBuilderWifi(&cameraThread);
227 
228  // Create an odometry thread to process camera events, it will send OdometryEvent.
229  OdometryThread odomThread(Odometry::create());
230 
231  // Create RTAB-Map to process OdometryEvent
232  Rtabmap * rtabmap = new Rtabmap();
233  ParametersMap param;
234  param.insert(ParametersPair(Parameters::kMemRehearsalSimilarity(), "1.0")); // disable rehearsal (node merging when not moving)
235  param.insert(ParametersPair(Parameters::kRGBDLinearUpdate(), "0")); // disable node ignored when not moving
236  param.insert(ParametersPair(Parameters::kRGBDAngularUpdate(), "0")); // disable node ignored when not moving
237  rtabmap->init(param);
238  RtabmapThread rtabmapThread(rtabmap); // ownership is transfered
239 
240  // Create Wifi monitoring thread
241  WifiThread wifiThread(interfaceName); // 0.5 Hz, should be under RTAB-Map rate (which is 1 Hz by default)
242 
243  // Setup handlers
244  odomThread.registerToEventsManager();
245  rtabmapThread.registerToEventsManager();
246  mapBuilderWifi.registerToEventsManager();
247 
248  // The RTAB-Map is subscribed by default to CameraEvent, but we want
249  // RTAB-Map to process OdometryEvent instead, ignoring the CameraEvent.
250  // We can do that by creating a "pipe" between the camera and odometry, then
251  // only the odometry will receive CameraEvent from that camera. RTAB-Map is
252  // also subscribed to OdometryEvent by default, so no need to create a pipe between
253  // odometry and RTAB-Map.
254  UEventsManager::createPipe(&cameraThread, &odomThread, "CameraEvent");
255 
256  // Let's start the threads
257  rtabmapThread.start();
258  odomThread.start();
259  cameraThread.start();
260  wifiThread.start();
261 
262  mapBuilderWifi.show();
263  app.exec(); // main loop
264 
265  // remove handlers
266  mapBuilderWifi.unregisterFromEventsManager();
267  rtabmapThread.unregisterFromEventsManager();
268  odomThread.unregisterFromEventsManager();
269 
270  // Kill all threads
271  cameraThread.kill();
272  odomThread.join(true);
273  rtabmapThread.join(true);
274  wifiThread.join(true);
275 
276  return 0;
277 }
static void createPipe(const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName)
void start()
Definition: UThread.cpp:122
std::pair< std::string, std::string > ParametersPair
Definition: Parameters.h:44
void kill()
Definition: UThread.cpp:48
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
int main(int argc, char *argv[])
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
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
static Odometry * create(const ParametersMap &parameters=ParametersMap())
Definition: Odometry.cpp:54
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
void showUsage()
void setMirroringEnabled(bool enabled)
Definition: CameraThread.h:63
void registerToEventsManager()
QApplication * app
#define UERROR(...)
static bool available()
Definition: CameraK4A.cpp:42
void unregisterFromEventsManager()
void join(bool killFirst=false)
Definition: UThread.cpp:85


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