lms2xx/lms2xx_stream_range_and_reflect/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  string device_str;
28  SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
29 
30  unsigned int num_range_values;
31  unsigned int num_reflect_values;
32  unsigned int range_values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
33  unsigned int reflect_values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
34 
35  /* Check for a device path. If it's not present, print a usage statement. */
36  if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
37  cout << "Usage: lms2xx_stream_range_and_reflect PATH [BAUD RATE]" << endl
38  << "Ex: lms2xx_stream_range_and_reflect /dev/ttyUSB0 9600" << endl;
39  return -1;
40  }
41 
42  /* Only device path is given */
43  if (argc == 2) {
44  device_str = argv[1];
45  }
46 
47  /* Device path and baud are given */
48  if (argc == 3) {
49  device_str = argv[1];
50  if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
51  cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
52  return -1;
53  }
54  }
55 
56  /*
57  * Instantiate driver instance
58  */
59  SickLMS2xx sick_lms_2xx(device_str);
60 
61  /*
62  * Initialize the Sick LMS 2xx
63  */
64  try {
65  sick_lms_2xx.Initialize(desired_baud);
66  }
67 
68  catch(...) {
69  cerr << "Initialize failed! Are you using the correct device path?" << endl;
70  return -1;
71  }
72 
73  /*
74  * Ensure it is an LMS Fast model
75  */
76  if (sick_lms_2xx.IsSickLMS2xxFast()) {
77 
78  /*
79  * Grab range and reflectivity data from the Sick LMS Fast
80  */
81  try {
82 
83  for (unsigned int i=0; i < 10; i++) {
84  sick_lms_2xx.GetSickScan(range_values,reflect_values,num_range_values,num_reflect_values);
85  cout << "Num. Range Vals: " << num_range_values << " Num. Reflect Vals: " << num_reflect_values << endl;
86  }
87 
88  }
89 
90  catch (...) {
91  cerr << "An error occurred!" << endl;
92  }
93 
94  }
95 
96  else {
97  cerr << "Oops... Your Sick is NOT an LMS Fast!" << endl;
98  cerr << "It doesn't support this kind of stream." << endl;
99  }
100 
101  /*
102  * Uninitialize the device
103  */
104  try {
105  sick_lms_2xx.Uninitialize();
106  }
107 
108  catch(...) {
109  cerr << "Uninitialize failed!" << endl;
110  return -1;
111  }
112 
113  /* Success! */
114  return 0;
115 
116 }
117 
sick_lms_2xx_baud_t
Defines available Sick LMS 2xx baud rates.
Definition: SickLMS2xx.hh:223
SickLMS2xx * sick_lms_2xx
void GetSickScan(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 obtained by the Sick LMS 2xx.
Definition: SickLMS2xx.cc:977
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
bool IsSickLMS2xxFast() const
Indicates whether the device is an LMS Fast.
Definition: SickLMS2xx.cc:1783
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...
int main(int argc, char *argv[])
A general class for interfacing w/ SickLMS2xx2xx laser range finders.
Definition: SickLMS2xx.hh:50
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