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) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00036     cout << "Usage: lms2xx_mean_values PATH [BAUD RATE]" << endl
00037          << "Ex: lms2xx_mean_values /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   /*
00073    * Acquire a few scans from the Sick LMS
00074    */
00075   try {
00076 
00077     for (unsigned int i=0; i < 10; i++) {
00078 
00079       /*
00080        * The first argument is an input to the driver
00081        * telling it the number of raw scans over which
00082        * the Sick should average. (i.e. here, the Sick
00083        * will average over 5 scans before returning
00084        * the resulting mean values)
00085        */
00086       sick_lms_2xx.GetSickMeanValues(5,values,num_values);
00087       cout << "\t  Num. Values: " << num_values << endl;
00088       
00089     }
00090 
00091   }
00092 
00093   /* Catch anything else and exit */ 
00094   catch(...) {
00095     cerr << "An error occurred!" << endl;
00096   }
00097 
00098   /*
00099    * Uninitialize the device
00100    */
00101   try {
00102     sick_lms_2xx.Uninitialize();
00103   }
00104   
00105   catch(...) {
00106     cerr << "Uninitialize failed!" << endl;
00107     return -1;
00108   }
00109 
00110   /* Success! */
00111   return 0;
00112 
00113 }
00114     


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