Go to the documentation of this file.00001
00018 #include <stdlib.h>
00019 #include <string>
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
00029 string device_str;
00030 SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::SICK_BAUD_38400;
00031
00032 unsigned int values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
00033 unsigned int num_values = 0;
00034 unsigned int telegram_idx = 0;
00035 unsigned int real_time_idx = 0;
00036
00037
00038 if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
00039 cout << "Usage: lms2xx_real_time_indices PATH [BAUD RATE]" << endl
00040 << "Ex: lms2xx_real_time_indices /dev/ttyUSB0 9600" << endl;
00041 return -1;
00042 }
00043
00044
00045 if (argc == 2) {
00046 device_str = argv[1];
00047 }
00048
00049
00050 if (argc == 3) {
00051 device_str = argv[1];
00052 if ((desired_baud = SickLMS2xx::StringToSickBaud(argv[2])) == SickLMS2xx::SICK_BAUD_UNKNOWN) {
00053 cerr << "Invalid baud value! Valid values are: 9600, 19200, 38400, and 500000" << endl;
00054 return -1;
00055 }
00056 }
00057
00058
00059
00060
00061 SickLMS2xx sick_lms_2xx(device_str);
00062
00063
00064
00065
00066 try {
00067 sick_lms_2xx.Initialize(desired_baud);
00068 }
00069
00070 catch(...) {
00071 cerr << "Initialize failed! Are you using the correct device path?" << endl;
00072 return -1;
00073 }
00074
00075
00076
00077
00078 if (sick_lms_2xx.GetSickAvailability() & SickLMS2xx::SICK_FLAG_AVAILABILITY_REAL_TIME_INDICES) {
00079
00080 try {
00081
00082
00083
00084
00085 for (unsigned int i=0; i < 10; i++) {
00086
00087
00088 sick_lms_2xx.GetSickScan(values,num_values,NULL,NULL,NULL,&telegram_idx,&real_time_idx);
00089 cout << "\t Num. Values: " << num_values << ", Msg Idx: " << telegram_idx
00090 << ", Real-time Idx: " << real_time_idx << endl;
00091
00092 }
00093
00094 }
00095
00096
00097 catch(...) {
00098 cerr << "An error occurred!" << endl;
00099 return -1;
00100 }
00101
00102 }
00103
00104 else {
00105 cout << "Please set the Sick LMS to an availability w/ real-time indices..." << endl;
00106 cout << "Hint: Use the lms_config utility/example! :o)"<< endl;
00107 }
00108
00109
00110
00111
00112 try {
00113 sick_lms_2xx.Uninitialize();
00114 }
00115
00116 catch(...) {
00117 cerr << "Uninitialize failed!" << endl;
00118 return -1;
00119 }
00120
00121
00122 return 0;
00123
00124 }
00125