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 <cstdlib>
00034 #include <csignal>
00035 #include <stdint.h>
00036 #include <cstdio>
00037 #include <sicktoolbox/SickLMS2xx.hh>
00038 #include "ros/time.h"
00039 using namespace SickToolbox;
00040 using namespace std;
00041
00042 bool got_ctrlc = false;
00043 void ctrlc_handler(int)
00044 {
00045 got_ctrlc = true;
00046 }
00047
00048 int main(int argc, char **argv)
00049 {
00050 if (argc != 3)
00051 {
00052 printf("Usage: print_scans DEVICE BAUD_RATE\n");
00053 return 1;
00054 }
00055 string lms_dev = argv[1];
00056 SickLMS2xx::sick_lms_2xx_baud_t desired_baud = SickLMS2xx::StringToSickBaud(argv[2]);
00057 if (desired_baud == SickLMS2xx::SICK_BAUD_UNKNOWN)
00058 {
00059 printf("bad baud rate. must be one of {9600, 19200, 38400, 500000}\n");
00060 return 1;
00061 }
00062 signal(SIGINT, ctrlc_handler);
00063 uint32_t values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
00064 uint32_t num_values = 0;
00065 SickLMS2xx sick_lms(lms_dev);
00066 try
00067 {
00068 sick_lms.Initialize(desired_baud);
00069 }
00070 catch (...)
00071 {
00072 printf("initialize failed! are you using the correct device path?\n");
00073 }
00074 try
00075 {
00076 ros::Time prev_scan_time = ros::Time::now();
00077 while (!got_ctrlc)
00078 {
00079 sick_lms.GetSickScan(values, num_values);
00080 ros::Time t = ros::Time::now();
00081 double delta = t.toSec() - prev_scan_time.toSec();
00082 printf("%f (%f)\n", delta, 1.0 / delta);
00083 prev_scan_time = t;
00084 }
00085 }
00086 catch (...)
00087 {
00088 printf("woah! error!\n");
00089 }
00090 try
00091 {
00092 sick_lms.Uninitialize();
00093 }
00094 catch (...)
00095 {
00096 printf("error during uninitialize\n");
00097 return 1;
00098 }
00099 printf("success.\n");
00100 return 0;
00101 }
00102