main.cc
Go to the documentation of this file.
00001 
00020 /* Implementation dependencies */
00021 #include <stdlib.h>
00022 #include <string>
00023 #include <iostream>
00024 #include <sicktoolbox/SickLMS2xx.hh>
00025 
00026 /* Use the namespace */
00027 using namespace std;
00028 using namespace SickToolbox;
00029 
00030 int main(int argc, char * argv[]) {
00031   
00032   string device_str;                
00033   SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
00034   
00035   /* Check for a device path.  If it's not present, print a usage statement. */
00036   if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00037     cout << "Usage: lms2xx_set_variant PATH [BAUD RATE]" << endl
00038          << "Ex: lms2xx_set_variant /dev/ttyUSB0 9600" << endl;
00039     return -1;
00040   }
00041 
00042   /* Only device path is given */
00043   if (argc == 2) {
00044     device_str = argv[1];
00045   }
00046 
00047   /* Device path and baud are given */
00048   if (argc == 3) {    
00049     device_str = argv[1];
00050     if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00051       cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00052       return -1;
00053     }
00054   }
00055 
00056   /* Instantiate the SickLMS2xx class with the device path string. */
00057   SickLMS2xx sick_lms_2xx(device_str);
00058 
00059   /* Define some buffers to hold the returned measurements */
00060   unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
00061   unsigned int num_values = 0;
00062 
00063   /*
00064    * Initialize the Sick LMS 2xx
00065    */
00066   try {
00067     sick_lms_2xx.Initialize(desired_baud);
00068   }
00069 
00070   catch(...) {
00071     cerr << "Initialize failed! Are you using the correct device path?" << endl;
00072     return -1;
00073   }  
00074 
00075   /*
00076    * Check whether device is LMS Fast
00077    */
00078   if (!sick_lms_2xx.IsSickLMS2xxFast()) {
00079 
00080     try {
00081       
00082       /*
00083        * Set the device variant to 100/0.25
00084        *
00085        * NOTE: If an invalid variant definition is
00086        *       given a SickConfigException will be
00087        *       thrown stating so.
00088        *
00089        */
00090       cout << "\tSetting variant to 100/0.25" << std::endl << flush;
00091       sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_100,SickLMS2xx::SICK_SCAN_RESOLUTION_25);
00092       
00093       /*
00094        * Acquire some measurements from Sick LMS 2xx using 100/0.25
00095        */
00096       cout << "\tAcquiring some measurements..." << endl;
00097       for(unsigned int i = 0; i < 10; i++) {
00098         
00099         /* Acquire the most recent scan from the Sick */
00100         sick_lms_2xx.GetSickScan(values,num_values);
00101         
00102         /* Display the number of measurements */
00103         cout << "\t  Num. Values: " << num_values << endl;
00104         
00105       }
00106       
00107       /*
00108        * Set the device variant to 180/0.5
00109        */
00110       cout << std::endl << "\tSetting variant to 180/0.50" << endl;
00111       sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_180,SickLMS2xx::SICK_SCAN_RESOLUTION_50);
00112       
00113       /*
00114        * Acquire some measurements from Sick LMS 2xx using 180/0.50
00115        */
00116       cout << "\tAcquiring some measurements..." << endl;
00117       for(unsigned int i = 0; i < 10; i++) {
00118         
00119         /* Acquire the most recent scan from the Sick */
00120         sick_lms_2xx.GetSickScan(values,num_values);
00121         
00122         /* Display the number of measured values */
00123         cout << "\t  Num. Values: " << num_values << endl;
00124         
00125       }
00126       
00127     }
00128 
00129     catch(...) {
00130       cerr << "An error occurred!" << endl;
00131     }
00132 
00133   }
00134     
00135   else {
00136     cerr << "Oops... Your Sick is an LMS Fast!" << endl;
00137     cerr << "It doesn't support the variant command." << endl;
00138   }
00139     
00140   /*
00141    * Uninitialize the device
00142    */
00143   try {
00144     sick_lms_2xx.Uninitialize();
00145   }
00146   
00147   catch(...) {
00148     cerr << "Uninitialize failed!" << endl;
00149     return -1;
00150   }
00151   
00152   /* Success! */
00153   return 0;
00154 
00155 }


sicktoolbox
Author(s): Jason Derenick , Thomas Miller
autogenerated on Thu Aug 27 2015 15:17:16