lms2xx/lms2xx_mean_values/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) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
36  cout << "Usage: lms2xx_mean_values PATH [BAUD RATE]" << endl
37  << "Ex: lms2xx_mean_values /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  /*
73  * Acquire a few scans from the Sick LMS
74  */
75  try {
76 
77  for (unsigned int i=0; i < 10; i++) {
78 
79  /*
80  * The first argument is an input to the driver
81  * telling it the number of raw scans over which
82  * the Sick should average. (i.e. here, the Sick
83  * will average over 5 scans before returning
84  * the resulting mean values)
85  */
86  sick_lms_2xx.GetSickMeanValues(5,values,num_values);
87  cout << "\t Num. Values: " << num_values << endl;
88 
89  }
90 
91  }
92 
93  /* Catch anything else and exit */
94  catch(...) {
95  cerr << "An error occurred!" << endl;
96  }
97 
98  /*
99  * Uninitialize the device
100  */
101  try {
102  sick_lms_2xx.Uninitialize();
103  }
104 
105  catch(...) {
106  cerr << "Uninitialize failed!" << endl;
107  return -1;
108  }
109 
110  /* Success! */
111  return 0;
112 
113 }
114 
sick_lms_2xx_baud_t
Defines available Sick LMS 2xx baud rates.
Definition: SickLMS2xx.hh:223
SickLMS2xx * sick_lms_2xx
int main(int argc, char *argv[])
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 GetSickMeanValues(const uint8_t sick_sample_size, unsigned int *const measurement_values, unsigned int &num_measurement_values, unsigned int *const sick_telegram_index=NULL, unsigned int *const sick_real_time_index=NULL)
Returns the most recent mean measured values from the Sick LMS 2xx.
Definition: SickLMS2xx.cc:1519
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