Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <csignal>
00034 extern "C" {
00035
00036 #include <stdint.h>
00037 }
00038 #include <cstdio>
00039 #include <sicktoolbox/SickLMS2xx.hh>
00040 using namespace SickToolbox;
00041 using namespace std;
00042
00043 bool got_ctrlc = false;
00044 void ctrlc_handler(int)
00045 {
00046 got_ctrlc = true;
00047 }
00048
00049 int main(int argc, char **argv)
00050 {
00051 if (argc != 3)
00052 {
00053 printf("Usage: print_scans DEVICE BAUD_RATE\n");
00054 return 1;
00055 }
00056 string lms_dev = argv[1];
00057 SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::StringToSickBaud(argv[2]);
00058 if (desired_baud == SickLMS2xx::SICK_BAUD_UNKNOWN)
00059 {
00060 printf("bad baud rate. must be one of {9600, 19200, 38400, 500000}\n");
00061 return 1;
00062 }
00063 signal(SIGINT, ctrlc_handler);
00064 uint32_t values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
00065 uint32_t num_values = 0;
00066 SickLMS2xx sick_lms(lms_dev);
00067 try
00068 {
00069 sick_lms.Initialize(desired_baud);
00070 }
00071 catch (...)
00072 {
00073 printf("initialize failed! are you using the correct device path?\n");
00074 }
00075 try
00076 {
00077 while (!got_ctrlc)
00078 {
00079 sick_lms.GetSickScan(values, num_values);
00080
00081 int inc = num_values / 11;
00082 printf("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n",
00083 values[0], values[inc],
00084 values[2*inc], values[3*inc],
00085 values[4*inc], values[5*inc],
00086 values[6*inc], values[7*inc],
00087 values[8*inc], values[9*inc],
00088 values[10*inc], values[num_values-1]);
00089 }
00090 }
00091 catch (...)
00092 {
00093 printf("woah! error!\n");
00094 }
00095 try
00096 {
00097 sick_lms.Uninitialize();
00098 }
00099 catch (...)
00100 {
00101 printf("error during uninitialize\n");
00102 return 1;
00103 }
00104 printf("success.\n");
00105 return 0;
00106 }
00107