Go to the documentation of this file.00001 #include "firewire_camera_driver_nodelet.h"
00002 #include <pluginlib/class_list_macros.h>
00003
00004 FirewireCameraDriverNode::FirewireCameraDriverNode(ros::NodeHandle &nh) : iri_base_driver::IriBaseNodeDriver<FirewireCameraDriver>(nh), camera_manager(ros::NodeHandle(this->public_node_handle_)),
00005 it(new image_transport::ImageTransport(this->public_node_handle_)),Image_msg_(new sensor_msgs::Image)
00006 {
00007 std::string cal_file;
00008
00009
00010 this->loop_rate_ = 1000;
00011 this->desired_framerate=30.0;
00012 this->diagnosed_camera_image=NULL;
00013
00014 this->diagnosed_camera_image = new diagnostic_updater::HeaderlessTopicDiagnostic("camera_image",this->diagnostic_,
00015 diagnostic_updater::FrequencyStatusParam(&this->desired_framerate,&this->desired_framerate,0.01,5));
00016
00017 this->event_server=CEventServer::instance();
00018
00019
00020 this->camera_image_publisher_ = this->it->advertiseCamera("camera_image", 1);
00021
00022
00023 public_node_handle_.param<std::string>("left_cal_file", cal_file, "");
00024 if(this->camera_manager.validateURL(cal_file))
00025 {
00026 if(!this->camera_manager.loadCameraInfo(this->driver_.get_calibration_file()))
00027 ROS_INFO("Invalid calibration file");
00028 }
00029 else
00030 ROS_INFO("Invalid calibration file");
00031
00032 public_node_handle_.param<std::string>("tf_prefix", tf_prefix_, "");
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 }
00044
00045 void FirewireCameraDriverNode::mainNodeThread(void)
00046 {
00047 sensor_msgs::CameraInfoPtr camera_info(new sensor_msgs::CameraInfo(this->camera_manager.getCameraInfo()));
00048 std::list<std::string> events;
00049 char *image_data=NULL;
00050 TCameraConfig config;
00051
00052 try{
00053
00054 this->driver_.lock();
00055 if(this->driver_.isRunning())
00056 {
00057 this->new_frame_event=this->driver_.get_new_frame_event();
00058 if(this->new_frame_event!="")
00059 {
00060 events.push_back(this->new_frame_event);
00061 this->event_server->wait_all(events,1000);
00062 this->driver_.get_image(&image_data);
00063 if(image_data!=NULL && this->camera_image_publisher_.getNumSubscribers()>0)
00064 {
00065 this->driver_.get_current_config(&config);
00066
00067 this->desired_framerate=config.framerate;
00068
00069 this->Image_msg_->width=config.width;
00070 this->Image_msg_->height=config.height;
00071 this->Image_msg_->step=config.width*config.depth/8;
00072 this->Image_msg_->data=std::vector<unsigned char>(image_data,image_data+config.width*config.height*config.depth/8);
00073 if(config.coding==MONO || config.coding==RAW)
00074 {
00075 if(config.depth==DEPTH8)
00076 this->Image_msg_->encoding="8UC1";
00077 else if(config.depth==DEPTH16)
00078 this->Image_msg_->encoding="16UC1";
00079 else
00080 this->Image_msg_->encoding="16UC1";
00081 }
00082 else if(config.coding==YUV)
00083 {
00084 this->Image_msg_->encoding="yuv422";
00085 }
00086 else
00087 {
00088 if(config.depth==DEPTH24)
00089 this->Image_msg_->encoding="rgb8";
00090 else if(config.depth==DEPTH48)
00091 this->Image_msg_->encoding="16UC3";
00092 else
00093 this->Image_msg_->encoding="16UC3";
00094 }
00095 }
00096 delete[] image_data;
00097
00098 this->Image_msg_->header.stamp = ros::Time::now();
00099 this->Image_msg_->header.frame_id = tf_prefix_ + "/" + this->driver_.get_frame_id();
00100 camera_info->header.stamp = this->Image_msg_->header.stamp;
00101 camera_info->header.frame_id = tf_prefix_ + "/" + this->driver_.get_frame_id();
00102
00103 this->camera_image_publisher_.publish(this->Image_msg_,camera_info);
00104 this->diagnosed_camera_image->tick();
00105 }
00106 }
00107 this->driver_.unlock();
00108 }catch(CException &e){
00109 this->driver_.unlock();
00110 ROS_INFO("Impossible to capture frame");
00111 }
00112
00113 }
00114
00115
00116 void FirewireCameraDriverNode::check_configuration(diagnostic_updater::DiagnosticStatusWrapper &stat)
00117 {
00118 TCameraConfig desired_config;
00119 TCameraConfig current_config;
00120
00121 this->driver_.get_current_config(¤t_config);
00122 this->driver_.get_desired_config(&desired_config);
00123
00124 if(current_config.left_offset!=desired_config.left_offset)
00125 {
00126 stat.summary(1,"The current configuration differs from the desired configuration");
00127 stat.addf("Image left offset:","current value is %d,desired value is %d", current_config.left_offset,desired_config.left_offset);
00128 }
00129 else if(current_config.top_offset!=desired_config.top_offset)
00130 {
00131 stat.summary(1,"The current configuration differs from the desired configuration");
00132 stat.addf("Image top offset:","current value is %d,desired value is %d", current_config.top_offset,desired_config.top_offset);
00133 }
00134 else if(current_config.width!=desired_config.width)
00135 {
00136 stat.summary(1,"The current configuration differs from the desired configuration");
00137 stat.addf("Image width:","current value is %d,desired value is %d", current_config.width,desired_config.width);
00138 }
00139 else if(current_config.height!=desired_config.height)
00140 {
00141 stat.summary(1,"The current configuration differs from the desired configuration");
00142 stat.addf("Image height:","current value is %d,desired value is %d", current_config.height,desired_config.height);
00143 }
00144 else
00145 stat.summary(0,"The current configuration is okay");
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 void FirewireCameraDriverNode::postNodeOpenHook(void)
00157 {
00158 }
00159
00160 void FirewireCameraDriverNode::addNodeDiagnostics(void)
00161 {
00162 diagnostic_.add("Check Configuration", this, &FirewireCameraDriverNode::check_configuration);
00163 }
00164
00165 void FirewireCameraDriverNode::addNodeOpenedTests(void)
00166 {
00167 }
00168
00169 void FirewireCameraDriverNode::addNodeStoppedTests(void)
00170 {
00171 }
00172
00173 void FirewireCameraDriverNode::addNodeRunningTests(void)
00174 {
00175 }
00176
00177 void FirewireCameraDriverNode::reconfigureNodeHook(int level)
00178 {
00179
00180 if(this->camera_manager.validateURL(this->driver_.get_calibration_file()))
00181 {
00182 this->camera_manager.loadCameraInfo(this->driver_.get_calibration_file());
00183 }
00184 else
00185 ROS_INFO("Invalid calibration file");
00186 }
00187
00188 FirewireCameraDriverNode::~FirewireCameraDriverNode()
00189 {
00190
00191 if(this->diagnosed_camera_image!=NULL)
00192 {
00193 delete this->diagnosed_camera_image;
00194 this->diagnosed_camera_image=NULL;
00195 }
00196 }
00197
00198 #include "firewire_camera_driver_nodelet.h"
00199 #include <pluginlib/class_list_macros.h>
00200
00201 FirewireCameraNodelet::FirewireCameraNodelet()
00202 {
00203 this->dev=NULL;
00204
00205 this->thread_server=CThreadServer::instance();
00206 this->spin_thread_id="firewire_camera_driver_nodelet_spin";
00207 this->thread_server->create_thread(this->spin_thread_id);
00208 this->thread_server->attach_thread(this->spin_thread_id,this->spin_thread,this);
00209 }
00210
00211 void FirewireCameraNodelet::onInit()
00212 {
00213 ros::NodeHandle priv_nh(getPrivateNodeHandle());
00214 this->dev=new FirewireCameraDriverNode(priv_nh);
00215
00216 this->thread_server->start_thread(this->spin_thread_id);
00217 }
00218
00219 void *FirewireCameraNodelet::spin_thread(void *param)
00220 {
00221 FirewireCameraNodelet *nodelet=(FirewireCameraNodelet *)param;
00222
00223 nodelet->dev->spin();
00224
00225 pthread_exit(NULL);
00226 }
00227
00228 FirewireCameraNodelet::~FirewireCameraNodelet()
00229 {
00230
00231 this->thread_server->kill_thread(this->spin_thread_id);
00232 this->thread_server->detach_thread(this->spin_thread_id);
00233 this->thread_server->delete_thread(this->spin_thread_id);
00234 this->spin_thread_id="";
00235 if(this->dev!=NULL)
00236 delete this->dev;
00237 }
00238
00239
00240 PLUGINLIB_DECLARE_CLASS(iri_firewire_camera, iri_firewire_nodelet, FirewireCameraNodelet, nodelet::Nodelet);
00241