Go to the documentation of this file.00001
00017 #include <stdlib.h>
00018 #include <string>
00019 #include <iomanip>
00020 #include <iostream>
00021 #include <sicktoolbox/SickLMS2xx.hh>
00022
00023 using namespace std;
00024 using namespace SickToolbox;
00025
00026 int main(int argc, char* argv[]) {
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 = 0;
00033 unsigned int scan_idx = 0;
00034 unsigned int telegram_idx = 0;
00035
00036
00037 if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00038 cout << "Usage: lms2xx_partial_scan PATH [BAUD RATE]" << endl
00039 << "Ex: lms2xx_partial_scan /dev/ttyUSB0 9600" << endl;
00040 return -1;
00041 }
00042
00043
00044 if (argc == 2) {
00045 device_str = argv[1];
00046 }
00047
00048
00049 if (argc == 3) {
00050 device_str = argv[1];
00051 if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00052 cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00053 return -1;
00054 }
00055 }
00056
00057
00058
00059
00060 SickLMS2xx sick_lms_2xx(device_str);
00061
00062
00063
00064
00065 try {
00066 sick_lms_2xx.Initialize(desired_baud);
00067 }
00068
00069 catch(...) {
00070 cerr << "Initialize failed! Are you using the correct device path?" << endl;
00071 return -1;
00072 }
00073
00074
00075
00076
00077 if (sick_lms_2xx.GetSickAvailability() & SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES) {
00078
00079 try {
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 sick_lms_2xx.SetSickVariant(SickLMS2xx::SICK_SCAN_ANGLE_100,SickLMS2xx::SICK_SCAN_RESOLUTION_25);
00090
00091
00092
00093
00094 for (unsigned int i=0; i < 12; i++) {
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 sick_lms_2xx.GetSickPartialScan(values,num_values,scan_idx,NULL,NULL,NULL,&telegram_idx);
00106 cout << "\t Start angle: " << setw(4) << 0.25*scan_idx << ", Num. Values: " << num_values << ", Msg Idx: " << telegram_idx << endl;
00107
00108 }
00109
00110 }
00111
00112
00113 catch(...) {
00114 cerr << "An error occurred!" << endl;
00115 }
00116
00117 }
00118
00119 else {
00120 cout << "Please set the Sick LMS to an availability w/ real-time indices..." << endl;
00121 cout << "Hint: Use the lms_config utility/example! :o)"<< endl;
00122 }
00123
00124
00125
00126
00127 try {
00128 sick_lms_2xx.Uninitialize();
00129 }
00130
00131 catch(...) {
00132 cerr << "Uninitialize failed!" << endl;
00133 return -1;
00134 }
00135
00136
00137 return 0;
00138
00139 }
00140