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 #include <csignal>
00032 extern "C" {
00033
00034 #include <stdint.h>
00035 }
00036 #include <cstdio>
00037 #include <sicklms-1.0/SickLMS.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 != 4)
00051 {
00052 printf("Usage: log_scans DEVICE BAUD_RATE FILENAME\n");
00053 return 1;
00054 }
00055 FILE *log = fopen(argv[3],"w");
00056 if (!log)
00057 {
00058 fprintf(stderr, "couldn't open logfile %s\n", argv[3]);
00059 return 1;
00060 }
00061 string lms_dev = argv[1];
00062 SickLMS::sick_lms_baud_t desired_baud = SickLMS::StringToSickBaud(argv[2]);
00063 if (desired_baud == SickLMS::SICK_BAUD_UNKNOWN)
00064 {
00065 printf("bad baud rate. must be one of {9600, 19200, 38400, 500000}\n");
00066 return 1;
00067 }
00068 signal(SIGINT, ctrlc_handler);
00069 uint32_t values[SickLMS::SICK_MAX_NUM_MEASUREMENTS] = {0};
00070 uint32_t num_values = 0;
00071 SickLMS sick_lms(lms_dev);
00072 try
00073 {
00074 sick_lms.Initialize(desired_baud);
00075 }
00076 catch (...)
00077 {
00078 printf("initialize failed! are you using the correct device path?\n");
00079 }
00080 try
00081 {
00082 while (!got_ctrlc)
00083 {
00084 sick_lms.GetSickScan(values, num_values);
00085
00086 int inc = num_values / 11;
00087 printf("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n",
00088 values[0], values[inc],
00089 values[2*inc], values[3*inc],
00090 values[4*inc], values[5*inc],
00091 values[6*inc], values[7*inc],
00092 values[8*inc], values[9*inc],
00093 values[10*inc], values[num_values-1]);
00094
00095 fprintf(log, "%.6f ", ros::Time::now().toSec());
00096 for (unsigned i = 0; i < num_values; i++)
00097 fprintf(log, "%d ", values[i]);
00098 fprintf(log, "\n");
00099 }
00100 }
00101 catch (...)
00102 {
00103 printf("woah! error!\n");
00104 }
00105 try
00106 {
00107 sick_lms.Uninitialize();
00108 }
00109 catch (...)
00110 {
00111 printf("error during uninitialize\n");
00112 return 1;
00113 }
00114 fclose(log);
00115 printf("success.\n");
00116 return 0;
00117 }
00118