gazebo_ros_camera.cpp
Go to the documentation of this file.
00001 /*
00002  *  Gazebo - Outdoor Multi-Robot Simulator
00003  *  Copyright (C) 2003
00004  *     Nate Koenig & Andrew Howard
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 /*
00022  @mainpage
00023    Desc: GazeboRosCamera plugin for simulating cameras in Gazebo
00024    Author: John Hsu
00025    Date: 24 Sept 2008
00026    SVN info: $Id$
00027  @htmlinclude manifest.html
00028  @b GazeboRosCamera plugin broadcasts ROS Image messages
00029  */
00030 
00031 #include <gazebo_plugins/gazebo_ros_camera.h>
00032 
00033 #include "sensors/Sensor.hh"
00034 #include "sensors/CameraSensor.hh"
00035 #include "sensors/SensorTypes.hh"
00036 
00037 namespace gazebo
00038 {
00039 
00041 // Constructor
00042 GazeboRosCamera::GazeboRosCamera()
00043 {
00044 }
00045 
00047 // Destructor
00048 GazeboRosCamera::~GazeboRosCamera()
00049 {
00050 }
00051 
00052 void GazeboRosCamera::Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf)
00053 {
00054   CameraPlugin::Load(_parent, _sdf);
00055   // copying from CameraPlugin into GazeboRosCameraUtils
00056   this->parentSensor_ = this->parentSensor;
00057   this->width_ = this->width;
00058   this->height_ = this->height;
00059   this->depth_ = this->depth;
00060   this->format_ = this->format;
00061   this->camera_ = this->camera;
00062   GazeboRosCameraUtils::Load(_parent, _sdf);
00063 }
00064 
00066 // Update the controller
00067 void GazeboRosCamera::OnNewFrame(const unsigned char *_image, 
00068     unsigned int _width, unsigned int _height, unsigned int _depth, 
00069     const std::string &_format)
00070 {
00071   this->sensor_update_time_ = this->parentSensor_->GetLastUpdateTime();
00072 
00073   if (!this->parentSensor->IsActive())
00074   {
00075     if (this->image_connect_count_ > 0)
00076       // do this first so there's chance for sensor to run 1 frame after activate
00077       this->parentSensor->SetActive(true);
00078   }
00079   else
00080   {
00081     if (this->image_connect_count_ > 0)
00082     {
00083       common::Time cur_time = this->world_->GetSimTime();
00084       if (cur_time - this->last_update_time_ >= this->update_period_)
00085       {
00086         this->PutCameraData(_image);
00087         this->last_update_time_ = cur_time;
00088       }
00089     }
00090   }
00091 }
00092 
00093 // Register this plugin with the simulator
00094 GZ_REGISTER_SENSOR_PLUGIN(GazeboRosCamera)
00095 
00096 }


gazebo_plugins
Author(s): Sachin Chitta, Stu Glaser, John Hsu
autogenerated on Sun Jan 5 2014 11:34:58