|
| 1 | +/** |
| 2 | +Software License Agreement (BSD) |
| 3 | +
|
| 4 | +\file gh3.cpp |
| 5 | +\authors Michael Hosmar <[email protected]> |
| 6 | +\copyright Copyright (c) 2018, Clearpath Robotics, Inc., All rights reserved. |
| 7 | +
|
| 8 | +Redistribution and use in source and binary forms, with or without modification, are permitted provided that |
| 9 | +the following conditions are met: |
| 10 | + * Redistributions of source code must retain the above copyright notice, this list of conditions and the |
| 11 | + following disclaimer. |
| 12 | + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the |
| 13 | + following disclaimer in the documentation and/or other materials provided with the distribution. |
| 14 | + * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or promote |
| 15 | + products derived from this software without specific prior written permission. |
| 16 | +
|
| 17 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WAR- |
| 18 | +RANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 19 | +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN- |
| 20 | +DIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| 21 | +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | +*/ |
| 25 | +#include "spinnaker_camera_driver/gh3.h" |
| 26 | + |
| 27 | +#include <string> |
| 28 | + |
| 29 | +namespace spinnaker_camera_driver |
| 30 | +{ |
| 31 | +Gh3::Gh3(Spinnaker::GenApi::INodeMap* node_map) : Camera(node_map) |
| 32 | +{ |
| 33 | +} |
| 34 | + |
| 35 | +Gh3::~Gh3() |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +void Gh3::setFrameRate(const float frame_rate) |
| 40 | +{ |
| 41 | + // This enables the "AcquisitionFrameRateEnabled" |
| 42 | + //====================================== |
| 43 | + setProperty(node_map_, "AcquisitionFrameRateEnabled", true); // different from Bfly S |
| 44 | + |
| 45 | + // This sets the "AcquisitionFrameRateAuto" to "Off" |
| 46 | + //====================================== |
| 47 | + setProperty(node_map_, "AcquisitionFrameRateAuto", static_cast<std::string>("Off")); // different from Bfly S |
| 48 | + |
| 49 | + // This sets the "AcquisitionFrameRate" to X FPS |
| 50 | + // ======================================== |
| 51 | + |
| 52 | + Spinnaker::GenApi::CFloatPtr ptrAcquisitionFrameRate = node_map_->GetNode("AcquisitionFrameRate"); |
| 53 | + ROS_DEBUG_STREAM("Minimum Frame Rate: \t " << ptrAcquisitionFrameRate->GetMin()); |
| 54 | + ROS_DEBUG_STREAM("Maximum Frame rate: \t " << ptrAcquisitionFrameRate->GetMax()); |
| 55 | + |
| 56 | + // Finally Set the Frame Rate |
| 57 | + setProperty(node_map_, "AcquisitionFrameRate", frame_rate); |
| 58 | + |
| 59 | + ROS_DEBUG_STREAM("Current Frame rate: \t " << ptrAcquisitionFrameRate->GetValue()); |
| 60 | +} |
| 61 | + |
| 62 | +void Gh3::setNewConfiguration(const SpinnakerConfig& config, const uint32_t& level) |
| 63 | +{ |
| 64 | + try |
| 65 | + { |
| 66 | + if (level >= LEVEL_RECONFIGURE_STOP) |
| 67 | + setImageControlFormats(config); |
| 68 | + |
| 69 | + setFrameRate(static_cast<float>(config.acquisition_frame_rate)); |
| 70 | + setProperty(node_map_, "AcquisitionFrameRateEnabled", |
| 71 | + config.acquisition_frame_rate_enable); // Set enable after frame rate encase its false |
| 72 | + |
| 73 | + // Set Trigger and Strobe Settings |
| 74 | + // NOTE: The trigger must be disabled (i.e. TriggerMode = "Off") in order to configure whether the source is |
| 75 | + // software or hardware. |
| 76 | + setProperty(node_map_, "TriggerMode", std::string("Off")); |
| 77 | + setProperty(node_map_, "TriggerSource", config.trigger_source); |
| 78 | + setProperty(node_map_, "TriggerSelector", config.trigger_selector); |
| 79 | + setProperty(node_map_, "TriggerActivation", config.trigger_activation_mode); |
| 80 | + setProperty(node_map_, "TriggerMode", config.enable_trigger); |
| 81 | + |
| 82 | + setProperty(node_map_, "LineSelector", config.line_selector); |
| 83 | + setProperty(node_map_, "LineMode", config.line_mode); |
| 84 | + // setProperty(node_map_, "LineSource", config.line_source); // Not available in GH3 |
| 85 | + |
| 86 | + // Set auto exposure |
| 87 | + setProperty(node_map_, "ExposureMode", config.exposure_mode); |
| 88 | + setProperty(node_map_, "ExposureAuto", config.exposure_auto); |
| 89 | + |
| 90 | + // Set sharpness |
| 91 | + if (IsAvailable(node_map_->GetNode("SharpeningEnable"))) |
| 92 | + { |
| 93 | + setProperty(node_map_, "SharpeningEnable", config.sharpening_enable); |
| 94 | + if (config.sharpening_enable) |
| 95 | + { |
| 96 | + setProperty(node_map_, "SharpeningAuto", config.auto_sharpness); |
| 97 | + setProperty(node_map_, "Sharpening", static_cast<float>(config.sharpness)); |
| 98 | + setProperty(node_map_, "SharpeningThreshold", static_cast<float>(config.sharpening_threshold)); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + // Set saturation |
| 103 | + if (IsAvailable(node_map_->GetNode("SaturationEnable"))) |
| 104 | + { |
| 105 | + setProperty(node_map_, "SaturationEnable", config.saturation_enable); |
| 106 | + if (config.saturation_enable) |
| 107 | + { |
| 108 | + setProperty(node_map_, "Saturation", static_cast<float>(config.saturation)); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + // Set shutter time/speed |
| 113 | + if (config.exposure_auto.compare(std::string("Off")) == 0) |
| 114 | + { |
| 115 | + setProperty(node_map_, "ExposureTime", static_cast<float>(config.exposure_time)); |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + setProperty(node_map_, "AutoExposureTimeUpperLimit", |
| 120 | + static_cast<float>(config.auto_exposure_time_upper_limit)); // Different than BFly S |
| 121 | + } |
| 122 | + |
| 123 | + // Set gain |
| 124 | + // setProperty(node_map_, "GainSelector", config.gain_selector); //Not Writeable for GH3 |
| 125 | + setProperty(node_map_, "GainAuto", config.auto_gain); |
| 126 | + if (config.auto_gain.compare(std::string("Off")) == 0) |
| 127 | + { |
| 128 | + setProperty(node_map_, "Gain", static_cast<float>(config.gain)); |
| 129 | + } |
| 130 | + |
| 131 | + // Set brightness |
| 132 | + setProperty(node_map_, "BlackLevel", static_cast<float>(config.brightness)); |
| 133 | + |
| 134 | + // Set gamma |
| 135 | + if (config.gamma_enable) |
| 136 | + { |
| 137 | + setProperty(node_map_, "GammaEnabled", config.gamma_enable); // GH3 includes -ed |
| 138 | + setProperty(node_map_, "Gamma", static_cast<float>(config.gamma)); |
| 139 | + } |
| 140 | + |
| 141 | + // Set white balance |
| 142 | + if (IsAvailable(node_map_->GetNode("BalanceWhiteAuto"))) |
| 143 | + { |
| 144 | + setProperty(node_map_, "BalanceWhiteAuto", config.auto_white_balance); |
| 145 | + if (config.auto_white_balance.compare(std::string("Off")) == 0) |
| 146 | + { |
| 147 | + setProperty(node_map_, "BalanceRatioSelector", "Blue"); |
| 148 | + setProperty(node_map_, "BalanceRatio", static_cast<float>(config.white_balance_blue_ratio)); |
| 149 | + setProperty(node_map_, "BalanceRatioSelector", "Red"); |
| 150 | + setProperty(node_map_, "BalanceRatio", static_cast<float>(config.white_balance_red_ratio)); |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + catch (const Spinnaker::Exception& e) |
| 155 | + { |
| 156 | + throw std::runtime_error("[Gh3::setNewConfiguration] Failed to set configuration: " + std::string(e.what())); |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +// Image Size and Pixel Format |
| 161 | +void Gh3::setImageControlFormats(const spinnaker_camera_driver::SpinnakerConfig& config) |
| 162 | +{ |
| 163 | + // Set Binning and Decimation |
| 164 | + // setProperty(node_map_, "BinningHorizontal", config.image_format_x_binning); // Not available on GH3 |
| 165 | + setProperty(node_map_, "BinningVertical", config.image_format_y_binning); |
| 166 | + // setProperty(node_map_, "DecimationHorizontal", config.image_format_x_decimation); |
| 167 | + // setProperty(node_map_, "DecimationVertical", config.image_format_y_decimation); |
| 168 | + |
| 169 | + // Grab the Max values after decimation |
| 170 | + Spinnaker::GenApi::CIntegerPtr height_max_ptr = node_map_->GetNode("HeightMax"); |
| 171 | + if (!IsAvailable(height_max_ptr) || !IsReadable(height_max_ptr)) |
| 172 | + { |
| 173 | + throw std::runtime_error("[Gh3::setImageControlFormats] Unable to read HeightMax"); |
| 174 | + } |
| 175 | + height_max_ = height_max_ptr->GetValue(); |
| 176 | + Spinnaker::GenApi::CIntegerPtr width_max_ptr = node_map_->GetNode("WidthMax"); |
| 177 | + if (!IsAvailable(width_max_ptr) || !IsReadable(width_max_ptr)) |
| 178 | + { |
| 179 | + throw std::runtime_error("[Gh3::setImageControlFormats] Unable to read WidthMax"); |
| 180 | + } |
| 181 | + width_max_ = width_max_ptr->GetValue(); |
| 182 | + |
| 183 | + // Offset first encase expanding ROI |
| 184 | + // Apply offset X |
| 185 | + setProperty(node_map_, "OffsetX", 0); |
| 186 | + // Apply offset Y |
| 187 | + setProperty(node_map_, "OffsetY", 0); |
| 188 | + |
| 189 | + // Set Width/Height |
| 190 | + if (config.image_format_roi_width <= 0 || config.image_format_roi_width > width_max_) |
| 191 | + setProperty(node_map_, "Width", width_max_); |
| 192 | + else |
| 193 | + setProperty(node_map_, "Width", config.image_format_roi_width); |
| 194 | + if (config.image_format_roi_height <= 0 || config.image_format_roi_height > height_max_) |
| 195 | + setProperty(node_map_, "Height", height_max_); |
| 196 | + else |
| 197 | + setProperty(node_map_, "Height", config.image_format_roi_height); |
| 198 | + |
| 199 | + // Apply offset X |
| 200 | + setProperty(node_map_, "OffsetX", config.image_format_x_offset); |
| 201 | + // Apply offset Y |
| 202 | + setProperty(node_map_, "OffsetY", config.image_format_y_offset); |
| 203 | + |
| 204 | + // Set Pixel Format |
| 205 | + setProperty(node_map_, "PixelFormat", config.image_format_color_coding); |
| 206 | +} |
| 207 | +} // namespace spinnaker_camera_driver |
0 commit comments