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 
29 #include "rtabmap/core/Rtabmap.h"
35 #include <QApplication>
36 #include <stdio.h>
37 
38 #include "MapBuilderWifi.h"
39 
40 #include "WifiThread.h"
41 
42 void showUsage()
43 {
44  printf("\nUsage:\n"
45  "rtabmap-wifi_mapping [options]\n"
46  "Options:\n"
47  " -i \"name\" Wifi interface name (e.g. \"eth0\"). Only required on Linux.\n"
48  " -m Enable mirroring of the camera image.\n"
49  " -d # Driver number to use: 0=OpenNI-PCL, 1=OpenNI2, 2=Freenect, 3=OpenNI-CV, 4=OpenNI-CV-ASUS\n\n");
50  exit(1);
51 }
52 
53 using namespace rtabmap;
54 int main(int argc, char * argv[])
55 {
58 
59  std::string interfaceName = "wlan0";
60  int driver = 0;
61  bool mirroring = false;
62 
63  // parse options
64  for(int i = 1; i<argc; ++i)
65  {
66  if(strcmp(argv[i], "-i") == 0)
67  {
68  ++i;
69  if(i < argc)
70  {
71  interfaceName = argv[i];
72  }
73  else
74  {
75  showUsage();
76  }
77  continue;
78  }
79  if(strcmp(argv[i], "-m") == 0)
80  {
81  mirroring = true;
82  continue;
83  }
84  if(strcmp(argv[i], "-d") == 0)
85  {
86  ++i;
87  if(i < argc)
88  {
89  driver = atoi(argv[i]);
90  if(driver < 0 || driver > 4)
91  {
92  UERROR("driver should be between 0 and 4.");
93  showUsage();
94  }
95  }
96  else
97  {
98  showUsage();
99  }
100  continue;
101  }
102 
103  UERROR("Option \"%s\" not recognized!", argv[i]);
104  showUsage();
105  }
106 
107  // Here is the pipeline that we will use:
108  // CameraOpenni -> "CameraEvent" -> OdometryThread -> "OdometryEvent" -> RtabmapThread -> "RtabmapEvent"
109 
110  // Create the OpenNI camera, it will send a CameraEvent at the rate specified.
111  // Set transform to camera so z is up, y is left and x going forward
112  Camera * camera = 0;
113  Transform opticalRotation(0,0,1,0, -1,0,0,0, 0,-1,0,0);
114  if(driver == 1)
115  {
117  {
118  UERROR("Not built with OpenNI2 support...");
119  exit(-1);
120  }
121  camera = new CameraOpenNI2("", CameraOpenNI2::kTypeColorDepth, 0, opticalRotation);
122  }
123  else if(driver == 2)
124  {
126  {
127  UERROR("Not built with Freenect support...");
128  exit(-1);
129  }
130  camera = new CameraFreenect(0, CameraFreenect::kTypeColorDepth, 0, opticalRotation);
131  }
132  else if(driver == 3)
133  {
135  {
136  UERROR("Not built with OpenNI from OpenCV support...");
137  exit(-1);
138  }
139  camera = new CameraOpenNICV(false, 0, opticalRotation);
140  }
141  else if(driver == 4)
142  {
144  {
145  UERROR("Not built with OpenNI from OpenCV support...");
146  exit(-1);
147  }
148  camera = new CameraOpenNICV(true, 0, opticalRotation);
149  }
150  else
151  {
152  camera = new rtabmap::CameraOpenni("", 0, opticalRotation);
153  }
154 
155 
156  if(!camera->init())
157  {
158  UERROR("Camera init failed! Try another camera driver.");
159  showUsage();
160  exit(1);
161  }
162  CameraThread cameraThread(camera);
163  if(mirroring)
164  {
165  cameraThread.setMirroringEnabled(true);
166  }
167 
168  // GUI stuff, there the handler will receive RtabmapEvent and construct the map
169  // We give it the camera so the GUI can pause/resume the camera
170  QApplication app(argc, argv);
171  MapBuilderWifi mapBuilderWifi(&cameraThread);
172 
173  // Create an odometry thread to process camera events, it will send OdometryEvent.
174  OdometryThread odomThread(new OdometryF2M());
175 
176  // Create RTAB-Map to process OdometryEvent
177  Rtabmap * rtabmap = new Rtabmap();
178  ParametersMap param;
179  param.insert(ParametersPair(Parameters::kMemRehearsalSimilarity(), "1.0")); // disable rehearsal (node merging when not moving)
180  rtabmap->init(param);
181  RtabmapThread rtabmapThread(rtabmap); // ownership is transfered
182 
183  // Create Wifi monitoring thread
184  WifiThread wifiThread(interfaceName); // 0.5 Hz, should be under RTAB-Map rate (which is 1 Hz by default)
185 
186  // Setup handlers
187  odomThread.registerToEventsManager();
188  rtabmapThread.registerToEventsManager();
189  mapBuilderWifi.registerToEventsManager();
190 
191  // The RTAB-Map is subscribed by default to CameraEvent, but we want
192  // RTAB-Map to process OdometryEvent instead, ignoring the CameraEvent.
193  // We can do that by creating a "pipe" between the camera and odometry, then
194  // only the odometry will receive CameraEvent from that camera. RTAB-Map is
195  // also subscribed to OdometryEvent by default, so no need to create a pipe between
196  // odometry and RTAB-Map.
197  UEventsManager::createPipe(&cameraThread, &odomThread, "CameraEvent");
198 
199  // Let's start the threads
200  rtabmapThread.start();
201  odomThread.start();
202  cameraThread.start();
203  wifiThread.start();
204 
205  mapBuilderWifi.show();
206  app.exec(); // main loop
207 
208  // remove handlers
209  mapBuilderWifi.unregisterFromEventsManager();
210  rtabmapThread.unregisterFromEventsManager();
211  odomThread.unregisterFromEventsManager();
212 
213  // Kill all threads
214  cameraThread.kill();
215  odomThread.join(true);
216  rtabmapThread.join(true);
217  wifiThread.join(true);
218 
219  return 0;
220 }
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:42
void kill()
Definition: UThread.cpp:48
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:41
int main(int argc, char *argv[])
static bool available()
Definition: CameraRGBD.cpp:382
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)
static bool available()
Definition: CameraRGBD.cpp:272
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
void showUsage()
static RTABMapApp app
void init(const ParametersMap &parameters, const std::string &databasePath="")
Definition: Rtabmap.cpp:282
void setMirroringEnabled(bool enabled)
Definition: CameraThread.h:62
void registerToEventsManager()
#define UERROR(...)
void unregisterFromEventsManager()
void join(bool killFirst=false)
Definition: UThread.cpp:85


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