From 2b6cfe8f5cd387b472252291b2a14c4cb00f001d Mon Sep 17 00:00:00 2001 From: Vikrant Shah Date: Thu, 4 Feb 2021 15:09:17 -0500 Subject: [PATCH] Adding setting for gain, fixing vector size print warning, renaming Node value functions --- include/spinnaker_sdk_camera_driver/camera.h | 3 +- include/spinnaker_sdk_camera_driver/capture.h | 1 + launch/acquisition.launch | 45 ++++++++++------- launch/acquisition_external_trigger.launch | 49 +++++++++++-------- src/camera.cpp | 23 +++++++-- src/capture.cpp | 32 ++++++++++-- 6 files changed, 105 insertions(+), 48 deletions(-) diff --git a/include/spinnaker_sdk_camera_driver/camera.h b/include/spinnaker_sdk_camera_driver/camera.h index 750b9f8..13af81b 100755 --- a/include/spinnaker_sdk_camera_driver/camera.h +++ b/include/spinnaker_sdk_camera_driver/camera.h @@ -59,7 +59,8 @@ namespace acquisition { // void setTrigMode(); // void setTriggerOverlapOff(); - string get_node_value(string node_string); + string getTLNodeStringValue(string node_string); + double getFloatValueMax(string node_string); string get_id(); void make_master() { MASTER_ = true; ROS_DEBUG_STREAM( "camera " << get_id() << " set as master"); } bool is_master() { return MASTER_; } diff --git a/include/spinnaker_sdk_camera_driver/capture.h b/include/spinnaker_sdk_camera_driver/capture.h index 8e1e817..a71436d 100755 --- a/include/spinnaker_sdk_camera_driver/capture.h +++ b/include/spinnaker_sdk_camera_driver/capture.h @@ -115,6 +115,7 @@ namespace acquisition { string dump_img_; string ext_; float exposure_time_; + float gain_; double target_grey_value_; bool first_image_received; // int decimation_; diff --git a/launch/acquisition.launch b/launch/acquisition.launch index 8d8fd31..33a5093 100644 --- a/launch/acquisition.launch +++ b/launch/acquisition.launch @@ -3,23 +3,29 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -29,7 +35,7 @@ - + @@ -38,12 +44,13 @@ + override what is in the yaml file. Thus use it to set parameters camer_array configuration params --> + diff --git a/launch/acquisition_external_trigger.launch b/launch/acquisition_external_trigger.launch index 682c11d..ae636d3 100644 --- a/launch/acquisition_external_trigger.launch +++ b/launch/acquisition_external_trigger.launch @@ -3,23 +3,29 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -29,21 +35,22 @@ - + - + + override what is in the yaml file. Thus use it to set parameters camer_array configuration params --> - + + diff --git a/src/camera.cpp b/src/camera.cpp index b83a339..9b7010c 100755 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -306,17 +306,34 @@ void acquisition::Camera::trigger() { } -string acquisition::Camera::get_node_value(string node_string) { +double acquisition::Camera::getFloatValueMax(string node_string) { + INodeMap& nodeMap = pCam_->GetNodeMap(); + + CFloatPtr ptrNodeValue = nodeMap.GetNode(node_string.c_str()); + + if (IsAvailable(ptrNodeValue)){ + //cout << "\tMax " << ptrNodeValue->GetValue() << "..." << endl; + return ptrNodeValue->GetMax(); + } else { + ROS_FATAL_STREAM("Node " << node_string << " not available" << endl); + return -1; + } +} + + +string acquisition::Camera::getTLNodeStringValue(string node_string) { INodeMap& nodeMap = pCam_->GetTLDeviceNodeMap(); CStringPtr ptrNodeValue = nodeMap.GetNode(node_string.c_str()); if (IsReadable(ptrNodeValue)){ return string(ptrNodeValue->GetValue()); + } else{ + ROS_FATAL_STREAM("Node " << node_string << " not readable" << endl); + return ""; } - return ""; } string acquisition::Camera::get_id() { - return get_node_value("DeviceSerialNumber"); + return getTLNodeStringValue("DeviceSerialNumber"); } void acquisition::Camera::targetGreyValueTest() { diff --git a/src/capture.cpp b/src/capture.cpp index 842a340..c662f9e 100755 --- a/src/capture.cpp +++ b/src/capture.cpp @@ -80,6 +80,7 @@ void acquisition::Capture::init_variables_register_to_ros() { // default values for the parameters are set here. Should be removed eventually!! exposure_time_ = 0 ; // default as 0 = auto exposure soft_framerate_ = 20; //default soft framrate + gain_ = 0; ext_ = ".bmp"; SOFT_FRAME_RATE_CTRL_ = false; LIVE_ = false; @@ -187,8 +188,8 @@ void acquisition::Capture::load_cameras() { for (int i=0; i0){ + ROS_INFO("gain value set to:%.1f",gain_); + } + else ROS_INFO(" 'gain' Parameter was zero or negative, using Auto gain based on target grey value"); + } + else ROS_WARN(" 'gain' Parameter not set, using default behavior: Auto gain based on target grey value"); + if (nh_pvt_.getParam("target_grey_value", target_grey_value_)){ if (target_grey_value_ >0) ROS_INFO(" target_grey_value set to: %.1f",target_grey_value_); else ROS_INFO(" 'target_grey_value'=%0.f, Setting AutoExposureTargetGreyValueAuto to Continuous/ auto",target_grey_value_);} @@ -694,6 +703,21 @@ void acquisition::Capture::init_cameras(bool soft = false) { } else { cams[i].setEnumValue("ExposureAuto", "Continuous"); } + + if(gain_>0){ //fixed gain + cams[i].setEnumValue("GainAuto", "Off"); + double max_gain_allowed = cams[i].getFloatValueMax("Gain"); + if (gain_ <= max_gain_allowed) + cams[i].setFloatValue("Gain", gain_); + else { + cams[i].setFloatValue("Gain", max_gain_allowed); + ROS_WARN("Provided Gain value is higher than max allowed, setting gain to %f", max_gain_allowed); + } + target_grey_value_ = 50; + } else { + cams[i].setEnumValue("GainAuto","Continuous"); + } + if (target_grey_value_ > 4.0) { cams[i].setEnumValue("AutoExposureTargetGreyValueAuto", "Off"); cams[i].setFloatValue("AutoExposureTargetGreyValue", target_grey_value_); @@ -706,7 +730,7 @@ void acquisition::Capture::init_cameras(bool soft = false) { // cams[i].setFloatValue("AcquisitionFrameRate", 5.0); if (color_) - cams[i].setEnumValue("PixelFormat", "BGR8"); + cams[i].setEnumValue("PixelFormat", "BGR8"); else cams[i].setEnumValue("PixelFormat", "Mono8"); cams[i].setEnumValue("AcquisitionMode", "Continuous"); @@ -1230,7 +1254,7 @@ void acquisition::Capture::write_queue_to_disk(queue* img_q, int cam_n convertedImage->Save(filename.str().c_str()); // release the image before popping out to save memory convertedImage->Release(); - ROS_INFO("image Queue size for cam %d is = %d",cam_no,img_q->size()); + ROS_INFO("image Queue size for cam %d is = %zu",cam_no, img_q->size()); queue_mutex_.lock(); img_q->pop(); queue_mutex_.unlock();