main.cc
Go to the documentation of this file.
00001 
00017 #include <stdlib.h>
00018 #include <string>
00019 #include <iostream>
00020 #include <sicktoolbox/SickLD.hh>
00021 
00022 /* Define the number of active sectors */
00023 #define NUM_ACTIVE_SECTORS (3)
00024 
00025 using namespace std;
00026 using namespace SickToolbox;
00027 
00028 int main (int argc, char *argv[]) {
00029 
00030   /* A string for the IP address */
00031   string sick_ip_addr(DEFAULT_SICK_IP_ADDRESS);
00032   
00033   /* Check the num of args */
00034   if(argc > 2 || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00035     cerr << "Usage: ld_multi_sector [SICK IP ADDRESS]" << endl
00036               << "Ex. ld_multi_sector 192.168.1.11" << endl;
00037     return -1;
00038   }
00039   
00040   /* Assign the IP address */
00041   if(argc == 2) {
00042     sick_ip_addr = argv[1];
00043   }
00044   
00045   /* Define the temporal scan area (3 active sectors/scan areas)
00046    * NOTE: This scan configuration will persist until the power
00047    *       is cycled or until it is reset w/ different params.
00048    */
00049   double sector_start_angs[NUM_ACTIVE_SECTORS] = {45,270,345};
00050   double sector_stop_angs[NUM_ACTIVE_SECTORS] = {90,315,15};
00051   
00052   /* Define the destination buffers */
00053   double range_values[SickLD::SICK_MAX_NUM_MEASUREMENTS] = {0};
00054   unsigned int reflect_values[SickLD::SICK_MAX_NUM_MEASUREMENTS] = {0};
00055 
00056   /* Some buffer for additional info we can get from the Sick LD */
00057   unsigned int num_values[NUM_ACTIVE_SECTORS] = {0};
00058   unsigned int data_offsets[NUM_ACTIVE_SECTORS] = {0};
00059   unsigned int sector_ids[NUM_ACTIVE_SECTORS] = {0};
00060 
00061   /* Define the object */
00062   SickLD sick_ld(sick_ip_addr);
00063 
00064   /* Initialize the Sick LD */
00065   try {
00066     sick_ld.Initialize();
00067   }
00068 
00069   catch(...) {
00070     cerr << "Initialize failed! Are you using the correct IP address?" << endl;
00071     return -1;
00072   }
00073   
00074   try {
00075   
00076     /* Set the temporary scan areas */
00077     sick_ld.SetSickTempScanAreas(sector_start_angs,sector_stop_angs,NUM_ACTIVE_SECTORS);
00078     
00079     /* Print the sector configuration */
00080     sick_ld.PrintSickSectorConfig();
00081     
00082     /* Request some measurements */
00083     for (unsigned int i = 0; i < 10; i++) {
00084 
00085       /* Acquire the most recent range and reflectivity (echo amplitude) values */
00086       sick_ld.GetSickMeasurements(range_values,reflect_values,num_values,sector_ids,data_offsets);
00087       
00088       /* Print out some data for each sector */
00089       for (unsigned int i = 0; i < NUM_ACTIVE_SECTORS; i++) {
00090         
00091         cout << "\t[Sector ID: " << sector_ids[i]
00092              << ", Num Meas: " << num_values[i]
00093              << ", 1st Range Val: " << range_values[data_offsets[i]]
00094              << ", 1st Reflect Val: " << reflect_values[data_offsets[i]]
00095              << "]" << endl;
00096         
00097       }
00098       cout << endl;
00099         
00100     }
00101 
00102   }
00103 
00104   /* Catch any exception! */
00105   catch(...) {
00106     cerr << "An error occurred!" << endl;
00107   }
00108 
00109   /*
00110    * Uninitialize the device
00111    */
00112   try {
00113     sick_ld.Uninitialize();
00114   }
00115   
00116   catch(...) {
00117     cerr << "Uninitialize failed!" << endl;
00118     return -1;
00119   }
00120   
00121   /* Success !*/
00122   return 0;
00123 
00124 }


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