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   string device_str;                      
00028   SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
00029   
00030   unsigned int num_range_values;
00031   unsigned int num_reflect_values;
00032   unsigned int range_values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
00033   unsigned int reflect_values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
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_stream_range_and_reflect PATH [BAUD RATE]" << endl
00038          << "Ex: lms2xx_stream_range_and_reflect /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   /*
00057    * Instantiate driver instance
00058    */
00059   SickLMS2xx sick_lms_2xx(device_str);
00060 
00061   /*
00062    * Initialize the Sick LMS 2xx
00063    */
00064   try {
00065     sick_lms_2xx.Initialize(desired_baud);
00066   }
00067   
00068   catch(...) {
00069     cerr << "Initialize failed! Are you using the correct device path?" << endl;
00070     return -1;
00071   }
00072 
00073   /*
00074    * Ensure it is an LMS Fast model
00075    */
00076   if (sick_lms_2xx.IsSickLMS2xxFast()) {
00077 
00078     /*
00079      * Grab range and reflectivity data from the Sick LMS Fast
00080      */        
00081     try {
00082       
00083       for (unsigned int i=0; i < 10; i++) {
00084         sick_lms_2xx.GetSickScan(range_values,reflect_values,num_range_values,num_reflect_values);
00085         cout << "Num. Range Vals: " << num_range_values << " Num. Reflect Vals: " << num_reflect_values << endl;        
00086       }
00087       
00088     }
00089 
00090     catch (...) {
00091       cerr << "An error occurred!" << endl;
00092     }
00093 
00094   }
00095 
00096   else {
00097     cerr << "Oops... Your Sick is NOT an LMS Fast!" << endl;
00098     cerr << "It doesn't support this kind of stream." << endl;
00099   }
00100    
00101   /*
00102    * Uninitialize the device
00103    */
00104   try {
00105     sick_lms_2xx.Uninitialize();
00106   }
00107   
00108   catch(...) {
00109     cerr << "Uninitialize failed!" << endl;
00110     return -1;
00111   }
00112   
00113   /* Success! */
00114   return 0;
00115 
00116 }
00117     


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