time_scans.cpp
Go to the documentation of this file.
00001 
00002 // this program is just a little test to make sure the laser is working.
00003 // it's mostly just to familiarize myself with the sicktoolbox library.
00004 // it's heavily lifted from the sicktoolbox lms_simple_app program.
00005 //
00006 // Copyright (C) 2008, Morgan Quigley
00007 //
00008 // I am distributing this code under the BSD license:
00009 //
00010 // Redistribution and use in source and binary forms, with or without 
00011 // modification, are permitted provided that the following conditions are met:
00012 //   * Redistributions of source code must retain the above copyright notice, 
00013 //     this list of conditions and the following disclaimer.
00014 //   * Redistributions in binary form must reproduce the above copyright 
00015 //     notice, this list of conditions and the following disclaimer in the 
00016 //     documentation and/or other materials provided with the distribution.
00017 //   * Neither the name of Stanford University nor the names of its 
00018 //     contributors may be used to endorse or promote products derived from 
00019 //     this software without specific prior written permission.
00020 //   
00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00023 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00024 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00025 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00026 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00027 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00028 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00029 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00030 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00031 // POSSIBILITY OF SUCH DAMAGE.
00032 
00033 #include <cstdlib>
00034 #include <csignal>
00035 #include <stdint.h>
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 != 3)
00051   {
00052     printf("Usage: print_scans DEVICE BAUD_RATE\n");
00053     return 1;
00054   }
00055   string lms_dev = argv[1];
00056   SickLMS::sick_lms_baud_t desired_baud = SickLMS::StringToSickBaud(argv[2]);
00057   if (desired_baud == SickLMS::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[SickLMS::SICK_MAX_NUM_MEASUREMENTS] = {0};
00064   uint32_t num_values = 0;
00065   SickLMS 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 


sicktoolbox_wrapper
Author(s): Morgan Quigley
autogenerated on Thu Jan 2 2014 11:23:55