lms2xx/lms2xx_config/src/main.cc
Go to the documentation of this file.
1 
16 /* Implementation dependencies */
17 #include <stdlib.h>
18 #include <string>
19 #include <sstream>
20 #include <iostream>
21 #include <signal.h>
22 #include <stdlib.h>
24 
25 #define INVALID_OPTION_STRING " Invalid option!!! :o("
26 #define PROMPT_STRING "lms2xx?> "
27 
28 using namespace std;
29 using namespace SickToolbox;
30 
36 void sigintHandler(int signal);
37 
43 int strToInt(string input_str);
44 
51 int getUserOption(bool &is_null_input);
52 
57 bool writeToEEPROM();
58 
64 void setMeasuringUnits();
65 
71 void setMeasuringMode();
72 
79 
85 void setSensitivityLevel();
86 
87 /* A pointer to the Sick obj */
89 
90 int main(int argc, char * argv[]) {
91 
92  string device_str; // Device path of the Sick LMS 2xx
93  SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
94 
95  /* Check for a device path. If it's not present, print a usage statement. */
96  if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
97  cout << "Usage: lms2xx_config PATH [BAUD RATE]" << endl
98  << "Ex: lms2xx_config /dev/ttyUSB0 9600" << endl;
99  return -1;
100  }
101 
102  /* Only device path is given */
103  if (argc == 2) {
104  device_str = argv[1];
105  }
106 
107  /* Device path and baud are given */
108  if (argc == 3) {
109  device_str = argv[1];
110  if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
111  cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
112  return -1;
113  }
114  }
115 
116  /* Instantiate the SickLMS2xx class with the device path string. */
117  sick_lms_2xx = new SickLMS2xx(device_str);
118 
119  cout << endl;
120  cout << "The Sick LIDAR C++/Matlab Toolbox " << endl;
121  cout << "Sick LMS 2xx Config Utility " << endl;
122 
123  /* Initialize the device */
124  try {
125  sick_lms_2xx->Initialize(desired_baud);
126  }
127 
128  catch(...) {
129  cerr << "Initialize failed! Are you using the correct device path?" << endl;
130  return -1;
131  }
132 
133  /* Register the signal handler */
134  signal(SIGINT,sigintHandler);
135 
136  cout << "NOTE - Configuring the Sick LMS - REQUIRES - writing to the device's EEPROM." << endl;
137  cout << " The number of times this can be done is finite (a few thousand)." << endl;
138  cout << " Thus, you should configure sparingly." << endl;
139  cout << endl;
140 
141  do {
142 
143  cout << "Enter your choice: (Ctrl-c to exit)" << endl;
144  cout << " [1] Set measuring units"<< endl;
145  cout << " [2] Set measuring mode"<< endl;
146  cout << " [3] Set availability level" << endl;
147  cout << " [4] Set sensitivity level" << endl;
148  cout << " [5] Show detailed configuration" << endl;
149  cout << PROMPT_STRING;
150 
151  bool is_null_input;
152  switch(getUserOption(is_null_input)) {
153 
154  case 1:
156  break;
157  case 2:
159  break;
160  case 3:
162  break;
163  case 4:
165  break;
166  case 5:
167  sick_lms_2xx->PrintSickConfig();
168  break;
169  default:
170  if (!is_null_input) {
171  cerr << INVALID_OPTION_STRING << endl;
172  }
173  }
174 
175  cout << endl;
176 
177  } while(true);
178 
179  /* Success! */
180  return 0;
181 
182 }
183 
187 void sigintHandler( int signal ) {
188 
189  cout << endl;
190  cout << "Quitting..." << endl;
191 
192  /* Unitialize the device */
193  try {
194 
195  sick_lms_2xx->Uninitialize();
196  delete sick_lms_2xx;
197 
198  }
199 
200  catch(...) {
201  cerr << "Uninitialize failed!" << endl;
202  exit(-1);
203  }
204 
205  cout << endl;
206  cout << "Thanks for using the Sick LIDAR Matlab/C++ Toolbox!" << endl;
207  cout << "Bye Bye :o)" << endl;
208 
209  exit(0);
210 
211 }
212 
216 int strToInt( string input_str ) {
217  int int_val;
218  istringstream input_stream(input_str);
219  input_stream >> int_val;
220  return int_val;
221 }
222 
227 int getUserOption( bool &is_null_input ) {
228 
229  string user_input_str;
230  getline(cin,user_input_str);
231 
232  // Check whether its null input
233  is_null_input = true;
234  if (user_input_str.length() > 0) {
235  is_null_input = false;
236  }
237 
238  return strToInt(user_input_str);
239 
240 }
241 
245 bool writeToEEPROM( ) {
246 
247  string user_input_str;
248 
249  do {
250 
251  cout << "This will attempt to write to EEPROM. Continue [y/n]? ";
252  getline(cin,user_input_str);
253 
254  // Check whether its null input
255  if (user_input_str == "Y" || user_input_str == "y") {
256  return true;
257  }
258  else if (user_input_str == "N" || user_input_str == "n") {
259  return false;
260  }
261  else {
262  cerr << "Please answer [y/n]!" << endl;
263  }
264 
265  } while (true);
266 
267 }
268 
273 
274  bool keep_running = true;
275 
276  do {
277 
278  cout << endl;
279  cout << "Select the desired units:" << endl;
280  cout << " [1] Centimeters (cm)"<< endl;
281  cout << " [2] Millimeters (mm)"<< endl;
282  cout << " [3] Back to main"<< endl;
283  cout << PROMPT_STRING;
284 
285  try {
286 
287  bool is_null_input;
288  switch(getUserOption(is_null_input)) {
289 
290  case 1:
291  if (writeToEEPROM()) {
292  cout << " Setting Sick LMS units to (cm)" << endl;
293  sick_lms_2xx->SetSickMeasuringUnits(SickLMS2xx::SICK_MEASURING_UNITS_CM);
294  cout << " Done!" << endl;
295  }
296  break;
297  case 2:
298  if (writeToEEPROM()) {
299  cout << " Setting Sick LMS units to (mm)" << endl;
300  sick_lms_2xx->SetSickMeasuringUnits(SickLMS2xx::SICK_MEASURING_UNITS_MM);
301  cout << " Done!" << endl;
302  }
303  break;
304  case 3:
305  keep_running = !keep_running;
306  break;
307  default:
308  if (!is_null_input) {
309  cerr << INVALID_OPTION_STRING << endl;
310  }
311  }
312 
313  }
314 
315  catch( SickException &sick_exception ) {
316  cerr << "A Sick exception occurred!" << endl;
317  exit(-1);
318  }
319 
320  catch(...) {
321  cerr << "An unknown exception occurred!" << endl;
322  exit(-1);
323  }
324 
325  } while (keep_running);
326 
327 }
328 
333 
334  bool keep_running = true;
335 
336  do {
337 
338  cout << endl;
339  cout << "Select the desired measuring mode (see telegram listing for descriptions):" << endl;
340  cout << " [1] Measurement range 8m/80m; field A, field B, and dazzle" << endl;
341  cout << " [2] Measurement range 8m/80m; reflector bits in 8 levels" << endl;
342  cout << " [3] Measurement range 8m/80m; field A, field B and field C" << endl;
343  cout << " [4] Measurement range 16m/theoretically 160m; reflector bits in 4 levels" << endl;
344  cout << " [5] Measurement range 16m/theoretically 160m; field A and field B" << endl;
345  cout << " [6] Measurement range 32m/theoretically 320m; reflector bits in 2 levels" << endl;
346  cout << " [7] Measurement range 32m/theoretically 320m; field A" << endl;
347  cout << " [8] Measurement range 32m/theoretically 320m; Immediate" << endl;
348  cout << " [9] Reflectivity/Intensity values" << endl;
349  cout << " [10] Back to main" << endl;
350  cout << PROMPT_STRING;
351 
352  try {
353 
354  bool is_null_input;
355  switch(getUserOption(is_null_input)) {
356 
357  case 1:
358  if (writeToEEPROM()) {
359  cout << " Setting Sick LMS Meas. Mode to: Measurement range 8m/80m; field A, field B, and dazzle" << endl;
360  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_8_OR_80_FA_FB_DAZZLE);
361  cout << " Done!" << endl;
362  }
363  break;
364  case 2:
365  if (writeToEEPROM()) {
366  cout << " Setting Sick LMS Meas. Mode to: Measurement range 8m/80m; reflector bits in 8 levels" << endl;
367  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_8_OR_80_REFLECTOR);
368  cout << " Done!" << endl;
369  }
370  break;
371  case 3:
372  if (writeToEEPROM()) {
373  cout << " Setting Sick LMS Meas. Mode to: Measurement range 8m/80m; field A, field B and field C" << endl;
374  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_8_OR_80_FA_FB_FC);
375  cout << " Done!" << endl;
376  }
377  break;
378  case 4:
379  if (writeToEEPROM()) {
380  cout << " Setting Sick LMS Meas. Mode to: Measurement range 16m/theoretically 160m; reflector bits in 4 levels" << endl;
381  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_16_REFLECTOR);
382  cout << " Done!" << endl;
383  }
384  break;
385  case 5:
386  if (writeToEEPROM()) {
387  cout << " Setting Sick LMS Meas. Mode to: Measurement range 16m/theoretically 160m; field A and field B" << endl;
388  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_16_FA_FB);
389  cout << " Done!" << endl;
390  }
391  break;
392  case 6:
393  if (writeToEEPROM()) {
394  cout << " Setting Sick LMS Meas. Mode to: Measurement range 32m/theoretically 320m; reflector bit in 2 levels" << endl;
395  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_32_REFLECTOR);
396  cout << " Done!" << endl;
397  }
398  break;
399  case 7:
400  if (writeToEEPROM()) {
401  cout << " Setting Sick LMS Meas. Mode to: Measurement range 32m/theoretically 320m; field A" << endl;
402  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_32_FA);
403  cout << " Done!" << endl;
404  }
405  break;
406  case 8:
407  if (writeToEEPROM()) {
408  cout << " Setting Sick LMS Meas. Mode to: Measurement range 32m/theoretically 320m; Immediate" << endl;
409  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_32_IMMEDIATE);
410  cout << " Done!" << endl;
411  }
412  break;
413  case 9:
414  if (writeToEEPROM()) {
415  cout << " Setting Sick LMS Meas. Mode to: Reflectivity/Intensity" << endl;
416  sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_REFLECTIVITY);
417  cout << " Done!" << endl;
418  }
419  break;
420  case 10:
421  keep_running = !keep_running;
422  break;
423  default:
424  if (!is_null_input) {
425  cerr << INVALID_OPTION_STRING << endl;
426  }
427  }
428 
429  }
430 
431  catch( SickException &sick_exception ) {
432  cerr << "A Sick exception occurred!" << endl;
433  exit(-1);
434  }
435 
436  catch(...) {
437  cerr << "An unknown exception occurred!" << endl;
438  exit(-1);
439  }
440 
441  } while (keep_running);
442 
443 }
444 
449 
450  bool keep_running = true;
451 
452  do {
453 
454  cout << endl;
455  cout << "Select the desired availability (see telegram listing for descriptions):" << endl;
456  cout << " [1] Restore to factory default" << endl;
457  cout << " [2] High" << endl;
458  cout << " [3] High w/ Real-time indices" << endl;
459  cout << " [4] High w/ No effect dazzle" << endl;
460  cout << " [5] High w/ Real-time indices and No effect dazzle" << endl;
461  cout << " [6] Real-time indices" << endl;
462  cout << " [7] Real-time indices w/ No effect dazzle" << endl;
463  cout << " [8] No effect dazzle" << endl;
464  cout << " [9] Back to main" << endl;
465  cout << PROMPT_STRING;
466 
467  try {
468 
469  bool is_null_input;
470  switch(getUserOption(is_null_input)) {
471 
472  case 1:
473  if (writeToEEPROM()) {
474  cout << " Setting Sick LMS Availability to: Factory settings" << endl;
475  sick_lms_2xx->SetSickAvailability();
476  cout << " Done!" << endl;
477  }
478  break;
479  case 2:
480  if (writeToEEPROM()) {
481  cout << " Setting Sick LMS Availability to: High" << endl;
482  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH);
483  cout << " Done!" << endl;
484  }
485  break;
486  case 3:
487  if (writeToEEPROM()) {
488  cout << " Setting Sick LMS Availability to: High w/ Real-time indices" << endl;
489  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH | SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES);
490  cout << " Done!" << endl;
491  }
492  break;
493  case 4:
494  if (writeToEEPROM()) {
495  cout << " Setting Sick LMS Availability to: High w/ No effect dazzle" << endl;
496  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH | SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
497  cout << " Done!" << endl;
498  }
499  break;
500  case 5:
501  if (writeToEEPROM()) {
502  cout << " Setting Sick LMS Availability to: High w/ Real-time indices and No effect dazzle" << endl;
503  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH | SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES | SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
504  cout << " Done!" << endl;
505  }
506  break;
507  case 6:
508  if (writeToEEPROM()) {
509  cout << " Setting Sick LMS Availability to: Real-time indices" << endl;
510  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES);
511  cout << " Done!" << endl;
512  }
513  break;
514  case 7:
515  if (writeToEEPROM()) {
516  cout << " Setting Sick LMS Availability to: Real-time indices w/ No effect dazzle" << endl;
517  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES | SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
518  cout << " Done!" << endl;
519  }
520  break;
521  case 8:
522  if (writeToEEPROM()) {
523  cout << " Setting Sick LMS Availability to: No effect dazzle" << endl;
524  sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
525  cout << " Done!" << endl;
526  }
527  break;
528  case 9:
529  keep_running = !keep_running;
530  break;
531  default:
532  if (!is_null_input) {
533  cerr << INVALID_OPTION_STRING << endl;
534  }
535  }
536 
537  }
538 
539  catch( SickException &sick_exception ) {
540  cerr << "A Sick exception occurred!" << endl;
541  exit(-1);
542  }
543 
544  catch(...) {
545  cerr << "An unknown exception occurred!" << endl;
546  exit(-1);
547  }
548 
549  } while (keep_running);
550 
551 }
552 
557 
558  bool keep_running = true;
559 
560  do {
561 
562  cout << endl;
563  cout << "Select the desired sensitivity level:" << endl;
564  cout << " [1] High (42m @ 10% reflectivity)"<< endl;
565  cout << " [2] Standard (30m @ 10% reflectivity, factory setting)"<< endl;
566  cout << " [3] Medium (25m @ 10% reflectivity)"<< endl;
567  cout << " [4] Low (20m @ 10% reflectivity)"<< endl;
568  cout << " [5] Back to main"<< endl;
569  cout << PROMPT_STRING;
570 
571  try {
572 
573  bool is_null_input;
574  switch(getUserOption(is_null_input)) {
575 
576  case 1:
577  if (writeToEEPROM()) {
578  cout << " Setting Sick LMS Sensitivity to: High" << endl;
579  sick_lms_2xx->SetSickSensitivity(SickLMS2xx::SICK_SENSITIVITY_HIGH);
580  cout << " Done!" << endl;
581  }
582  break;
583  case 2:
584  if (writeToEEPROM()) {
585  cout << " Setting Sick LMS Sensitivity to: Standard (Factory setting)" << endl;
586  sick_lms_2xx->SetSickSensitivity();
587  cout << " Done!" << endl;
588  }
589  break;
590  case 3:
591  if (writeToEEPROM()) {
592  cout << " Setting Sick LMS Sensitivity to: Medium" << endl;
593  sick_lms_2xx->SetSickSensitivity(SickLMS2xx::SICK_SENSITIVITY_MEDIUM);
594  cout << " Done!" << endl;
595  }
596  break;
597  case 4:
598  if (writeToEEPROM()) {
599  cout << " Setting Sick LMS Sensitivity to: Low" << endl;
600  sick_lms_2xx->SetSickSensitivity(SickLMS2xx::SICK_SENSITIVITY_LOW);
601  cout << " Done!" << endl;
602  }
603  break;
604  case 5:
605  keep_running = !keep_running;
606  break;
607  default:
608  if (!is_null_input) {
609  cerr << INVALID_OPTION_STRING << endl;
610  }
611  }
612 
613  }
614 
615  catch( SickException &sick_exception ) {
616  cerr << "A Sick exception occurred!" << endl;
617  exit(-1);
618  }
619 
620  catch(...) {
621  cerr << "An unknown exception occurred!" << endl;
622  exit(-1);
623  }
624 
625  } while (keep_running);
626 
627 }
void PrintSickConfig() const
Prints out the Sick LMS configurations parameters.
Definition: SickLMS2xx.cc:2000
sick_lms_2xx_baud_t
Defines available Sick LMS 2xx baud rates.
Definition: SickLMS2xx.hh:223
int getUserOption(bool &is_null_input)
void SetSickSensitivity(const sick_lms_2xx_sensitivity_t sick_sensitivity=SICK_SENSITIVITY_STANDARD)
Sets the Sick LMS sensitivity level.
Definition: SickLMS2xx.cc:440
SickLMS2xx * sick_lms_2xx
void SetSickAvailability(const uint8_t sick_availability_flags=SICK_FLAG_AVAILABILITY_DEFAULT)
Sets the availability level of the device.
Definition: SickLMS2xx.cc:745
void sigintHandler(int signal)
void Initialize(const sick_lms_2xx_baud_t desired_baud_rate, const uint32_t delay=0)
Attempts to initialize the Sick LMS 2xx and then sets communication at at the given baud rate...
Definition: SickLMS2xx.cc:98
void SetSickMeasuringUnits(const sick_lms_2xx_measuring_units_t sick_units=SICK_MEASURING_UNITS_MM)
Sets the measurement units for the device.
Definition: SickLMS2xx.cc:351
Provides a base exception class from which to derive other Sick exceptions.
int main(int argc, char *argv[])
void Uninitialize()
Uninitializes the LMS by putting it in a mode where it stops streaming data, and returns it to the de...
Definition: SickLMS2xx.cc:229
#define INVALID_OPTION_STRING
Definition of class SickLMS2xx. Code by Jason C. Derenick and Thomas H. Miller. Contact derenick(at)l...
void SetSickMeasuringMode(const sick_lms_2xx_measuring_mode_t sick_measuring_mode=SICK_MS_MODE_8_OR_80_FA_FB_DAZZLE)
Sets the measuring mode for the device.
Definition: SickLMS2xx.cc:640
void setAvailabilityLevel()
Prompts the user and sets the desired availability level via the driver interface.
A general class for interfacing w/ SickLMS2xx2xx laser range finders.
Definition: SickLMS2xx.hh:50
void setMeasuringUnits()
Prompts the user and sets the desired measuring units via the driver interface.
Encapsulates the Sick LIDAR Matlab/C++ toolbox.
Definition: SickLD.cc:44
bool writeToEEPROM()
Confirms the user actually wants to perform write.
void setSensitivityLevel()
Prompts the user and sets the desired sensitivity level via the driver interface. ...
void setMeasuringMode()
Prompts the user and sets the desired measuring mode via the driver interface.
#define PROMPT_STRING
int strToInt(string input_str)


sicktoolbox
Author(s): Jason Derenick , Thomas Miller
autogenerated on Tue Sep 10 2019 03:37:34