lms2xx/lms2xx_simple_app/src/main.cc
Go to the documentation of this file.
1 
16 #include <stdlib.h>
17 #include <string>
18 #include <iostream>
20 
21 using namespace std;
22 using namespace SickToolbox;
23 
24 int main(int argc, char* argv[])
25 {
26 
27  string device_str;
28  SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
29 
30  unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0}; // Uses macro defined in SickLMS2xx.hh
31  unsigned int num_values = 0; // Holds the number of measurements returned
32 
33  /* Check for a device path. If it's not present, print a usage statement. */
34  if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
35  cout << "Usage: lms2xx_simple_app PATH [BAUD RATE]" << endl
36  << "Ex: lms2xx_simple_app /dev/ttyUSB0 9600" << endl;
37  return -1;
38  }
39 
40  /* Only device path is given */
41  if (argc == 2) {
42  device_str = argv[1];
43  }
44 
45  /* Device path and baud are given */
46  if (argc == 3) {
47  device_str = argv[1];
48  if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
49  cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
50  return -1;
51  }
52  }
53 
54  /*
55  * Instantiate an instance
56  */
57  SickLMS2xx sick_lms_2xx(device_str);
58 
59  /*
60  * Initialize the Sick LMS 2xx
61  */
62  try {
63  sick_lms_2xx.Initialize(desired_baud);
64  }
65 
66  catch(...) {
67  cerr << "Initialize failed! Are you using the correct device path?" << endl;
68  return -1;
69  }
70 
71  /*
72  * Acquire a few scans from the Sick LMS
73  */
74  try {
75 
76  for (unsigned int i=0; i < 10; i++) {
77  sick_lms_2xx.GetSickScan(values,num_values);
78  cout << "\t Num. Values: " << num_values << endl;
79  }
80 
81  }
82 
83  /* Catch anything else and exit */
84  catch(...) {
85  cerr << "An error occurred!" << endl;
86  }
87 
88  /*
89  * Uninitialize the device
90  */
91  try {
92  sick_lms_2xx.Uninitialize();
93  }
94 
95  catch(...) {
96  cerr << "Uninitialize failed!" << endl;
97  return -1;
98  }
99 
100  /* Success! */
101  return 0;
102 
103 }
104 
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
int main(int argc, char *argv[])
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
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