Skip to content

Commit 2b6cfe8

Browse files
committed
Adding setting for gain, fixing vector size print warning, renaming Node value functions
1 parent 040e77a commit 2b6cfe8

File tree

6 files changed

+105
-48
lines changed

6 files changed

+105
-48
lines changed

include/spinnaker_sdk_camera_driver/camera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ namespace acquisition {
5959
// void setTrigMode();
6060
// void setTriggerOverlapOff();
6161

62-
string get_node_value(string node_string);
62+
string getTLNodeStringValue(string node_string);
63+
double getFloatValueMax(string node_string);
6364
string get_id();
6465
void make_master() { MASTER_ = true; ROS_DEBUG_STREAM( "camera " << get_id() << " set as master"); }
6566
bool is_master() { return MASTER_; }

include/spinnaker_sdk_camera_driver/capture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ namespace acquisition {
115115
string dump_img_;
116116
string ext_;
117117
float exposure_time_;
118+
float gain_;
118119
double target_grey_value_;
119120
bool first_image_received;
120121
// int decimation_;

launch/acquisition.launch

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33
<env name="ROSCONSOLE_CONFIG_FILE" value="$(find spinnaker_sdk_camera_driver)/cfg/std_console.conf"/>
44

55
<!-- acquisition spinnaker params-->
6-
<arg name="binning" default="1" doc="Binning for cameras, when changing from 2 to 1 cameras need to be unplugged and replugged"/>
7-
<arg name="color" default="false" doc="Should color images be used (only works on models that support color images)"/>
8-
<arg name="exposure_time" default="0" doc="Exposure_time setting for cameras"/>
9-
<arg name="external_trigger" default="false" doc="External trigger (No camera is master)"/>
10-
<arg name="target_grey_value" default="0" doc="AutoExposureTargetGreyValue min: 4 max: 99 if set below 4, AutoExposureTargetGreyValueAuto will be set to continuous(auto) also available as dynamic reconfigurable parameter" />
11-
<arg name="frames" default="3400" doc="Numer of frames to save/view 0=ON"/>
12-
<arg name="live" default="false" doc="Show images on screen GUI"/>
13-
<arg name="live_grid" default="false" doc="Show images on screen GUI in a grid"/>
14-
<arg name="output" default="screen" doc="display output to screen or log file"/>
15-
<arg name="save" default="false" doc="flag whether images should be saved or not"/>
16-
<arg name="save_path" default="~" doc="location to save the image data"/>
17-
<arg name="save_type" default="bmp" doc="Type of file type to save to when saving images locally: binary, tiff, bmp, jpeg etc." />
18-
<arg name="soft_framerate" default="30" doc="When hybrid software triggering is used, this controls the FPS, 0=as fast as possible"/>
19-
<arg name="time" default="false" doc="Show time/FPS on output"/>
20-
<arg name="to_ros" default="true" doc="Flag whether images should be published to ROS" />
21-
<arg name="utstamps" default="false" doc="Flag whether each image should have Unique timestamps vs the master cams time stamp for all" />
22-
<arg name="max_rate_save" default="false" doc="Flag for max rate mode which is when the master triggerst the slaves and saves images at maximum rate possible" />
6+
<arg name="binning" default="1" doc="Binning for cameras, when changing from 2 to 1 cameras need to be unplugged and replugged"/>
7+
<arg name="color" default="false" doc="Should color images be used (only works on models that support color images)"/>
8+
<arg name="exposure_time" default="0" doc="Exposure_time setting for cameras"/>
9+
<arg name="external_trigger" default="false" doc="External trigger (No camera is master)"/>
10+
<arg name="gain" default="0" doc="Gain setting. Gain should be positive (full range - 0 - 18 dB for blackfly-s camera)
11+
or zero (auto gain). if gain > max, it will be set to max allowed value.
12+
Default is 0, auto gain which is set according to target grey value or autoexposure settings"/>
13+
<arg name="target_grey_value" default="0" doc="AutoExposureTargetGreyValue min: 4 max: 99 if set below 4,
14+
AutoExposureTargetGreyValueAuto will be set to continuous(auto)
15+
also available as dynamic reconfigurable parameter.
16+
This parameter has no meaning when auto exposure and auto gain are off" />
17+
<arg name="frames" default="3400" doc="Numer of frames to save/view 0=ON"/>
18+
<arg name="live" default="false" doc="Show images on screen GUI"/>
19+
<arg name="live_grid" default="false" doc="Show images on screen GUI in a grid"/>
20+
<arg name="output" default="screen" doc="display output to screen or log file"/>
21+
<arg name="save" default="false" doc="flag whether images should be saved or not"/>
22+
<arg name="save_path" default="~" doc="location to save the image data"/>
23+
<arg name="save_type" default="bmp" doc="Type of file type to save to when saving images locally: binary, tiff, bmp, jpeg etc." />
24+
<arg name="soft_framerate" default="30" doc="When hybrid software triggering is used, this controls the FPS, 0=as fast as possible"/>
25+
<arg name="time" default="false" doc="Show time/FPS on output"/>
26+
<arg name="to_ros" default="true" doc="Flag whether images should be published to ROS" />
27+
<arg name="utstamps" default="false" doc="Flag whether each image should have Unique timestamps vs the master cams time stamp for all" />
28+
<arg name="max_rate_save" default="false" doc="Flag for max rate mode which is when the master triggerst the slaves and saves images at maximum rate possible" />
2329

2430

2531
<!-- nodelet manager params-->
@@ -29,7 +35,7 @@
2935

3036
<!-- Capture nodelet params-->
3137
<arg name="tf_prefix" default="" doc="will prefix (arg tf_prefix)/ to existing frame_id in Image msg and camerainfo msg" />
32-
<arg name="config_file" default="$(find spinnaker_sdk_camera_driver)/params/test_params.yaml" doc="File specifying the parameters of the camera_array"/>
38+
<arg name="config_file" default="$(find spinnaker_sdk_camera_driver)/params/test_params.yaml" doc="File specifying the parameters of the camera_array"/>
3339

3440
<!-- start the nodelet manager if $(arg start_nodelet_manager) is true-->
3541
<node pkg="nodelet" type="nodelet" name="$(arg manager)" args="manager" output="screen" unless="$(arg external_manager)" />
@@ -38,12 +44,13 @@
3844
<node pkg="nodelet" type="nodelet" name="acquisition_node"
3945
args="load acquisition/Capture $(arg manager)" >
4046
<!-- load the acquisition node parameters file. Note any parameters provided in this file will
41-
override what is in the yaml file. Thus use it to set parameters camer_array configuration params -->
47+
override what is in the yaml file. Thus use it to set parameters camer_array configuration params -->
4248
<rosparam command="load" file="$(arg config_file)" />
4349

4450
<!-- Load parameters onto server using argument or default values above -->
4551
<param name="exposure_time" value="$(arg exposure_time)" />
4652
<param name="external_trigger" value="$(arg external_trigger)" />
53+
<param name="gain" value="$(arg gain)"/>
4754
<param name="target_grey_value" value="$(arg target_grey_value)" />
4855
<param name="binning" value="$(arg binning)" />
4956
<param name="color" value="$(arg color)" />

launch/acquisition_external_trigger.launch

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33
<env name="ROSCONSOLE_CONFIG_FILE" value="$(find spinnaker_sdk_camera_driver)/cfg/std_console.conf"/>
44

55
<!-- acquisition spinnaker params-->
6-
<arg name="binning" default="1" doc="Binning for cameras, when changing from 2 to 1 cameras need to be unplugged and replugged"/>
7-
<arg name="color" default="false" doc="Should color images be used (only works on models that support color images)"/>
8-
<arg name="exposure_time" default="0" doc="Exposure_time setting for cameras"/>
9-
<arg name="external_trigger" default="true" doc="External trigger (No camera is master)"/>
10-
<arg name="target_grey_value" default="0" doc="AutoExposureTargetGreyValue min: 4 max: 99 if set below 4, AutoExposureTargetGreyValueAuto will be set to continuous(auto) also available as dynamic reconfigurable parameter" />
11-
<arg name="frames" default="3400" doc="Numer of frames to save/view 0=ON"/>
12-
<arg name="live" default="false" doc="Show images on screen GUI"/>
13-
<arg name="live_grid" default="false" doc="Show images on screen GUI in a grid"/>
14-
<arg name="output" default="screen" doc="display output to screen or log file"/>
15-
<arg name="save" default="false" doc="flag whether images should be saved or not"/>
16-
<arg name="save_path" default="/media/jagatpreet/Data/datasets/vio_rosbags/vio_rig/dummy" doc="location to save the image data"/>
17-
<arg name="save_type" default="bmp" doc="Type of file type to save to when saving images locally: binary, tiff, bmp, jpeg etc." />
18-
<arg name="soft_framerate" default="30" doc="When hybrid software triggering is used, this controls the FPS, 0=as fast as possible"/>
19-
<arg name="time" default="false" doc="Show time/FPS on output"/>
20-
<arg name="to_ros" default="true" doc="Flag whether images should be published to ROS" />
21-
<arg name="utstamps" default="false" doc="Flag whether each image should have Unique timestamps vs the master cams time stamp for all" />
22-
<arg name="max_rate_save" default="false" doc="Flag for max rate mode which is when the master triggerst the slaves and saves images at maximum rate possible" />
6+
<arg name="binning" default="1" doc="Binning for cameras, when changing from 2 to 1 cameras need to be unplugged and replugged"/>
7+
<arg name="color" default="false" doc="Should color images be used (only works on models that support color images)"/>
8+
<arg name="exposure_time" default="0" doc="Exposure_time setting for cameras"/>
9+
<arg name="external_trigger" default="true" doc="External trigger (No camera is master)"/>
10+
<arg name="gain" default="0" doc="Gain setting. Gain should be positive (full range - 0 - 18 dB for blackfly-s camera)
11+
or zero (auto gain). if gain > max, it will be set to max allowed value.
12+
Default is 0, auto gain which is set according to target grey value or autoexposure settings"/>
13+
<arg name="target_grey_value" default="0" doc="AutoExposureTargetGreyValue min: 4 max: 99 if set below 4,
14+
AutoExposureTargetGreyValueAuto will be set to continuous(auto)
15+
also available as dynamic reconfigurable parameter.
16+
This parameter has no meaning when auto exposure and auto gain are off" />
17+
<arg name="frames" default="3400" doc="Numer of frames to save/view 0=ON"/>
18+
<arg name="live" default="false" doc="Show images on screen GUI"/>
19+
<arg name="live_grid" default="false" doc="Show images on screen GUI in a grid"/>
20+
<arg name="output" default="screen" doc="display output to screen or log file"/>
21+
<arg name="save" default="false" doc="flag whether images should be saved or not"/>
22+
<arg name="save_path" default="~" doc="location to save the image data"/>
23+
<arg name="save_type" default="bmp" doc="Type of file type to save to when saving images locally: binary, tiff, bmp, jpeg etc." />
24+
<arg name="soft_framerate" default="30" doc="When hybrid software triggering is used, this controls the FPS, 0=as fast as possible"/>
25+
<arg name="time" default="false" doc="Show time/FPS on output"/>
26+
<arg name="to_ros" default="true" doc="Flag whether images should be published to ROS" />
27+
<arg name="utstamps" default="false" doc="Flag whether each image should have Unique timestamps vs the master cams time stamp for all" />
28+
<arg name="max_rate_save" default="false" doc="Flag for max rate mode which is when the master triggerst the slaves and saves images at maximum rate possible" />
2329

2430

2531
<!-- nodelet manager params-->
@@ -29,21 +35,22 @@
2935

3036
<!-- Capture nodelet params-->
3137
<arg name="tf_prefix" default="" doc="will prefix (arg tf_prefix)/ to existing frame_id in Image msg and camerainfo msg" />
32-
<arg name="config_file" default="$(find spinnaker_sdk_camera_driver)/params/external_trigger_params.yaml" doc="File specifying the parameters of the camera_array"/>
38+
<arg name="config_file" default="$(find spinnaker_sdk_camera_driver)/params/external_trigger_params.yaml" doc="File specifying the parameters of the camera_array"/>
3339

34-
<!-- start the nodelet manager if $(arg start_nodelet_manager) is true-->
40+
<!-- start the nodelet manager if $(arg start_nodelet_manager) is true-->
3541
<node pkg="nodelet" type="nodelet" name="$(arg manager)" args="manager" output="screen" unless="$(arg external_manager)" />
3642

3743
<!-- load the acquisition nodelet -->
3844
<node pkg="nodelet" type="nodelet" name="acquisition_node"
3945
args="load acquisition/Capture $(arg manager)" >
4046
<!-- load the acquisition node parameters file. Note any parameters provided in this file will
41-
override what is in the yaml file. Thus use it to set parameters camer_array configuration params -->
47+
override what is in the yaml file. Thus use it to set parameters camer_array configuration params -->
4248
<rosparam command="load" file="$(arg config_file)" />
4349

4450
<!-- Load parameters onto server using argument or default values above -->
4551
<param name="exposure_time" value="$(arg exposure_time)" />
46-
<param name="external_trigger" value="$(arg external_trigger)" />
52+
<param name="external_trigger" value="$(arg external_trigger)" />
53+
<param name="gain" value="$(arg gain)"/>
4754
<param name="target_grey_value" value="$(arg target_grey_value)" />
4855
<param name="binning" value="$(arg binning)" />
4956
<param name="color" value="$(arg color)" />

src/camera.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,34 @@ void acquisition::Camera::trigger() {
306306

307307
}
308308

309-
string acquisition::Camera::get_node_value(string node_string) {
309+
double acquisition::Camera::getFloatValueMax(string node_string) {
310+
INodeMap& nodeMap = pCam_->GetNodeMap();
311+
312+
CFloatPtr ptrNodeValue = nodeMap.GetNode(node_string.c_str());
313+
314+
if (IsAvailable(ptrNodeValue)){
315+
//cout << "\tMax " << ptrNodeValue->GetValue() << "..." << endl;
316+
return ptrNodeValue->GetMax();
317+
} else {
318+
ROS_FATAL_STREAM("Node " << node_string << " not available" << endl);
319+
return -1;
320+
}
321+
}
322+
323+
324+
string acquisition::Camera::getTLNodeStringValue(string node_string) {
310325
INodeMap& nodeMap = pCam_->GetTLDeviceNodeMap();
311326
CStringPtr ptrNodeValue = nodeMap.GetNode(node_string.c_str());
312327
if (IsReadable(ptrNodeValue)){
313328
return string(ptrNodeValue->GetValue());
329+
} else{
330+
ROS_FATAL_STREAM("Node " << node_string << " not readable" << endl);
331+
return "";
314332
}
315-
return "";
316333
}
317334

318335
string acquisition::Camera::get_id() {
319-
return get_node_value("DeviceSerialNumber");
336+
return getTLNodeStringValue("DeviceSerialNumber");
320337
}
321338

322339
void acquisition::Camera::targetGreyValueTest() {

src/capture.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void acquisition::Capture::init_variables_register_to_ros() {
8080
// default values for the parameters are set here. Should be removed eventually!!
8181
exposure_time_ = 0 ; // default as 0 = auto exposure
8282
soft_framerate_ = 20; //default soft framrate
83+
gain_ = 0;
8384
ext_ = ".bmp";
8485
SOFT_FRAME_RATE_CTRL_ = false;
8586
LIVE_ = false;
@@ -187,8 +188,8 @@ void acquisition::Capture::load_cameras() {
187188
for (int i=0; i<numCameras_; i++) {
188189
acquisition::Camera cam(camList_.GetByIndex(i));
189190
ROS_INFO_STREAM(" -"<< cam.get_id()
190-
<<" "<< cam.get_node_value("DeviceModelName")
191-
<<" "<< cam.get_node_value("DeviceVersion") );
191+
<<" "<< cam.getTLNodeStringValue("DeviceModelName")
192+
<<" "<< cam.getTLNodeStringValue("DeviceVersion") );
192193
}
193194

194195
bool master_set = false;
@@ -474,6 +475,14 @@ void acquisition::Capture::read_parameters() {
474475
else ROS_INFO(" 'exposure_time'=%0.f, Setting autoexposure",exposure_time_);
475476
} else ROS_WARN(" 'exposure_time' Parameter not set, using default behavior: Automatic Exposure ");
476477

478+
if(nh_pvt_.getParam("gain", gain_)){
479+
if(gain_>0){
480+
ROS_INFO("gain value set to:%.1f",gain_);
481+
}
482+
else ROS_INFO(" 'gain' Parameter was zero or negative, using Auto gain based on target grey value");
483+
}
484+
else ROS_WARN(" 'gain' Parameter not set, using default behavior: Auto gain based on target grey value");
485+
477486
if (nh_pvt_.getParam("target_grey_value", target_grey_value_)){
478487
if (target_grey_value_ >0) ROS_INFO(" target_grey_value set to: %.1f",target_grey_value_);
479488
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) {
694703
} else {
695704
cams[i].setEnumValue("ExposureAuto", "Continuous");
696705
}
706+
707+
if(gain_>0){ //fixed gain
708+
cams[i].setEnumValue("GainAuto", "Off");
709+
double max_gain_allowed = cams[i].getFloatValueMax("Gain");
710+
if (gain_ <= max_gain_allowed)
711+
cams[i].setFloatValue("Gain", gain_);
712+
else {
713+
cams[i].setFloatValue("Gain", max_gain_allowed);
714+
ROS_WARN("Provided Gain value is higher than max allowed, setting gain to %f", max_gain_allowed);
715+
}
716+
target_grey_value_ = 50;
717+
} else {
718+
cams[i].setEnumValue("GainAuto","Continuous");
719+
}
720+
697721
if (target_grey_value_ > 4.0) {
698722
cams[i].setEnumValue("AutoExposureTargetGreyValueAuto", "Off");
699723
cams[i].setFloatValue("AutoExposureTargetGreyValue", target_grey_value_);
@@ -706,7 +730,7 @@ void acquisition::Capture::init_cameras(bool soft = false) {
706730
// cams[i].setFloatValue("AcquisitionFrameRate", 5.0);
707731

708732
if (color_)
709-
cams[i].setEnumValue("PixelFormat", "BGR8");
733+
cams[i].setEnumValue("PixelFormat", "BGR8");
710734
else
711735
cams[i].setEnumValue("PixelFormat", "Mono8");
712736
cams[i].setEnumValue("AcquisitionMode", "Continuous");
@@ -1230,7 +1254,7 @@ void acquisition::Capture::write_queue_to_disk(queue<ImagePtr>* img_q, int cam_n
12301254
convertedImage->Save(filename.str().c_str());
12311255
// release the image before popping out to save memory
12321256
convertedImage->Release();
1233-
ROS_INFO("image Queue size for cam %d is = %d",cam_no,img_q->size());
1257+
ROS_INFO("image Queue size for cam %d is = %zu",cam_no, img_q->size());
12341258
queue_mutex_.lock();
12351259
img_q->pop();
12361260
queue_mutex_.unlock();

0 commit comments

Comments
 (0)