Go to the documentation of this file.00001
00017 #include <stdlib.h>
00018 #include <string>
00019 #include <iostream>
00020 #include <sicktoolbox/SickLMS2xx.hh>
00021
00022 using namespace std;
00023 using namespace SickToolbox;
00024
00025 int main(int argc, char* argv[])
00026 {
00027
00028 string device_str;
00029 SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
00030
00031 unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
00032 unsigned int num_values;
00033
00034
00035 if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00036 cout << "Usage: lms2xx_mean_values PATH [BAUD RATE]" << endl
00037 << "Ex: lms2xx_mean_values /dev/ttyUSB0 9600" << endl;
00038 return -1;
00039 }
00040
00041
00042 if (argc == 2) {
00043 device_str = argv[1];
00044 }
00045
00046
00047 if (argc == 3) {
00048 device_str = argv[1];
00049 if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00050 cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00051 return -1;
00052 }
00053 }
00054
00055
00056
00057
00058 SickLMS2xx sick_lms_2xx(device_str);
00059
00060
00061
00062
00063 try {
00064 sick_lms_2xx.Initialize(desired_baud);
00065 }
00066
00067 catch(...) {
00068 cerr << "Initialize failed! Are you using the correct device path?" << endl;
00069 return -1;
00070 }
00071
00072
00073
00074
00075 try {
00076
00077 for (unsigned int i=0; i < 10; i++) {
00078
00079
00080
00081
00082
00083
00084
00085
00086 sick_lms_2xx.GetSickMeanValues(5,values,num_values);
00087 cout << "\t Num. Values: " << num_values << endl;
00088
00089 }
00090
00091 }
00092
00093
00094 catch(...) {
00095 cerr << "An error occurred!" << endl;
00096 }
00097
00098
00099
00100
00101 try {
00102 sick_lms_2xx.Uninitialize();
00103 }
00104
00105 catch(...) {
00106 cerr << "Uninitialize failed!" << endl;
00107 return -1;
00108 }
00109
00110
00111 return 0;
00112
00113 }
00114