Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <avt_vimba_camera/mono_camera.h>
00034
00035 #define DEBUG_PRINTS 1
00036
00037 namespace avt_vimba_camera {
00038
00039 MonoCamera::MonoCamera(ros::NodeHandle nh, ros::NodeHandle nhp) : nh_(nh), nhp_(nhp), it_(nhp), cam_(ros::this_node::getName()) {
00040
00041
00042
00043
00044 api_.start();
00045
00046
00047 pub_ = it_.advertiseCamera("image_raw", 1);
00048
00049
00050 cam_.setCallback(boost::bind(&avt_vimba_camera::MonoCamera::frameCallback, this, _1));
00051
00052
00053 nhp_.param("ip", ip_, std::string(""));
00054 nhp_.param("guid", guid_, std::string(""));
00055 nhp_.param("camera_info_url", camera_info_url_, std::string(""));
00056 std::string frame_id;
00057 nhp_.param("frame_id", frame_id, std::string(""));
00058 nhp_.param("show_debug_prints", show_debug_prints_, false);
00059
00060
00061 info_man_ = boost::shared_ptr<camera_info_manager::CameraInfoManager>(new camera_info_manager::CameraInfoManager(nhp_, frame_id, camera_info_url_));
00062
00063
00064 reconfigure_server_.setCallback(boost::bind(&avt_vimba_camera::MonoCamera::configure, this, _1, _2));
00065 }
00066
00067 MonoCamera::~MonoCamera(void) {
00068 cam_.stop();
00069 pub_.shutdown();
00070 }
00071
00072 void MonoCamera::frameCallback(const FramePtr& vimba_frame_ptr) {
00073 ros::Time ros_time = ros::Time::now();
00074 if (pub_.getNumSubscribers() > 0) {
00075 sensor_msgs::Image img;
00076 if (api_.frameToImage(vimba_frame_ptr, img)) {
00077 sensor_msgs::CameraInfo ci = info_man_->getCameraInfo();
00078 ci.header.stamp = img.header.stamp = ros_time;
00079 img.header.frame_id = ci.header.frame_id;
00080 pub_.publish(img, ci);
00081 } else {
00082 ROS_WARN_STREAM("Function frameToImage returned 0. No image published.");
00083 }
00084 }
00085
00086 }
00087
00097 void MonoCamera::configure(Config& newconfig, uint32_t level) {
00098 try {
00099
00100 if (newconfig.frame_id == "") {
00101 newconfig.frame_id = "camera";
00102 }
00103
00104
00105 if (!cam_.isOpened()) {
00106 cam_.start(ip_, guid_, show_debug_prints_);
00107 }
00108
00109 Config config = newconfig;
00110 cam_.updateConfig(newconfig);
00111 updateCameraInfo(config);
00112 } catch (const std::exception& e) {
00113 ROS_ERROR_STREAM("Error reconfiguring mono_camera node : " << e.what());
00114 }
00115 }
00116
00117 void MonoCamera::updateCameraInfo(const avt_vimba_camera::AvtVimbaCameraConfig& config) {
00118
00119
00120 sensor_msgs::CameraInfo ci = info_man_->getCameraInfo();
00121
00122
00123 ci.header.frame_id = config.frame_id;
00124
00125
00126 int binning_or_decimation_x = std::max(config.binning_x, config.decimation_x);
00127 int binning_or_decimation_y = std::max(config.binning_y, config.decimation_y);
00128
00129
00130 ci.height = config.height;
00131 ci.width = config.width;
00132 ci.binning_x = binning_or_decimation_x;
00133 ci.binning_y = binning_or_decimation_y;
00134
00135
00136 ci.roi.x_offset = config.roi_offset_x;
00137 ci.roi.y_offset = config.roi_offset_y;
00138 ci.roi.height = config.roi_height;
00139 ci.roi.width = config.roi_width;
00140
00141
00142 std::string camera_info_url;
00143 nhp_.getParam("camera_info_url", camera_info_url);
00144 if (camera_info_url != camera_info_url_) {
00145 info_man_->setCameraName(config.frame_id);
00146 if (info_man_->validateURL(camera_info_url)) {
00147 info_man_->loadCameraInfo(camera_info_url);
00148 ci = info_man_->getCameraInfo();
00149 } else {
00150 ROS_WARN_STREAM("Camera info URL not valid: " << camera_info_url);
00151 }
00152 }
00153
00154 bool roiMatchesCalibration = (ci.height == config.roi_height
00155 && ci.width == config.roi_width);
00156 bool resolutionMatchesCalibration = (ci.width == config.width
00157 && ci.height == config.height);
00158
00159 ci.roi.do_rectify = roiMatchesCalibration || resolutionMatchesCalibration;
00160
00161
00162 info_man_->setCameraInfo(ci);
00163 }
00164
00165 };