main.cc
Go to the documentation of this file.
00001 
00016 /* Implementation dependencies */
00017 #include <stdlib.h>
00018 #include <string>
00019 #include <sstream>
00020 #include <iostream>
00021 #include <signal.h>
00022 #include <stdlib.h>
00023 #include <sicktoolbox/SickLMS2xx.hh>
00024 
00025 #define INVALID_OPTION_STRING "   Invalid option!!! :o("
00026 #define PROMPT_STRING "lms2xx?> "
00027 
00028 using namespace std;
00029 using namespace SickToolbox;
00030 
00036 void sigintHandler(int signal);
00037 
00043 int strToInt(string input_str);
00044 
00051 int getUserOption(bool &is_null_input);
00052 
00057 bool writeToEEPROM();
00058 
00064 void setMeasuringUnits();
00065 
00071 void setMeasuringMode();
00072 
00078 void setAvailabilityLevel();
00079 
00085 void setSensitivityLevel();
00086 
00087 /* A pointer to the Sick obj */
00088 SickLMS2xx *sick_lms_2xx = NULL;
00089 
00090 int main(int argc, char * argv[]) {
00091 
00092   string device_str; // Device path of the Sick LMS 2xx
00093   SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
00094 
00095   /* Check for a device path.  If it's not present, print a usage statement. */
00096   if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00097     cout << "Usage: lms2xx_config PATH [BAUD RATE]" << endl
00098          << "Ex: lms2xx_config /dev/ttyUSB0 9600" << endl;
00099     return -1;
00100   }
00101 
00102   /* Only device path is given */
00103   if (argc == 2) {
00104     device_str = argv[1];
00105   }
00106 
00107   /* Device path and baud are given */
00108   if (argc == 3) {    
00109     device_str = argv[1];
00110     if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00111       cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00112       return -1;
00113     }
00114   }
00115   
00116   /* Instantiate the SickLMS2xx class with the device path string. */
00117   sick_lms_2xx = new SickLMS2xx(device_str);
00118 
00119   cout << endl;
00120   cout << "The Sick LIDAR C++/Matlab Toolbox    " << endl;
00121   cout << "Sick LMS 2xx Config Utility          " << endl;
00122   
00123   /* Initialize the device */
00124   try {
00125     sick_lms_2xx->Initialize(desired_baud);
00126   }
00127 
00128   catch(...) {
00129     cerr << "Initialize failed! Are you using the correct device path?" << endl;
00130     return -1;
00131   }
00132   
00133   /* Register the signal handler */
00134   signal(SIGINT,sigintHandler);
00135 
00136   cout << "NOTE - Configuring the Sick LMS - REQUIRES - writing to the device's EEPROM." << endl;
00137   cout << "       The number of times this can be done is finite (a few thousand)." << endl;
00138   cout << "       Thus, you should configure sparingly." << endl;
00139   cout << endl;
00140 
00141   do {
00142 
00143     cout << "Enter your choice: (Ctrl-c to exit)" << endl;
00144     cout << "  [1] Set measuring units"<< endl;
00145     cout << "  [2] Set measuring mode"<< endl;
00146     cout << "  [3] Set availability level" << endl;
00147     cout << "  [4] Set sensitivity level" << endl;
00148     cout << "  [5] Show detailed configuration" << endl;
00149     cout << PROMPT_STRING;
00150     
00151     bool is_null_input;
00152     switch(getUserOption(is_null_input)) {
00153 
00154     case 1:
00155       setMeasuringUnits();
00156       break;
00157     case 2:
00158       setMeasuringMode();
00159       break;
00160     case 3:
00161       setAvailabilityLevel();
00162       break;
00163     case 4:
00164       setSensitivityLevel();
00165       break;
00166     case 5:
00167       sick_lms_2xx->PrintSickConfig();
00168       break;
00169     default:    
00170       if (!is_null_input) {
00171         cerr << INVALID_OPTION_STRING << endl;
00172       }
00173     }
00174     
00175     cout << endl;
00176     
00177   } while(true);
00178          
00179   /* Success! */
00180   return 0;
00181 
00182 }
00183 
00187 void sigintHandler( int signal ) {
00188 
00189   cout << endl;
00190   cout << "Quitting..." << endl;
00191 
00192   /* Unitialize the device */
00193   try {
00194 
00195     sick_lms_2xx->Uninitialize();
00196     delete sick_lms_2xx;
00197 
00198   }
00199 
00200   catch(...) {
00201     cerr << "Uninitialize failed!" << endl;
00202     exit(-1);
00203   }
00204 
00205   cout << endl;
00206   cout << "Thanks for using the Sick LIDAR Matlab/C++ Toolbox!" << endl;
00207   cout << "Bye Bye :o)" << endl;
00208   
00209   exit(0);
00210 
00211 }
00212 
00216 int strToInt( string input_str ) {
00217   int int_val;
00218   istringstream input_stream(input_str);
00219   input_stream >> int_val;
00220   return int_val;
00221 }
00222 
00227 int getUserOption( bool &is_null_input ) {
00228 
00229   string user_input_str;
00230   getline(cin,user_input_str);
00231 
00232   // Check whether its null input
00233   is_null_input = true;
00234   if (user_input_str.length() > 0) {
00235     is_null_input = false;
00236   }
00237 
00238   return strToInt(user_input_str);
00239   
00240 }
00241 
00245 bool writeToEEPROM( ) {
00246 
00247   string user_input_str;
00248   
00249   do {
00250 
00251     cout << "This will attempt to write to EEPROM. Continue [y/n]? ";
00252     getline(cin,user_input_str);
00253 
00254     // Check whether its null input
00255     if (user_input_str == "Y" || user_input_str == "y") {
00256       return true;
00257     }
00258     else if (user_input_str == "N" || user_input_str == "n") {
00259       return false;
00260     }
00261     else {
00262       cerr << "Please answer [y/n]!" << endl;
00263     }
00264     
00265   } while (true);
00266     
00267 }
00268 
00272 void setMeasuringUnits() {
00273 
00274   bool keep_running = true;
00275   
00276   do {
00277 
00278     cout << endl;
00279     cout << "Select the desired units:" << endl;
00280     cout << "  [1] Centimeters (cm)"<< endl;
00281     cout << "  [2] Millimeters (mm)"<< endl;
00282     cout << "  [3] Back to main"<< endl;
00283     cout << PROMPT_STRING;
00284 
00285     try {
00286 
00287       bool is_null_input;
00288       switch(getUserOption(is_null_input)) {
00289         
00290       case 1:
00291         if (writeToEEPROM()) {
00292           cout << "  Setting Sick LMS units to (cm)" << endl;
00293           sick_lms_2xx->SetSickMeasuringUnits(SickLMS2xx::SICK_MEASURING_UNITS_CM);
00294           cout << "  Done!" << endl;
00295         }
00296         break;
00297       case 2:
00298         if (writeToEEPROM()) {
00299           cout << "  Setting Sick LMS units to (mm)" << endl;
00300           sick_lms_2xx->SetSickMeasuringUnits(SickLMS2xx::SICK_MEASURING_UNITS_MM);
00301           cout << "  Done!" << endl;
00302         }
00303         break;
00304       case 3:
00305         keep_running = !keep_running;
00306         break;
00307       default:
00308         if (!is_null_input) {
00309           cerr << INVALID_OPTION_STRING << endl;
00310         }       
00311       }
00312       
00313     }
00314     
00315     catch( SickException &sick_exception ) {
00316       cerr << "A Sick exception occurred!" << endl;
00317       exit(-1);
00318     }
00319     
00320     catch(...) {
00321       cerr << "An unknown exception occurred!" << endl;
00322       exit(-1);
00323     } 
00324     
00325   } while (keep_running);
00326 
00327 }
00328 
00332 void setMeasuringMode() {
00333 
00334   bool keep_running = true;
00335   
00336   do {
00337 
00338     cout << endl;
00339     cout << "Select the desired measuring mode (see telegram listing for descriptions):" << endl;
00340     cout << "  [1] Measurement range 8m/80m; field A, field B, and dazzle" << endl;
00341     cout << "  [2] Measurement range 8m/80m; reflector bits in 8 levels" << endl;       
00342     cout << "  [3] Measurement range 8m/80m; field A, field B and field C" << endl;
00343     cout << "  [4] Measurement range 16m/theoretically 160m; reflector bits in 4 levels" << endl;
00344     cout << "  [5] Measurement range 16m/theoretically 160m; field A and field B" << endl;
00345     cout << "  [6] Measurement range 32m/theoretically 320m; reflector bits in 2 levels" << endl;
00346     cout << "  [7] Measurement range 32m/theoretically 320m; field A" << endl;
00347     cout << "  [8] Measurement range 32m/theoretically 320m; Immediate" << endl;
00348     cout << "  [9] Reflectivity/Intensity values" << endl;
00349     cout << " [10] Back to main" << endl;
00350     cout << PROMPT_STRING;
00351     
00352     try {
00353 
00354       bool is_null_input;
00355       switch(getUserOption(is_null_input)) {
00356         
00357       case 1:
00358         if (writeToEEPROM()) {
00359           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 8m/80m; field A, field B, and dazzle" << endl;
00360           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_8_OR_80_FA_FB_DAZZLE);
00361           cout << "  Done!" << endl;
00362         }
00363         break;
00364       case 2:
00365         if (writeToEEPROM()) {
00366           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 8m/80m; reflector bits in 8 levels" << endl;
00367           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_8_OR_80_REFLECTOR);
00368           cout << "  Done!" << endl;
00369         }
00370         break;
00371       case 3:
00372         if (writeToEEPROM()) {
00373           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 8m/80m; field A, field B and field C" << endl;
00374           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_8_OR_80_FA_FB_FC);
00375           cout << "  Done!" << endl;
00376         }
00377         break;
00378       case 4:
00379         if (writeToEEPROM()) {
00380           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 16m/theoretically 160m; reflector bits in 4 levels" << endl;
00381           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_16_REFLECTOR);
00382           cout << "  Done!" << endl;
00383         }
00384         break;
00385       case 5:
00386         if (writeToEEPROM()) {
00387           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 16m/theoretically 160m; field A and field B" << endl;
00388           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_16_FA_FB);
00389           cout << "  Done!" << endl;
00390         }
00391         break;
00392       case 6:
00393         if (writeToEEPROM()) {
00394           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 32m/theoretically 320m; reflector bit in 2 levels" << endl;
00395           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_32_REFLECTOR);
00396           cout << "  Done!" << endl;
00397         }
00398         break;
00399       case 7:
00400         if (writeToEEPROM()) {
00401           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 32m/theoretically 320m; field A" << endl;
00402           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_32_FA);
00403           cout << "  Done!" << endl;
00404         }
00405         break;
00406       case 8:
00407         if (writeToEEPROM()) {
00408           cout << "  Setting Sick LMS Meas. Mode to: Measurement range 32m/theoretically 320m; Immediate" << endl;
00409           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_32_IMMEDIATE);
00410           cout << "  Done!" << endl;
00411         }
00412         break;
00413       case 9:
00414         if (writeToEEPROM()) {
00415           cout << "  Setting Sick LMS Meas. Mode to: Reflectivity/Intensity" << endl;
00416           sick_lms_2xx->SetSickMeasuringMode(SickLMS2xx::SICK_MS_MODE_REFLECTIVITY);
00417           cout << "  Done!" << endl;
00418         }
00419         break;
00420       case 10:
00421         keep_running = !keep_running;
00422         break;
00423       default:
00424         if (!is_null_input) {
00425           cerr << INVALID_OPTION_STRING << endl;
00426         }
00427       }
00428       
00429     }
00430     
00431     catch( SickException &sick_exception ) {
00432       cerr << "A Sick exception occurred!" << endl;
00433       exit(-1);
00434     }
00435     
00436     catch(...) {
00437       cerr << "An unknown exception occurred!" << endl;
00438       exit(-1);
00439     } 
00440    
00441   } while (keep_running);
00442 
00443 }
00444 
00448 void setAvailabilityLevel() {
00449 
00450   bool keep_running = true;
00451   
00452   do {
00453 
00454     cout << endl;
00455     cout << "Select the desired availability (see telegram listing for descriptions):" << endl;
00456     cout << "  [1] Restore to factory default" << endl;
00457     cout << "  [2] High" << endl;       
00458     cout << "  [3] High w/ Real-time indices" << endl;
00459     cout << "  [4] High w/ No effect dazzle" << endl;
00460     cout << "  [5] High w/ Real-time indices and No effect dazzle" << endl;
00461     cout << "  [6] Real-time indices" << endl;
00462     cout << "  [7] Real-time indices w/ No effect dazzle" << endl;
00463     cout << "  [8] No effect dazzle" << endl;
00464     cout << "  [9] Back to main" << endl;
00465     cout << PROMPT_STRING;
00466     
00467     try {
00468 
00469       bool is_null_input;
00470       switch(getUserOption(is_null_input)) {
00471         
00472       case 1:
00473         if (writeToEEPROM()) {
00474           cout << "  Setting Sick LMS Availability to: Factory settings" << endl;
00475           sick_lms_2xx->SetSickAvailability();
00476           cout << "  Done!" << endl;
00477         }
00478         break;
00479       case 2:
00480         if (writeToEEPROM()) {
00481           cout << "  Setting Sick LMS Availability to: High" << endl;
00482           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH);
00483           cout << "  Done!" << endl;
00484         }
00485         break;
00486       case 3:
00487         if (writeToEEPROM()) {
00488           cout << "  Setting Sick LMS Availability to: High w/ Real-time indices" << endl;
00489           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH | SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES);
00490           cout << "  Done!" << endl;
00491         }
00492         break;
00493       case 4:
00494         if (writeToEEPROM()) {
00495           cout << "  Setting Sick LMS Availability to: High w/ No effect dazzle" << endl;
00496           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH | SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
00497           cout << "  Done!" << endl;
00498         }
00499         break;
00500       case 5:
00501         if (writeToEEPROM()) {
00502           cout << "  Setting Sick LMS Availability to: High w/ Real-time indices and No effect dazzle" << endl;
00503           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_HIGH | SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES | SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
00504           cout << "  Done!" << endl;
00505         }
00506         break;
00507       case 6:
00508         if (writeToEEPROM()) {
00509           cout << "  Setting Sick LMS Availability to: Real-time indices" << endl;
00510           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES);
00511           cout << "  Done!" << endl;
00512         }
00513         break;
00514       case 7:
00515         if (writeToEEPROM()) {
00516           cout << "  Setting Sick LMS Availability to: Real-time indices w/ No effect dazzle" << endl;
00517           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES | SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
00518           cout << "  Done!" << endl;
00519         }
00520         break;
00521       case 8:
00522         if (writeToEEPROM()) {
00523           cout << "  Setting Sick LMS Availability to: No effect dazzle" << endl;
00524           sick_lms_2xx->SetSickAvailability(SickLMS2xx::SICK_FLAG_AVAILABILITY_DAZZLE_NO_EFFECT);
00525           cout << "  Done!" << endl;
00526         }
00527         break;
00528       case 9:
00529         keep_running = !keep_running;
00530         break;
00531       default:
00532         if (!is_null_input) {
00533           cerr << INVALID_OPTION_STRING << endl;
00534         }
00535       }
00536       
00537     }
00538     
00539     catch( SickException &sick_exception ) {
00540       cerr << "A Sick exception occurred!" << endl;
00541       exit(-1);
00542     }
00543     
00544     catch(...) {
00545       cerr << "An unknown exception occurred!" << endl;
00546       exit(-1);
00547     } 
00548    
00549   } while (keep_running);
00550   
00551 }
00552 
00556 void setSensitivityLevel() {
00557 
00558   bool keep_running = true;
00559   
00560   do {
00561 
00562     cout << endl;
00563     cout << "Select the desired sensitivity level:" << endl;
00564     cout << "  [1] High (42m @ 10% reflectivity)"<< endl;
00565     cout << "  [2] Standard (30m @ 10% reflectivity, factory setting)"<< endl;
00566     cout << "  [3] Medium (25m @ 10% reflectivity)"<< endl;
00567     cout << "  [4] Low (20m @ 10% reflectivity)"<< endl;
00568     cout << "  [5] Back to main"<< endl;
00569     cout << PROMPT_STRING;
00570 
00571     try {
00572 
00573       bool is_null_input;
00574       switch(getUserOption(is_null_input)) {
00575         
00576       case 1:
00577         if (writeToEEPROM()) {
00578           cout << "  Setting Sick LMS Sensitivity to: High" << endl;
00579           sick_lms_2xx->SetSickSensitivity(SickLMS2xx::SICK_SENSITIVITY_HIGH);
00580           cout << "  Done!" << endl;
00581         }
00582         break;
00583       case 2:
00584         if (writeToEEPROM()) {
00585           cout << "  Setting Sick LMS Sensitivity to: Standard (Factory setting)" << endl;
00586           sick_lms_2xx->SetSickSensitivity();
00587           cout << "  Done!" << endl;
00588         }
00589         break;
00590       case 3:
00591         if (writeToEEPROM()) {
00592           cout << "  Setting Sick LMS Sensitivity to: Medium" << endl;
00593           sick_lms_2xx->SetSickSensitivity(SickLMS2xx::SICK_SENSITIVITY_MEDIUM);
00594           cout << "  Done!" << endl;
00595         }
00596         break;
00597       case 4:
00598         if (writeToEEPROM()) {
00599           cout << "  Setting Sick LMS Sensitivity to: Low" << endl;
00600           sick_lms_2xx->SetSickSensitivity(SickLMS2xx::SICK_SENSITIVITY_LOW);
00601           cout << "  Done!" << endl;
00602         }
00603         break;
00604       case 5:
00605         keep_running = !keep_running;
00606         break;
00607       default:
00608         if (!is_null_input) {
00609           cerr << INVALID_OPTION_STRING << endl;
00610         }       
00611       }
00612       
00613     }
00614     
00615     catch( SickException &sick_exception ) {
00616       cerr << "A Sick exception occurred!" << endl;
00617       exit(-1);
00618     }
00619     
00620     catch(...) {
00621       cerr << "An unknown exception occurred!" << endl;
00622       exit(-1);
00623     } 
00624     
00625   } while (keep_running);
00626   
00627 }


sicktoolbox
Author(s): Jason Derenick , Thomas Miller
autogenerated on Sun May 5 2019 02:28:23