camera.cpp
Go to the documentation of this file.
1 
26 
27 #include <string>
28 
30 {
32 {
33  Spinnaker::GenApi::CIntegerPtr height_max_ptr = node_map_->GetNode("HeightMax");
34  if (!IsAvailable(height_max_ptr) || !IsReadable(height_max_ptr))
35  {
36  throw std::runtime_error("[Camera::init] Unable to read HeightMax");
37  }
38  height_max_ = height_max_ptr->GetValue();
39  Spinnaker::GenApi::CIntegerPtr width_max_ptr = node_map_->GetNode("WidthMax");
40  if (!IsAvailable(width_max_ptr) || !IsReadable(width_max_ptr))
41  {
42  throw std::runtime_error("[Camera::init] Unable to read WidthMax");
43  }
44  width_max_ = width_max_ptr->GetValue();
45  // Set Throughput to maximum
46  //=====================================
47  setMaxInt(node_map_, "DeviceLinkThroughputLimit");
48 }
49 void Camera::setFrameRate(const float frame_rate)
50 {
51  // This enables the "AcquisitionFrameRateEnabled"
52  //======================================
53  setProperty(node_map_, "AcquisitionFrameRateEnable", true);
54 
55  // This sets the "AcquisitionFrameRate" to X FPS
56  // ========================================
57 
58  Spinnaker::GenApi::CFloatPtr ptrAcquisitionFrameRate = node_map_->GetNode("AcquisitionFrameRate");
59  ROS_DEBUG_STREAM("Minimum Frame Rate: \t " << ptrAcquisitionFrameRate->GetMin());
60  ROS_DEBUG_STREAM("Maximum Frame rate: \t " << ptrAcquisitionFrameRate->GetMax());
61 
62  // Finally Set the Frame Rate
63  setProperty(node_map_, "AcquisitionFrameRate", frame_rate);
64 
65  ROS_DEBUG_STREAM("Current Frame rate: \t " << ptrAcquisitionFrameRate->GetValue());
66 }
67 
68 void Camera::setNewConfiguration(const SpinnakerConfig& config, const uint32_t& level)
69 {
70  try
71  {
72  if (level >= LEVEL_RECONFIGURE_STOP)
73  setImageControlFormats(config);
74 
75  setFrameRate(static_cast<float>(config.acquisition_frame_rate));
76  // Set enable after frame rate encase its false
77  setProperty(node_map_, "AcquisitionFrameRateEnable", config.acquisition_frame_rate_enable);
78 
79  // Set Trigger and Strobe Settings
80  // NOTE: The trigger must be disabled (i.e. TriggerMode = "Off") in order to configure whether the source is
81  // software or hardware.
82  setProperty(node_map_, "TriggerMode", std::string("Off"));
83  setProperty(node_map_, "TriggerSource", config.trigger_source);
84  setProperty(node_map_, "TriggerSelector", config.trigger_selector);
85  setProperty(node_map_, "TriggerActivation", config.trigger_activation_mode);
86  setProperty(node_map_, "TriggerMode", config.enable_trigger);
87 
88  setProperty(node_map_, "LineSelector", config.line_selector);
89  setProperty(node_map_, "LineMode", config.line_mode);
90  setProperty(node_map_, "LineSource", config.line_source);
91 
92  // Set auto exposure
93  setProperty(node_map_, "ExposureMode", config.exposure_mode);
94  setProperty(node_map_, "ExposureAuto", config.exposure_auto);
95 
96  // Set sharpness
97  if (IsAvailable(node_map_->GetNode("SharpeningEnable")))
98  {
99  setProperty(node_map_, "SharpeningEnable", config.sharpening_enable);
100  if (config.sharpening_enable)
101  {
102  setProperty(node_map_, "SharpeningAuto", config.auto_sharpness);
103  setProperty(node_map_, "Sharpening", static_cast<float>(config.sharpness));
104  setProperty(node_map_, "SharpeningThreshold", static_cast<float>(config.sharpening_threshold));
105  }
106  }
107 
108  // Set saturation
109  if (IsAvailable(node_map_->GetNode("SaturationEnable")))
110  {
111  setProperty(node_map_, "SaturationEnable", config.saturation_enable);
112  if (config.saturation_enable)
113  {
114  setProperty(node_map_, "Saturation", static_cast<float>(config.saturation));
115  }
116  }
117 
118  // Set shutter time/speed
119  if (config.exposure_auto.compare(std::string("Off")) == 0)
120  {
121  setProperty(node_map_, "ExposureTime", static_cast<float>(config.exposure_time));
122  }
123  else
124  {
125  setProperty(node_map_, "AutoExposureExposureTimeUpperLimit",
126  static_cast<float>(config.auto_exposure_time_upper_limit));
127  }
128 
129  // Set gain
130  setProperty(node_map_, "GainSelector", config.gain_selector);
131  setProperty(node_map_, "GainAuto", config.auto_gain);
132  if (config.auto_gain.compare(std::string("Off")) == 0)
133  {
134  setProperty(node_map_, "Gain", static_cast<float>(config.gain));
135  }
136 
137  // Set brightness
138  setProperty(node_map_, "BlackLevel", static_cast<float>(config.brightness));
139 
140  // Set gamma
141  if (config.gamma_enable)
142  {
143  setProperty(node_map_, "GammaEnable", config.gamma_enable);
144  setProperty(node_map_, "Gamma", static_cast<float>(config.gamma));
145  }
146 
147  // Set white balance
148  if (IsAvailable(node_map_->GetNode("BalanceWhiteAuto")))
149  {
150  setProperty(node_map_, "BalanceWhiteAuto", config.auto_white_balance);
151  if (config.auto_white_balance.compare(std::string("Off")) == 0)
152  {
153  setProperty(node_map_, "BalanceRatioSelector", "Blue");
154  setProperty(node_map_, "BalanceRatio", static_cast<float>(config.white_balance_blue_ratio));
155  setProperty(node_map_, "BalanceRatioSelector", "Red");
156  setProperty(node_map_, "BalanceRatio", static_cast<float>(config.white_balance_red_ratio));
157  }
158  }
159 
160  // Set Auto exposure/white balance parameters
161  if (IsAvailable(node_map_->GetNode("AutoAlgorithmSelector")))
162  {
163  setProperty(node_map_, "AutoAlgorithmSelector", std::string("Ae"));
164  setProperty(node_map_, "AasRoiEnable", true);
165  if (config.auto_exposure_roi_width != 0 && config.auto_exposure_roi_height != 0)
166  {
167  setProperty(node_map_, "AasRoiOffsetX", config.auto_exposure_roi_offset_x);
168  setProperty(node_map_, "AasRoiOffsetY", config.auto_exposure_roi_offset_y);
169  setProperty(node_map_, "AasRoiWidth", config.auto_exposure_roi_width);
170  setProperty(node_map_, "AasRoiHeight", config.auto_exposure_roi_height);
171  }
172  }
173 
174  // Set Auto exposure lighting mode
175  if (IsAvailable(node_map_->GetNode("AutoExposureLightingMode")))
176  {
177  setProperty(node_map_, "AutoExposureLightingMode", config.auto_exposure_lighting_mode);
178  }
179  }
180  catch (const Spinnaker::Exception& e)
181  {
182  throw std::runtime_error("[Camera::setNewConfiguration] Failed to set configuration: " + std::string(e.what()));
183  }
184 }
185 
186 // Image Size and Pixel Format
187 void Camera::setImageControlFormats(const spinnaker_camera_driver::SpinnakerConfig& config)
188 {
189  // Set Binning, Decimation, and Reverse
190  setProperty(node_map_, "BinningHorizontal", config.image_format_x_binning);
191  setProperty(node_map_, "BinningVertical", config.image_format_y_binning);
192  setProperty(node_map_, "DecimationHorizontal", config.image_format_x_decimation);
193  setProperty(node_map_, "DecimationVertical", config.image_format_y_decimation);
194  setProperty(node_map_, "ReverseX", config.image_format_x_reverse);
195  setProperty(node_map_, "ReverseY", config.image_format_y_reverse);
196 
197  // Grab the Max values after decimation
198  Spinnaker::GenApi::CIntegerPtr height_max_ptr = node_map_->GetNode("HeightMax");
199  if (!IsAvailable(height_max_ptr) || !IsReadable(height_max_ptr))
200  {
201  throw std::runtime_error("[Camera::setImageControlFormats] Unable to read HeightMax");
202  }
203  height_max_ = height_max_ptr->GetValue();
204  Spinnaker::GenApi::CIntegerPtr width_max_ptr = node_map_->GetNode("WidthMax");
205  if (!IsAvailable(width_max_ptr) || !IsReadable(width_max_ptr))
206  {
207  throw std::runtime_error("[Camera::setImageControlFormats] Unable to read WidthMax");
208  }
209  width_max_ = width_max_ptr->GetValue();
210 
211  // Offset first encase expanding ROI
212  // Apply offset X
213  setProperty(node_map_, "OffsetX", 0);
214  // Apply offset Y
215  setProperty(node_map_, "OffsetY", 0);
216 
217  // Set Width/Height
218  if (config.image_format_roi_width <= 0 || config.image_format_roi_width > width_max_)
219  setProperty(node_map_, "Width", width_max_);
220  else
221  setProperty(node_map_, "Width", config.image_format_roi_width);
222  if (config.image_format_roi_height <= 0 || config.image_format_roi_height > height_max_)
223  setProperty(node_map_, "Height", height_max_);
224  else
225  setProperty(node_map_, "Height", config.image_format_roi_height);
226 
227  // Apply offset X
228  setProperty(node_map_, "OffsetX", config.image_format_x_offset);
229  // Apply offset Y
230  setProperty(node_map_, "OffsetY", config.image_format_y_offset);
231 
232  // Set Pixel Format
233  setProperty(node_map_, "PixelFormat", config.image_format_color_coding);
234 }
235 
236 void Camera::setGain(const float& gain)
237 {
238  setProperty(node_map_, "GainAuto", "Off");
239  setProperty(node_map_, "Gain", static_cast<float>(gain));
240 }
241 
242 /*
243 void Camera::setGigEParameters(bool auto_packet_size, unsigned int packet_size, unsigned int packet_delay)
244 {
245 }
246 
247 void Camera::setupGigEPacketSize(PGRGuid & guid)
248 {
249 }
250 
251 void Camera::setupGigEPacketSize(PGRGuid & guid, unsigned int packet_size)
252 {
253 
254 }
255 
256 void Camera::setupGigEPacketDelay(PGRGuid & guid, unsigned int packet_delay)
257 {
258 }
259 
260 */
261 
263 {
264  return height_max_;
265 }
266 
268 {
269  return width_max_;
270 }
271 
272 // uint SpinnakerCamera::getGain()
273 // {
274 // return metadata_.embeddedGain >> 20;
275 // }
276 
277 // uint Camera::getShutter()
278 // {
279 // return metadata_.embeddedShutter >> 20;
280 // }
281 
282 // uint Camera::getBrightness()
283 // {
284 // return metadata_.embeddedTimeStamp >> 20;
285 // }
286 
287 // uint Camera::getExposure()
288 // {
289 // return metadata_.embeddedBrightness >> 20;
290 // }
291 
292 // uint Camera::getWhiteBalance()
293 // {
294 // return metadata_.embeddedExposure >> 8;
295 // }
296 
297 // uint Camera::getROIPosition()
298 // {
299 // return metadata_.embeddedROIPosition >> 24;
300 // }
301 
302 // float Camera::getCameraTemperature()
303 //{
304 //}
305 
306 // float Camera::getCameraFrameRate()
307 //{
308 //}
309 Spinnaker::GenApi::CNodePtr Camera::readProperty(const Spinnaker::GenICam::gcstring property_name)
310 {
311  Spinnaker::GenApi::CNodePtr ptr = node_map_->GetNode(property_name);
312  if (!Spinnaker::GenApi::IsAvailable(ptr) || !Spinnaker::GenApi::IsReadable(ptr))
313  {
314  throw std::runtime_error("Unable to get parmeter " + property_name);
315  }
316  return ptr;
317 }
318 
319 Camera::Camera(Spinnaker::GenApi::INodeMap* node_map)
320 {
321  node_map_ = node_map;
322  init();
323 }
324 } // namespace spinnaker_camera_driver
bool setProperty(Spinnaker::GenApi::INodeMap *node_map, const std::string &property_name, const std::string &entry_name)
Definition: set_property.h:36
virtual void setNewConfiguration(const spinnaker_camera_driver::SpinnakerConfig &config, const uint32_t &level)
Definition: camera.cpp:68
Spinnaker::GenApi::INodeMap * node_map_
Definition: camera.h:73
static const uint8_t LEVEL_RECONFIGURE_STOP
Definition: camera.h:60
Camera(Spinnaker::GenApi::INodeMap *node_map)
Definition: camera.cpp:319
virtual void setImageControlFormats(const spinnaker_camera_driver::SpinnakerConfig &config)
Definition: camera.cpp:187
#define ROS_DEBUG_STREAM(args)
bool setMaxInt(Spinnaker::GenApi::INodeMap *node_map, const std::string &property_name)
Definition: set_property.h:239
virtual void setFrameRate(const float frame_rate)
Changes the video mode of the connected camera.
Definition: camera.cpp:49
Spinnaker::GenApi::CNodePtr readProperty(const Spinnaker::GenICam::gcstring property_name)
Definition: camera.cpp:309
virtual void setGain(const float &gain)
Definition: camera.cpp:236


spinnaker_camera_driver
Author(s): Chad Rockey
autogenerated on Sun Feb 14 2021 03:47:26