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


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