main.cc
Go to the documentation of this file.
00001 
00017 #include <stdlib.h>
00018 #include <string>
00019 #include <iomanip>
00020 #include <iostream>
00021 #include <sicktoolbox/SickLMS2xx.hh>
00022 
00023 using namespace std;
00024 using namespace SickToolbox;
00025 
00026 int main(int argc, char* argv[]) {
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 = 0;                                   // Holds the number of measurements returned
00033   unsigned int scan_idx = 0;                                     // Holds the idx for the returned partial scan
00034   unsigned int telegram_idx = 0;                                 // Holds the idx of the telegram associated w/ scan
00035   
00036   /* Check for a device path.  If it's not present, print a usage statement. */
00037   if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00038     cout << "Usage: lms2xx_partial_scan PATH [BAUD RATE]" << endl
00039          << "Ex: lms2xx_partial_scan /dev/ttyUSB0 9600" << endl;
00040     return -1;
00041   }
00042 
00043   /* Only device path is given */
00044   if (argc == 2) {
00045     device_str = argv[1];
00046   }
00047 
00048   /* Device path and baud are given */
00049   if (argc == 3) {    
00050     device_str = argv[1];
00051     if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00052       cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00053       return -1;
00054     }
00055   }
00056 
00057   /*
00058    * Instantiate an instance
00059    */
00060   SickLMS2xx sick_lms_2xx(device_str);
00061 
00062   /*
00063    * Initialize the Sick LMS 2xx
00064    */
00065   try {
00066     sick_lms_2xx.Initialize(desired_baud);
00067   }
00068 
00069   catch(...) {
00070     cerr << "Initialize failed! Are you using the correct device path?" << endl;
00071     return -1;
00072   }
00073 
00074   /*
00075    * Ensure real-time indices are set
00076    */
00077   if (sick_lms_2xx.GetSickAvailability() & SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES) {
00078   
00079     try {
00080       
00081       /*
00082        * Set the device variant to 100/0.25
00083        *
00084        * NOTE: Setting the variant this way ensures that the
00085        *       partial scans will start at angles that are a
00086        *       multiple of 0.25 deg.
00087        *
00088        */
00089       sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_100,SickLMS2xx::SICK_SCAN_RESOLUTION_25);
00090       
00091       /*
00092        * Acquire some partial scans from Sick
00093        */
00094       for (unsigned int i=0; i < 12; i++) {
00095         
00096         /*
00097          * NOTE: Notice that here we are also obtaining the telegram idx.  In a
00098          *       proper implementation, this value would be used to ensure the
00099          *       temporal consistency (acting as a sequence number) of the newly
00100          *       obtained partial scan. Here we simply just print it out.
00101          *
00102          *       Also, we don't want Field A,B, or C outputs... so we pass in
00103          *       NULL for these params.
00104          */     
00105         sick_lms_2xx.GetSickPartialScan(values,num_values,scan_idx,NULL,NULL,NULL,&telegram_idx);
00106         cout << "\t  Start angle: " << setw(4) << 0.25*scan_idx << ", Num. Values: " << num_values << ", Msg Idx: " << telegram_idx << endl;
00107         
00108       }
00109       
00110     }
00111     
00112     /* Catch anything else and exit */ 
00113     catch(...) {
00114       cerr << "An error occurred!" << endl;
00115     }
00116     
00117   }
00118 
00119   else {
00120     cout << "Please set the Sick LMS to an availability w/ real-time indices..." << endl;
00121     cout << "Hint: Use the lms_config utility/example! :o)"<< endl;
00122   }
00123   
00124   /*
00125    * Uninitialize the device
00126    */
00127   try {
00128     sick_lms_2xx.Uninitialize();
00129   }
00130   
00131   catch(...) {
00132     cerr << "Uninitialize failed!" << endl;
00133     return -1;
00134   }
00135 
00136   /* Success! */
00137   return 0;
00138 
00139 }
00140     


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