test-LaserRangeFinder.C

Go to the documentation of this file.
00001 /*!@file AppDevices/test-LaserRangeFinder.C Test the Hokuyo laser
00002 range finder */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Farhan Baluch <fbaluch@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppDevices/test-LaserRangeFinder.C $
00036 // $Id: test-LaserRangeFinder.C 12962 2010-03-06 02:13:53Z irock $
00037 //
00038 // NOTE: need Liburg-0.1.0-9mdv2008.1.x86_64.rpm
00039 //       which may be obtained at: /lab/mviswana/rpm/RPMS/
00040 
00041 #include "Component/ModelManager.H"
00042 #include "Raster/Raster.H"
00043 #include "Image/Image.H"
00044 #include "Image/DrawOps.H"
00045 #include "Image/MathOps.H"
00046 #include "Media/FrameSeries.H"
00047 #include "Transport/FrameInfo.H"
00048 #include "Raster/GenericFrame.H"
00049 #include "Transport/FrameInfo.H"
00050 #include "GUI/ImageDisplayStream.H"
00051 #include "GUI/XWinManaged.H"
00052 #include "Robots/LoBot/io/LoLaserRangeFinder.H"
00053 #include <algorithm>
00054 #include <iterator>
00055 //#include <urg/urg.h>
00056 
00057 
00058 int main(int argc, const char **argv)
00059 {
00060   // Instantiate a ModelManager:
00061   ModelManager manager("Test laser range finder");
00062 
00063   nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00064   manager.addSubComponent(ofs);
00065 
00066   // Parse command-line:
00067   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00068 
00069   manager.start();
00070   LINFO("Testing the Hokuyo laser range finder");
00071 
00072   //declare a new laserRangeFinder object
00073   lobot::LaserRangeFinder* lrf = new lobot::LaserRangeFinder();
00074 
00075   Image<int> dists;
00076   Image<int>::iterator aptr, stop;
00077   float rad; int dist;
00078   int  min,max;
00079   int angle;
00080 
00081   while(true)
00082   {
00083       lrf->update();
00084       dists = lrf->get_distances();
00085       aptr = dists.beginw();
00086       stop = dists.endw();
00087       LDEBUG("dims= %d", dists.getDims().w());
00088 
00089       // some scaling
00090       getMinMax(dists, min, max);
00091       if (max == min) max = min + 1;
00092 
00093       angle = -141; int count = 0;
00094       Image<PixRGB<byte> > dispImg(512,512,ZEROS);
00095       while(aptr!=stop)
00096         {
00097           dist = *aptr++;
00098           rad = dist; rad = ((rad - min)/(max-min))*256;
00099           if (rad < 0) rad = 1.0;
00100 
00101           Point2D<int> pt;
00102           pt.i = 256 - int(rad*sin((double)angle*M_PI/180.0));
00103           pt.j = 256 - int(rad*cos((double)angle*M_PI/180.0));
00104 
00105           drawCircle(dispImg, pt, 2, PixRGB<byte>(255,0,0));
00106           drawLine(dispImg, Point2D<int>(256,256),pt,PixRGB<byte>(0,255,0));
00107 
00108           LDEBUG("[%4d] <%4d>: %13d mm", count, angle, dist);
00109           angle++; count++;
00110         }
00111       ofs->writeRGB(dispImg,"Output",FrameInfo("output",SRC_POS));
00112       usleep(200);
00113 
00114       //      std::copy(dists.begin(), dists.end(),
00115       //          std::ostream_iterator<int>(std::cout, " ")) ;
00116       //std::cout << '\n\n\n---------' ;
00117   }
00118 
00119   manager.stop();
00120   return 0;
00121 
00122 }
00123 
00124 
00125 
00126 // ######################################################################
00127 
00128 
00129 /* So things look consistent in everyone's emacs... */
00130 /* Local Variables: */
00131 /* indent-tabs-mode: nil */
00132 /* End: */
Generated on Sun May 8 08:40:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3