main.cc
Go to the documentation of this file.
00001 
00017 #include <stdlib.h>
00018 #include <string>
00019 #include <iostream>
00020 #include <sicktoolbox/SickLMS2xx.hh>
00021 
00022 using namespace std;
00023 using namespace SickToolbox;
00024 
00025 int main(int argc, char* argv[])
00026 {
00027   
00028   string device_str;                      
00029   SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
00030 
00031   unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0}; // Uses macro defined in SickLMS2xx.hh
00032   unsigned int num_values;                                       // Holds the number of measurements returned
00033 
00034   /* Check for a device path.  If it's not present, print a usage statement. */
00035   if ((argc != 2 && argc != 3) || (strcasecmp(argv[1],"--help") == 0)) {
00036     cout << "Usage: lms2xx_subrange PATH [BAUD RATE]" << endl
00037          << "Ex: lms2xx_subrange /dev/ttyUSB0 9600" << endl;
00038     return -1;
00039   }
00040 
00041   /* Only device path is given */
00042   if (argc == 2) {
00043     device_str = argv[1];
00044   }
00045 
00046   /* Device path and baud are given */
00047   if (argc == 3) {    
00048     device_str = argv[1];
00049     if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00050       cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00051       return -1;
00052     }
00053   }
00054 
00055   /*
00056    * Instantiate an instance
00057    */
00058   SickLMS2xx sick_lms_2xx(device_str);
00059 
00060   /*
00061    * Initialize the Sick LMS 2xx
00062    */
00063   try {
00064     sick_lms_2xx.Initialize(desired_baud);
00065   }
00066 
00067   catch(...) {
00068     cerr << "Initialize failed! Are you using the correct device path?" << endl;
00069     return -1;
00070   }  
00071   
00072   try {
00073 
00074     /*
00075      * Acquire a few scans from the Sick LMS
00076      */
00077     for (unsigned int i=0; i < 10; i++) {
00078 
00079       /*
00080        * Acquire the first ten measurements of a scan from the Sick
00081        */
00082       sick_lms_2xx.GetSickScanSubrange(1,10,values,num_values);
00083       cout << "\t  Num. Values: " << num_values << endl;
00084       
00085     }
00086 
00087   }
00088 
00089   catch(...) {
00090     cerr << "An error occurred!" << endl;
00091   }
00092 
00093   /*
00094    * Uninitialize the device
00095    */
00096   try {
00097     sick_lms_2xx.Uninitialize();
00098   }
00099   
00100   catch(...) {
00101     cerr << "Uninitialize failed!" << endl;
00102     return -1;
00103   }
00104   
00105   /* Success! */
00106   return 0;
00107 
00108 }
00109     


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