lms2xx/lms2xx_real_time_indices/src/main.cc
Go to the documentation of this file.
1 
18 #include <stdlib.h>
19 #include <string>
20 #include <iostream>
22 
23 using namespace std;
24 using namespace SickToolbox;
25 
26 int main(int argc, char* argv[])
27 {
28 
29  string device_str;
30  SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
31 
32  unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0}; // Uses macro defined in SickLMS2xx.hh
33  unsigned int num_values = 0; // Holds the number of measurements returned
34  unsigned int telegram_idx = 0;
35  unsigned int real_time_idx = 0;
36 
37  /* Check for a device path. If it's not present, print a usage statement. */
38  if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
39  cout << "Usage: lms2xx_real_time_indices PATH [BAUD RATE]" << endl
40  << "Ex: lms2xx_real_time_indices /dev/ttyUSB0 9600" << endl;
41  return -1;
42  }
43 
44  /* Only device path is given */
45  if (argc == 2) {
46  device_str = argv[1];
47  }
48 
49  /* Device path and baud are given */
50  if (argc == 3) {
51  device_str = argv[1];
52  if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
53  cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
54  return -1;
55  }
56  }
57 
58  /*
59  * Instantiate an instance
60  */
61  SickLMS2xx sick_lms_2xx(device_str);
62 
63  /*
64  * Initialize the Sick LMS 2xx
65  */
66  try {
67  sick_lms_2xx.Initialize(desired_baud);
68  }
69 
70  catch(...) {
71  cerr << "Initialize failed! Are you using the correct device path?" << endl;
72  return -1;
73  }
74 
75  /*
76  * Ensure real-time indices are enabled
77  */
78  if (sick_lms_2xx.GetSickAvailability() & SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES) {
79 
80  try {
81 
82  /*
83  * Acquire a few scans from the Sick LMS
84  */
85  for (unsigned int i=0; i < 10; i++) {
86 
87  /* We don't want Fields A,B, or C, so we pass NULL */
88  sick_lms_2xx.GetSickScan(values,num_values,NULL,NULL,NULL,&telegram_idx,&real_time_idx);
89  cout << "\t Num. Values: " << num_values << ", Msg Idx: " << telegram_idx
90  << ", Real-time Idx: " << real_time_idx << endl;
91 
92  }
93 
94  }
95 
96  /* Catch anything else and exit */
97  catch(...) {
98  cerr << "An error occurred!" << endl;
99  return -1;
100  }
101 
102  }
103 
104  else {
105  cout << "Please set the Sick LMS to an availability w/ real-time indices..." << endl;
106  cout << "Hint: Use the lms_config utility/example! :o)"<< endl;
107  }
108 
109  /*
110  * Uninitialize the device
111  */
112  try {
113  sick_lms_2xx.Uninitialize();
114  }
115 
116  catch(...) {
117  cerr << "Uninitialize failed!" << endl;
118  return -1;
119  }
120 
121  /* Success! */
122  return 0;
123 
124 }
125 
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
uint8_t GetSickAvailability() const
Gets the current Sick LMS 2xx availability level flags.
Definition: SickLMS2xx.cc:821
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