log_scans.cpp
Go to the documentation of this file.
00001 
00002 // a little program that dumps LMS scans to disk in ASCII.
00003 //
00004 // Copyright (C) 2010, Morgan Quigley
00005 //
00006 // I am distributing this code under the BSD license:
00007 //
00008 // Redistribution and use in source and binary forms, with or without 
00009 // modification, are permitted provided that the following conditions are met:
00010 //   * Redistributions of source code must retain the above copyright notice, 
00011 //     this list of conditions and the following disclaimer.
00012 //   * Redistributions in binary form must reproduce the above copyright 
00013 //     notice, this list of conditions and the following disclaimer in the 
00014 //     documentation and/or other materials provided with the distribution.
00015 //   * Neither the name of Stanford University nor the names of its 
00016 //     contributors may be used to endorse or promote products derived from 
00017 //     this software without specific prior written permission.
00018 //   
00019 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00020 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00021 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00022 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00023 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00024 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00025 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00026 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00027 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00028 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00029 // POSSIBILITY OF SUCH DAMAGE.
00030 
00031 #include <csignal>
00032 extern "C" {
00033 // not everyone has <cstdint>
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       // print 12 ranges to the console
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       // dump all these guys to disk
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 


sicktoolbox_wrapper
Author(s): Morgan Quigley
autogenerated on Tue Apr 22 2014 18:56:50