nodelet.cpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*********************************************************************
00004 * Software License Agreement (BSD License)
00005 *
00006 *  Copyright (c) 2010 Jack O'Quin, 2013 Séverin Lemaignan
00007 *  All rights reserved.
00008 *
00009 *  Redistribution and use in source and binary forms, with or without
00010 *  modification, are permitted provided that the following conditions
00011 *  are met:
00012 *
00013 *   * Redistributions of source code must retain the above copyright
00014 *     notice, this list of conditions and the following disclaimer.
00015 *   * Redistributions in binary form must reproduce the above
00016 *     copyright notice, this list of conditions and the following
00017 *     disclaimer in the documentation and/or other materials provided
00018 *     with the distribution.
00019 *   * Neither the name of the author nor other contributors may be
00020 *     used to endorse or promote products derived from this software
00021 *     without specific prior written permission.
00022 *
00023 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034 *  POSSIBILITY OF SUCH DAMAGE.
00035 *********************************************************************/
00036 
00037 #include <signal.h>
00038 
00039 #include <boost/thread.hpp>
00040 
00041 #include <ros/ros.h>
00042 #include <pluginlib/class_list_macros.h>
00043 #include <nodelet/nodelet.h>
00044 
00045 #include "nao_camera.h"
00046 
00054 class NaoCameraNodelet: public nodelet::Nodelet
00055 {
00056 public:
00057   NaoCameraNodelet():
00058     running_(false)
00059   {}
00060 
00061   ~NaoCameraNodelet()
00062   {
00063     if (running_)
00064       {
00065         NODELET_INFO("shutting down driver thread");
00066         running_ = false;
00067         deviceThread_->join();
00068         NODELET_INFO("driver thread stopped");
00069       }
00070     dvr_->shutdown();
00071   }
00072 
00073 private:
00074   virtual void onInit();
00075   virtual void devicePoll();
00076 
00077   volatile bool running_;               
00078   boost::shared_ptr<naocamera_driver::NaoCameraDriver> dvr_;
00079   boost::shared_ptr<boost::thread> deviceThread_;
00080 };
00081 
00086 void NaoCameraNodelet::onInit()
00087 {
00088   ros::NodeHandle priv_nh(getPrivateNodeHandle());
00089   ros::NodeHandle node(getNodeHandle());
00090   ros::NodeHandle camera_nh(node, "camera");
00091   //TODO: allow for passing host/port of broker!
00092   int argc = 0;
00093   char* argv = "";
00094   dvr_.reset(new naocamera_driver::NaoCameraDriver(argc, &argv, priv_nh, camera_nh));
00095   dvr_->setup();
00096 
00097   // spawn device thread
00098   running_ = true;
00099   deviceThread_ = boost::shared_ptr< boost::thread >
00100     (new boost::thread(boost::bind(&NaoCameraNodelet::devicePoll, this)));
00101 }
00102 
00104 void NaoCameraNodelet::devicePoll()
00105 {
00106   while (running_)
00107     {
00108       dvr_->poll();
00109     }
00110 }
00111 
00112 // Register this plugin with pluginlib.  Names must match nodelet_velodyne.xml.
00113 //
00114 // parameters are: package, class name, class type, base class type
00115 PLUGINLIB_DECLARE_CLASS(naocamera, driver,
00116                         NaoCameraNodelet, nodelet::Nodelet);


nao_sensors
Author(s): Séverin Lemaignan, Vincent Rabaud, Karsten Knese, Jack O'Quin, Ken Tossell, Patrick Beeson, Nate Koenig, Andrew Howard, Damien Douxchamps, Dan Dennedy, Daniel Maier
autogenerated on Mon Oct 6 2014 02:40:25