hdl_grabber_example.cpp
Go to the documentation of this file.
00001 /*
00002  * hdl_grabber_example.cpp
00003  *
00004  *  Created on: Nov 29, 2012
00005  *      Author: keven
00006  */
00007 
00008 #include <string>
00009 #include <iostream>
00010 #include <iomanip>
00011 
00012 #include <pcl/io/hdl_grabber.h>
00013 #include <pcl/console/parse.h>
00014 #include <pcl/common/time.h>
00015 
00016 class SimpleHDLGrabber 
00017 {
00018   public:
00019     std::string calibrationFile, pcapFile;
00020 
00021     SimpleHDLGrabber (std::string& calibFile, std::string& pcapFile) 
00022       : calibrationFile (calibFile)
00023       , pcapFile (pcapFile) 
00024     {
00025     }
00026 
00027     void 
00028     sectorScan (
00029         const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&, 
00030         float,
00031         float) 
00032     {
00033       static unsigned count = 0;
00034       static double last = pcl::getTime ();
00035       if (++count == 30) 
00036       {
00037         double now = pcl::getTime();
00038         std::cout << "got sector scan.  Avg Framerate " << double(count) / double(now - last) << " Hz" << std::endl;
00039         count = 0;
00040         last = now;
00041       }
00042     }
00043 
00044     void 
00045     sweepScan (
00046         const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >& sweep)
00047     {
00048       static unsigned count = 0;
00049       static double last = pcl::getTime();
00050 
00051       if (sweep->header.seq == 0) {
00052         pcl::uint64_t stamp;
00053         stamp = sweep->header.stamp;
00054         time_t systemTime = static_cast<time_t>(((stamp & 0xffffffff00000000l) >> 32) & 0x00000000ffffffff);
00055         pcl::uint32_t usec = static_cast<pcl::uint32_t>(stamp & 0x00000000ffffffff);
00056         std::cout << std::hex << stamp << "  " << ctime(&systemTime) << " usec: " << usec << std::endl;
00057       }
00058 
00059       if (++count == 30) 
00060       {
00061         double now = pcl::getTime ();
00062         std::cout << "got sweep.  Avg Framerate " << double(count) / double(now - last) << " Hz" << std::endl;
00063         count = 0;
00064         last = now;
00065       }
00066     }
00067 
00068     void 
00069     run () 
00070     {
00071       pcl::HDLGrabber interface (calibrationFile, pcapFile);
00072       // make callback function from member function
00073       boost::function<void(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&, float, float)> f =
00074           boost::bind(&SimpleHDLGrabber::sectorScan, this, _1, _2, _3);
00075 
00076       // connect callback function for desired signal. In this case its a sector with XYZ and intensity information
00077       //boost::signals2::connection c = interface.registerCallback(f);
00078 
00079       // Register a callback function that gets complete 360 degree sweeps.
00080       boost::function<void(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&)> f2 = boost::bind(
00081           &SimpleHDLGrabber::sweepScan, this, _1);
00082       boost::signals2::connection c2 = interface.registerCallback(f2);
00083 
00084       //interface.filterPackets(boost::asio::ip::address_v4::from_string("192.168.18.38"));
00085 
00086       // start receiving point clouds
00087       interface.start ();
00088 
00089       std::cout << "<Esc>, \'q\', \'Q\': quit the program" << std::endl;
00090       char key;
00091       do 
00092       {
00093         key = static_cast<char> (getchar ());
00094       } while (key != 27 && key != 'q' && key != 'Q');
00095 
00096       // stop the grabber
00097       interface.stop ();
00098     }
00099 };
00100 
00101 int 
00102 main (int argc, char **argv) 
00103 {
00104         std::string hdlCalibration, pcapFile;
00105 
00106         pcl::console::parse_argument (argc, argv, "-calibrationFile", hdlCalibration);
00107         pcl::console::parse_argument (argc, argv, "-pcapFile", pcapFile);
00108 
00109         SimpleHDLGrabber grabber (hdlCalibration, pcapFile);
00110         grabber.run ();
00111         return (0);
00112 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:24:42