lms2xx/lms2xx_partial_scan/src/main.cc
Go to the documentation of this file.
1 
17 #include <stdlib.h>
18 #include <string>
19 #include <iomanip>
20 #include <iostream>
22 
23 using namespace std;
24 using namespace SickToolbox;
25 
26 int main(int argc, char* argv[]) {
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 = 0; // Holds the number of measurements returned
33  unsigned int scan_idx = 0; // Holds the idx for the returned partial scan
34  unsigned int telegram_idx = 0; // Holds the idx of the telegram associated w/ scan
35 
36  /* Check for a device path. If it's not present, print a usage statement. */
37  if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
38  cout << "Usage: lms2xx_partial_scan PATH [BAUD RATE]" << endl
39  << "Ex: lms2xx_partial_scan /dev/ttyUSB0 9600" << endl;
40  return -1;
41  }
42 
43  /* Only device path is given */
44  if (argc == 2) {
45  device_str = argv[1];
46  }
47 
48  /* Device path and baud are given */
49  if (argc == 3) {
50  device_str = argv[1];
51  if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
52  cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
53  return -1;
54  }
55  }
56 
57  /*
58  * Instantiate an instance
59  */
60  SickLMS2xx sick_lms_2xx(device_str);
61 
62  /*
63  * Initialize the Sick LMS 2xx
64  */
65  try {
66  sick_lms_2xx.Initialize(desired_baud);
67  }
68 
69  catch(...) {
70  cerr << "Initialize failed! Are you using the correct device path?" << endl;
71  return -1;
72  }
73 
74  /*
75  * Ensure real-time indices are set
76  */
77  if (sick_lms_2xx.GetSickAvailability() & SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES) {
78 
79  try {
80 
81  /*
82  * Set the device variant to 100/0.25
83  *
84  * NOTE: Setting the variant this way ensures that the
85  * partial scans will start at angles that are a
86  * multiple of 0.25 deg.
87  *
88  */
89  sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_100,SickLMS2xx::SICK_SCAN_RESOLUTION_25);
90 
91  /*
92  * Acquire some partial scans from Sick
93  */
94  for (unsigned int i=0; i < 12; i++) {
95 
96  /*
97  * NOTE: Notice that here we are also obtaining the telegram idx. In a
98  * proper implementation, this value would be used to ensure the
99  * temporal consistency (acting as a sequence number) of the newly
100  * obtained partial scan. Here we simply just print it out.
101  *
102  * Also, we don't want Field A,B, or C outputs... so we pass in
103  * NULL for these params.
104  */
105  sick_lms_2xx.GetSickPartialScan(values,num_values,scan_idx,NULL,NULL,NULL,&telegram_idx);
106  cout << "\t Start angle: " << setw(4) << 0.25*scan_idx << ", Num. Values: " << num_values << ", Msg Idx: " << telegram_idx << endl;
107 
108  }
109 
110  }
111 
112  /* Catch anything else and exit */
113  catch(...) {
114  cerr << "An error occurred!" << endl;
115  }
116 
117  }
118 
119  else {
120  cout << "Please set the Sick LMS to an availability w/ real-time indices..." << endl;
121  cout << "Hint: Use the lms_config utility/example! :o)"<< endl;
122  }
123 
124  /*
125  * Uninitialize the device
126  */
127  try {
128  sick_lms_2xx.Uninitialize();
129  }
130 
131  catch(...) {
132  cerr << "Uninitialize failed!" << endl;
133  return -1;
134  }
135 
136  /* Success! */
137  return 0;
138 
139 }
140 
sick_lms_2xx_baud_t
Defines available Sick LMS 2xx baud rates.
Definition: SickLMS2xx.hh:223
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
uint8_t GetSickAvailability() const
Gets the current Sick LMS 2xx availability level flags.
Definition: SickLMS2xx.cc:821
void SetSickVariant(const sick_lms_2xx_scan_angle_t scan_angle, const sick_lms_2xx_scan_resolution_t scan_resolution)
Sets the variant of the Sick LMS 2xx (scan angle and scan resolution)
Definition: SickLMS2xx.cc:838
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
void GetSickPartialScan(unsigned int *const measurement_values, unsigned int &num_measurement_values, unsigned int &partial_scan_index, 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 partial scan obtained by Sick LMS 2xx.
Definition: SickLMS2xx.cc:1388
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