lms2xx/lms2xx_set_variant/src/main.cc
Go to the documentation of this file.
1 
20 /* Implementation dependencies */
21 #include <stdlib.h>
22 #include <string>
23 #include <iostream>
25 
26 /* Use the namespace */
27 using namespace std;
28 using namespace SickToolbox;
29 
30 int main(int argc, char * argv[]) {
31 
32  string device_str;
33  SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
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_set_variant PATH [BAUD RATE]" << endl
38  << "Ex: lms2xx_set_variant /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  /* Instantiate the SickLMS2xx class with the device path string. */
57  SickLMS2xx sick_lms_2xx(device_str);
58 
59  /* Define some buffers to hold the returned measurements */
60  unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
61  unsigned int num_values = 0;
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  * Check whether device is LMS Fast
77  */
78  if (!sick_lms_2xx.IsSickLMS2xxFast()) {
79 
80  try {
81 
82  /*
83  * Set the device variant to 100/0.25
84  *
85  * NOTE: If an invalid variant definition is
86  * given a SickConfigException will be
87  * thrown stating so.
88  *
89  */
90  cout << "\tSetting variant to 100/0.25" << std::endl << flush;
91  sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_100,SickLMS2xx::SICK_SCAN_RESOLUTION_25);
92 
93  /*
94  * Acquire some measurements from Sick LMS 2xx using 100/0.25
95  */
96  cout << "\tAcquiring some measurements..." << endl;
97  for(unsigned int i = 0; i < 10; i++) {
98 
99  /* Acquire the most recent scan from the Sick */
100  sick_lms_2xx.GetSickScan(values,num_values);
101 
102  /* Display the number of measurements */
103  cout << "\t Num. Values: " << num_values << endl;
104 
105  }
106 
107  /*
108  * Set the device variant to 180/0.5
109  */
110  cout << std::endl << "\tSetting variant to 180/0.50" << endl;
111  sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_180,SickLMS2xx::SICK_SCAN_RESOLUTION_50);
112 
113  /*
114  * Acquire some measurements from Sick LMS 2xx using 180/0.50
115  */
116  cout << "\tAcquiring some measurements..." << endl;
117  for(unsigned int i = 0; i < 10; i++) {
118 
119  /* Acquire the most recent scan from the Sick */
120  sick_lms_2xx.GetSickScan(values,num_values);
121 
122  /* Display the number of measured values */
123  cout << "\t Num. Values: " << num_values << endl;
124 
125  }
126 
127  }
128 
129  catch(...) {
130  cerr << "An error occurred!" << endl;
131  }
132 
133  }
134 
135  else {
136  cerr << "Oops... Your Sick is an LMS Fast!" << endl;
137  cerr << "It doesn't support the variant command." << endl;
138  }
139 
140  /*
141  * Uninitialize the device
142  */
143  try {
144  sick_lms_2xx.Uninitialize();
145  }
146 
147  catch(...) {
148  cerr << "Uninitialize failed!" << endl;
149  return -1;
150  }
151 
152  /* Success! */
153  return 0;
154 
155 }
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
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[])
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...
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