ld/ld_multi_sector/src/main.cc
Go to the documentation of this file.
1 
17 #include <stdlib.h>
18 #include <string>
19 #include <iostream>
20 #include <sicktoolbox/SickLD.hh>
21 
22 /* Define the number of active sectors */
23 #define NUM_ACTIVE_SECTORS (3)
24 
25 using namespace std;
26 using namespace SickToolbox;
27 
28 int main (int argc, char *argv[]) {
29 
30  /* A string for the IP address */
31  string sick_ip_addr(DEFAULT_SICK_IP_ADDRESS);
32 
33  /* Check the num of args */
34  if(argc > 2 || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
35  cerr << "Usage: ld_multi_sector [SICK IP ADDRESS]" << endl
36  << "Ex. ld_multi_sector 192.168.1.11" << endl;
37  return -1;
38  }
39 
40  /* Assign the IP address */
41  if(argc == 2) {
42  sick_ip_addr = argv[1];
43  }
44 
45  /* Define the temporal scan area (3 active sectors/scan areas)
46  * NOTE: This scan configuration will persist until the power
47  * is cycled or until it is reset w/ different params.
48  */
49  double sector_start_angs[NUM_ACTIVE_SECTORS] = {45,270,345};
50  double sector_stop_angs[NUM_ACTIVE_SECTORS] = {90,315,15};
51 
52  /* Define the destination buffers */
53  double range_values[SickLD::SICK_MAX_NUM_MEASUREMENTS] = {0};
54  unsigned int reflect_values[SickLD::SICK_MAX_NUM_MEASUREMENTS] = {0};
55 
56  /* Some buffer for additional info we can get from the Sick LD */
57  unsigned int num_values[NUM_ACTIVE_SECTORS] = {0};
58  unsigned int data_offsets[NUM_ACTIVE_SECTORS] = {0};
59  unsigned int sector_ids[NUM_ACTIVE_SECTORS] = {0};
60 
61  /* Define the object */
62  SickLD sick_ld(sick_ip_addr);
63 
64  /* Initialize the Sick LD */
65  try {
66  sick_ld.Initialize();
67  }
68 
69  catch(...) {
70  cerr << "Initialize failed! Are you using the correct IP address?" << endl;
71  return -1;
72  }
73 
74  try {
75 
76  /* Set the temporary scan areas */
77  sick_ld.SetSickTempScanAreas(sector_start_angs,sector_stop_angs,NUM_ACTIVE_SECTORS);
78 
79  /* Print the sector configuration */
80  sick_ld.PrintSickSectorConfig();
81 
82  /* Request some measurements */
83  for (unsigned int i = 0; i < 10; i++) {
84 
85  /* Acquire the most recent range and reflectivity (echo amplitude) values */
86  sick_ld.GetSickMeasurements(range_values,reflect_values,num_values,sector_ids,data_offsets);
87 
88  /* Print out some data for each sector */
89  for (unsigned int i = 0; i < NUM_ACTIVE_SECTORS; i++) {
90 
91  cout << "\t[Sector ID: " << sector_ids[i]
92  << ", Num Meas: " << num_values[i]
93  << ", 1st Range Val: " << range_values[data_offsets[i]]
94  << ", 1st Reflect Val: " << reflect_values[data_offsets[i]]
95  << "]" << endl;
96 
97  }
98  cout << endl;
99 
100  }
101 
102  }
103 
104  /* Catch any exception! */
105  catch(...) {
106  cerr << "An error occurred!" << endl;
107  }
108 
109  /*
110  * Uninitialize the device
111  */
112  try {
113  sick_ld.Uninitialize();
114  }
115 
116  catch(...) {
117  cerr << "Uninitialize failed!" << endl;
118  return -1;
119  }
120 
121  /* Success !*/
122  return 0;
123 
124 }
Provides a simple driver interface for working with the Sick LD-OEM/Sick LD-LRS long-range models via...
Definition: SickLD.hh:56
void PrintSickSectorConfig() const
Print the Sick LD&#39;s sector configuration.
Definition: SickLD.cc:1652
#define DEFAULT_SICK_IP_ADDRESS
Default Sick LD INet 4 address.
Definition: SickLD.hh:21
#define NUM_ACTIVE_SECTORS
void Initialize()
Initializes the driver and syncs it with Sick LD unit. Uses sector config given in flash...
Definition: SickLD.cc:91
void GetSickMeasurements(double *const range_measurements, unsigned int *const echo_measurements=NULL, unsigned int *const num_measurements=NULL, unsigned int *const sector_ids=NULL, unsigned int *const sector_data_offsets=NULL, double *const sector_step_angles=NULL, double *const sector_start_angles=NULL, double *const sector_stop_angles=NULL, unsigned int *const sector_start_timestamps=NULL, unsigned int *const sector_stop_timestamps=NULL)
Acquires measurements and corresponding sector data from the Sick LD.
Definition: SickLD.cc:740
Defines the SickLD class for working with the Sick LD-OEM/LD-LRS long range LIDARs.
Encapsulates the Sick LIDAR Matlab/C++ toolbox.
Definition: SickLD.cc:44
SickLD * sick_ld
void Uninitialize()
Tear down the connection between the host and the Sick LD.
Definition: SickLD.cc:1659
int main(int argc, char *argv[])
void SetSickTempScanAreas(const double *active_sector_start_angles, const double *const active_sector_stop_angles, const unsigned int num_active_sectors)
Set the temporary scan areas for the Sick LD.
Definition: SickLD.cc:190


sicktoolbox
Author(s): Jason Derenick , Thomas Miller
autogenerated on Tue Sep 10 2019 03:37:34