lms2xx/lms2xx_subrange/src/main.cc
Go to the documentation of this file.
1 
17 #include <stdlib.h>
18 #include <string>
19 #include <iostream>
21 
22 using namespace std;
23 using namespace SickToolbox;
24 
25 int main(int argc, char* argv[])
26 {
27 
28  string device_str;
29  SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
30 
31  unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0}; // Uses macro defined in SickLMS2xx.hh
32  unsigned int num_values; // Holds the number of measurements returned
33 
34  /* Check for a device path. If it's not present, print a usage statement. */
35  if ((argc != 2 && argc != 3) || (strcasecmp(argv[1],"--help") == 0)) {
36  cout << "Usage: lms2xx_subrange PATH [BAUD RATE]" << endl
37  << "Ex: lms2xx_subrange /dev/ttyUSB0 9600" << endl;
38  return -1;
39  }
40 
41  /* Only device path is given */
42  if (argc == 2) {
43  device_str = argv[1];
44  }
45 
46  /* Device path and baud are given */
47  if (argc == 3) {
48  device_str = argv[1];
49  if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
50  cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
51  return -1;
52  }
53  }
54 
55  /*
56  * Instantiate an instance
57  */
58  SickLMS2xx sick_lms_2xx(device_str);
59 
60  /*
61  * Initialize the Sick LMS 2xx
62  */
63  try {
64  sick_lms_2xx.Initialize(desired_baud);
65  }
66 
67  catch(...) {
68  cerr << "Initialize failed! Are you using the correct device path?" << endl;
69  return -1;
70  }
71 
72  try {
73 
74  /*
75  * Acquire a few scans from the Sick LMS
76  */
77  for (unsigned int i=0; i < 10; i++) {
78 
79  /*
80  * Acquire the first ten measurements of a scan from the Sick
81  */
82  sick_lms_2xx.GetSickScanSubrange(1,10,values,num_values);
83  cout << "\t Num. Values: " << num_values << endl;
84 
85  }
86 
87  }
88 
89  catch(...) {
90  cerr << "An error occurred!" << endl;
91  }
92 
93  /*
94  * Uninitialize the device
95  */
96  try {
97  sick_lms_2xx.Uninitialize();
98  }
99 
100  catch(...) {
101  cerr << "Uninitialize failed!" << endl;
102  return -1;
103  }
104 
105  /* Success! */
106  return 0;
107 
108 }
109 
sick_lms_2xx_baud_t
Defines available Sick LMS 2xx baud rates.
Definition: SickLMS2xx.hh:223
int main(int argc, char *argv[])
SickLMS2xx * sick_lms_2xx
void Initialize(const sick_lms_2xx_baud_t desired_baud_rate, const uint32_t delay=0)
Attempts to initialize the Sick LMS 2xx and then sets communication at at the given baud rate...
Definition: SickLMS2xx.cc:98
void Uninitialize()
Uninitializes the LMS by putting it in a mode where it stops streaming data, and returns it to the de...
Definition: SickLMS2xx.cc:229
Definition of class SickLMS2xx. Code by Jason C. Derenick and Thomas H. Miller. Contact derenick(at)l...
A general class for interfacing w/ SickLMS2xx2xx laser range finders.
Definition: SickLMS2xx.hh:50
void GetSickScanSubrange(const uint16_t sick_subrange_start_index, const uint16_t sick_subrange_stop_index, unsigned int *const measurement_values, unsigned int &num_measurement_values, unsigned int *const sick_field_a_values=NULL, unsigned int *const sick_field_b_values=NULL, unsigned int *const sick_field_c_values=NULL, unsigned int *const sick_telegram_index=NULL, unsigned int *const sick_real_time_scan_index=NULL)
Returns the most recent measured values from the corresponding subrange.
Definition: SickLMS2xx.cc:1250
Encapsulates the Sick LIDAR Matlab/C++ toolbox.
Definition: SickLD.cc:44


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