main.cpp
Go to the documentation of this file.
1 //
2 // main.cpp
3 //
4 // LD-MRS example driver and application.
5 // This code should compile under Linux.
6 //
7 // The main() function contains calls to several demo applications.
8 // Most of the scanner parameters - including its IP address - are set up
9 // directly in the LDMRS class constructor.
10 //
11 // All source code provided here is intended for demonstration and reference purposes only.
12 // SICK provides no warranty whatsoever for the function of this code.
13 //
14 // Note that not all features are available with all firmware versions of the MRS. Please refer
15 // to the manual if the intended functionality is available with your device.
16 //
17 // Change log:
18 // 2013-09-18, willhvo:
19 // - Started change log.
20 // 2014-03-04, willhvo:
21 // - Added NtpTimeApp demo.
22 // 2014-12-18, willhvo:
23 // - Added ScanpointCoordinateApp demo.
24 //
25 
26 #include "tools/errorhandler.hpp"
27 #include "BasicDatatypes.hpp"
28 #include "manager.hpp"
29 
30 //
31 // This example demonstrates setting and receiving the NTP timestamp of the MRS. The timestamp
32 // can be set with two commands, and is automatically included in every data packet received
33 // from the sensor.
34 // This feature is available in all firmware versions.
35 //
36 // The MRS device should be configured like this:
37 // m_weWantScanData: true
38 // m_weWantObjectData: false
39 // m_weWantFieldData: false
40 // m_weWantScanDataFromSopas: false
41 //
43 {
44  // First, create the manager object. The manager handles devices, collects
45  // device data and forwards it to the application(s).
46  printInfoMessage("mrsNtpTimeApp: Creating the manager.", true);
47  Manager manager;
48 
49  Sourcetype type;
50  std::string name;
51  UINT16 id;
52  bool result = false;
53 
54  // Add the MRS device (sensor)
55  printInfoMessage("mrsNtpTimeApp: Adding the LDMRS device.", true);
56  type = Sourcetype_LDMRS;
57  name = "LDMRS-1";
58  id = 1;
59  result = manager.addAndRunDevice(type, name, id);
60  if (result == false)
61  {
62  printError("mrsNtpTimeApp: Failed to add device " + name + ", aborting!");
63  return 0;
64  }
65 
66  // Add the application. As the devices may send configuration data only once
67  // at startup, the applications may want to be present before the devices are
68  // started. But - this is not needed here.
69  printInfoMessage("mrsNtpTimeApp: Adding the application MrsNtpTimeApp.", true);
71  name = "MRS Example NTP time App";
72  id = 51;
73  result = manager.addApplication(type, name, id);
74  if (result == false)
75  {
76  printError("mrsNtpTimeApp: Failed to add application " + name + ", aborting!");
77  return 0;
78  }
79  printInfoMessage("mrsNtpTimeApp: Application NTP-time is running.", true);
80 
81 
82  // This loop never ends
83  while (1)
84  {
85  // Sleep 100 ms
86  usleep(100000);
87  }
88 
89  return 0;
90 }
91 
92 
93 //
94 // This example demonstrates setting and checking the FlexibleResolution feature of the
95 // LDMRS. This feature is not available in all firmware versions.
96 //
97 // The MRS device should be configured like this:
98 // m_weWantScanData: true
99 // m_weWantObjectData: false
100 // m_weWantFieldData: false
101 // m_weWantScanDataFromSopas: false
102 //
104 {
105  // First, create the manager object. The manager handles devices, collects
106  // device data and forwards it to the application(s).
107  printInfoMessage("sectorChangeApp: Creating the manager.", true);
108  Manager manager;
109 
110  Sourcetype type;
111  std::string name;
112  UINT16 id;
113  bool result = false;
114 
115  // Add the MRS device (sensor)
116  printInfoMessage("sectorChangeApp: Adding the LDMRS device.", true);
117  type = Sourcetype_LDMRS;
118  name = "LDMRS-1";
119  id = 1;
120  result = manager.addAndRunDevice(type, name, id);
121  if (result == false)
122  {
123  printError("sectorChangeApp: Failed to add device " + name + ", aborting!");
124  return 0;
125  }
126 
127  // Add the application. As the devices may send configuration data only once
128  // at startup, the applications may want to be present before the devices are
129  // started. But - this is not needed here.
130  printInfoMessage("sectorChangeApp: Adding the application MrsSectorChangeApp.", true);
132  name = "MRS Example Sector Change App";
133  id = 51;
134  result = manager.addApplication(type, name, id);
135  if (result == false)
136  {
137  printError("sectorChangeApp: Failed to add application " + name + ", aborting!");
138  return 0;
139  }
140  printInfoMessage("sectorChangeApp: Application SectorChange is running.", true);
141 
142 
143  // This loop never ends
144  while (1)
145  {
146  // Sleep 100 ms
147  usleep(100000);
148  }
149 
150  return 0;
151 }
152 
153 
154 //
155 // SOPAS scan data reception application.
156 // This example shows the reception of scan data via the SOPAS interface.
157 // Note 1: If only scan data is required, it is recommended to use the MRS interface instead.
158 // Note 2: Not all MRS devices have a SOPAS interface.
159 //
160 // The MRS device should be configured like this:
161 // m_weWantScanData: false
162 // m_weWantObjectData: false
163 // m_weWantFieldData: false
164 // m_weWantScanDataFromSopas: true
165 //
167 {
168  // First, create the manager object. The manager handles devices, collects
169  // device data and forwards it to the application(s).
170  printInfoMessage("mrsSopasScandataApp: Creating the manager.", true);
171  Manager manager;
172 
173  // Add the application. As the devices may send configuration data only once
174  // at startup, the applications must be present before the devices are
175  // started. Here, we are using the general data display app because we only want
176  // to show the received data.
177  Sourcetype type;
178  std::string name;
179  UINT16 id;
180  bool result = false;
181 
182  printInfoMessage("mrsSopasScandataApp: Adding the application MrsApp.", true);
183  type = Sourcetype_MrsApp;
184  name = "MRS ExampleApp";
185  id = 50;
186  result = manager.addApplication(type, name, id);
187  if (result == false)
188  {
189  printError("mrsSopasScandataApp: Failed to add application " + name + ", aborting!");
190  return 0;
191  }
192  printInfoMessage("mrsSopasScandataApp: Application is running.", true);
193 
194  //
195  // Add and run the sensor
196  //
197  printInfoMessage("mrsSopasScandataApp: Adding the LDMRS device.", true);
198  type = Sourcetype_LDMRS;
199  name = "LDMRS-1";
200  id = 1;
201  result = manager.addAndRunDevice(type, name, id);
202  if (result == false)
203  {
204  printError("mrsSopasScandataApp: Failed to add device " + name + ", aborting!");
205  return 0;
206  }
207 
208  // This loop never ends
209  while (1)
210  {
211  // Sleep 100 ms
212  usleep(100000);
213  }
214 
215  return 0;
216 }
217 
218 
219 //
220 // Field setting application.
221 //
222 // The MRS device should be configured like this:
223 // m_weWantScanData: false
224 // m_weWantObjectData: false
225 // m_weWantFieldData: true
226 // m_weWantScanDataFromSopas: false
227 //
229 {
230  // First, create the manager object. The manager handles devices, collects
231  // device data and forwards it to the application(s).
232  printInfoMessage("mrsFieldApp: Creating the manager.", true);
233  Manager manager;
234 
235  // Add the application. As the devices may send configuration data only once
236  // at startup, the applications must be present before the devices are
237  // started.
238  Sourcetype type;
239  std::string name;
240  UINT16 id;
241  bool result = false;
242 
243  printInfoMessage("mrsFieldApp: Adding the application MrsFieldApp.", true);
244  type = Sourcetype_MrsFieldApp;
245  name = "MRS FieldApp";
246  id = 50;
247  result = manager.addApplication(type, name, id);
248  if (result == false)
249  {
250  printError("mrsFieldApp: Failed to add application " + name + ", aborting!");
251  return 0;
252  }
253  printInfoMessage("mrsFieldApp: Application is running.", true);
254 
255  //
256  // Add and run the sensor
257  //
258  printInfoMessage("mrsFieldApp: Adding the LDMRS device.", true);
259  type = Sourcetype_LDMRS;
260  name = "LDMRS-1";
261  id = 1;
262  result = manager.addAndRunDevice(type, name, id);
263  if (result == false)
264  {
265  printError("mrsFieldApp: Failed to add device " + name + ", aborting!");
266  return 0;
267  }
268 
269  // This loop never ends
270  while (1)
271  {
272  // Sleep 100 ms
273  usleep(100000);
274  }
275 
276  return 0;
277 }
278 
279 
280 //
281 // Demo application for scanpoint coordinate calculation. Receives the scanpoints, and prints coordinates of the points at the
282 // configured scan angle.
283 //
284 // The MRS device could be configured like this:
285 // m_weWantScanData: true
286 // m_weWantObjectData: false
287 // m_weWantFieldData: false
288 // m_weWantScanDataFromSopas: false
289 //
291 {
292  // First, create the manager object. The manager handles devices, collects
293  // device data and forwards it to the application(s).
294  printInfoMessage("mrsScanpointCoordinateApp: Creating the manager.", true);
295  Manager manager;
296 
297  // Add the application. As the devices may send configuration data only once
298  // at startup, the applications must be present before the devices are
299  // started.
300  Sourcetype type;
301  std::string name;
302  UINT16 id;
303  bool result = false;
304 
305  printInfoMessage("mrsScanpointCoordinateApp: Adding the application MrsScanpointCoordinateApp.", true);
307  name = "MRS CoordinateApp";
308  id = 50;
309  result = manager.addApplication(type, name, id);
310  if (result == false)
311  {
312  printError("mrsScanpointCoordinateApp: Failed to add application " + name + ", aborting!");
313  return 0;
314  }
315  printInfoMessage("mrsScanpointCoordinateApp: Application is running.", true);
316 
317  //
318  // Add and run the sensor
319  //
320  printInfoMessage("mrsScanpointCoordinateApp: Adding the LDMRS device.", true);
321  type = Sourcetype_LDMRS;
322  name = "LDMRS-1";
323  id = 1;
324  result = manager.addAndRunDevice(type, name, id);
325  if (result == false)
326  {
327  printError("mrsScanpointCoordinateApp: Failed to add device " + name + ", aborting!");
328  return 0;
329  }
330 
331  // This loop never ends
332  while (1)
333  {
334  // Sleep 100 ms
335  usleep(100000);
336  }
337 
338  return 0;
339 }
340 
341 
342 
343 //
344 // Minimal demo application. Receives all datatypes and just prints the data.
345 //
346 // The MRS device could be configured like this:
347 // m_weWantScanData: true
348 // m_weWantObjectData: true
349 // m_weWantFieldData: false
350 // m_weWantScanDataFromSopas: false
351 //
352 int mrsApp()
353 {
354  // First, create the manager object. The manager handles devices, collects
355  // device data and forwards it to the application(s).
356  printInfoMessage("mrsApp: Creating the manager.", true);
357  Manager manager;
358 
359  // Add the application. As the devices may send configuration data only once
360  // at startup, the applications must be present before the devices are
361  // started.
362  Sourcetype type;
363  std::string name;
364  UINT16 id;
365  bool result = false;
366 
367  printInfoMessage("mrsApp: Adding the application MrsApp.", true);
368  type = Sourcetype_MrsApp;
369  name = "MRS ExampleApp";
370  id = 50;
371  result = manager.addApplication(type, name, id);
372  if (result == false)
373  {
374  printError("mrsApp: Failed to add application " + name + ", aborting!");
375  return 0;
376  }
377  printInfoMessage("mrsApp: Application is running.", true);
378 
379  //
380  // Add and run the sensor
381  //
382  printInfoMessage("mrsApp: Adding the LDMRS device.", true);
383  type = Sourcetype_LDMRS;
384  name = "LDMRS-1";
385  id = 1;
386  result = manager.addAndRunDevice(type, name, id);
387  if (result == false)
388  {
389  printError("mrsApp: Failed to add device " + name + ", aborting!");
390  return 0;
391  }
392 
393  // This loop never ends
394  while (1)
395  {
396  // Sleep 100 ms
397  usleep(100000);
398  }
399 
400  return 0;
401 }
402 
403 
404 //
405 // The main program.
406 // Choose the desired application here.
407 //
408 int main(int argc, char **argv)
409 {
410  //
411  // LD-MRS Example
412  //
413  int result;
414 
415  // The MRS-App connects to an MRS, reads its configuration and receives all incoming data.
416  result = mrsApp();
417 
418  // The MRS-App connects to an MRS, reads its configuration and displays scanpoint coordinates.
419 // result = mrsScanpointCoordinateApp();
420 
421  // The MRS NtpTimeApp demonstrates setting and reading the NTP timestamp.
422 // result = mrsNtpTimeApp();
423 
424  // The SectorChangeApp demonstrates the usage of the FlexRes feature.
425 // result = sectorChangeApp();
426 
427  // The FieldApp demonstrates the usage of the SOPAS interface. It removes and creates fields and
428  // eval cases.
429 // result = mrsFieldApp();
430 
431  // The SopasScandataApp demonstrates reading scan data via the SOPAS interface.
432 // result = mrsSopasScandataApp();
433 
434 
435  return result;
436 }
void printError(std::string message)
int mrsApp()
Definition: main.cpp:352
uint16_t UINT16
int main(int argc, char **argv)
Definition: main.cpp:408
int mrsSopasScandataApp()
Definition: main.cpp:166
bool addAndRunDevice(Sourcetype deviceType, std::string deviceName, UINT16 wantedId=0xFFFF)
Definition: manager.cpp:91
int mrsFieldApp()
Definition: main.cpp:228
#define printInfoMessage(a, b)
bool addApplication(Sourcetype appType, std::string appName, UINT16 wantedId=0xFFFF)
Definition: manager.cpp:178
int sectorChangeApp()
Definition: main.cpp:103
int mrsScanpointCoordinateApp()
Definition: main.cpp:290
Sourcetype
int mrsNtpTimeApp()
Definition: main.cpp:42


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Mon Oct 26 2020 03:27:30