Skip to content

Commit fa1d908

Browse files
authored
Added support for Grasshopper3. Identical to Chameleon3, split into separate files for clarity. (#26)
1 parent fddc779 commit fa1d908

File tree

5 files changed

+259
-1
lines changed

5 files changed

+259
-1
lines changed

spinnaker_camera_driver/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ add_library(Cm3 src/cm3.cpp)
7373
target_link_libraries(Cm3 Camera ${catkin_LIBRARIES})
7474
add_dependencies(Cm3 ${PROJECT_NAME}_gencfg)
7575

76+
add_library(Gh3 src/gh3.cpp)
77+
target_link_libraries(Gh3 Camera ${catkin_LIBRARIES})
78+
add_dependencies(Gh3 ${PROJECT_NAME}_gencfg)
79+
7680
add_library(Diagnostics src/diagnostics.cpp)
7781
target_link_libraries(Diagnostics Camera SpinnakerCameraLib ${catkin_LIBRARIES})
7882
add_dependencies(Diagnostics ${PROJECT_NAME}_gencfg)
7983

8084
add_library(SpinnakerCameraNodelet src/nodelet.cpp)
81-
target_link_libraries(SpinnakerCameraNodelet Diagnostics SpinnakerCameraLib Camera Cm3 ${catkin_LIBRARIES})
85+
target_link_libraries(SpinnakerCameraNodelet Diagnostics SpinnakerCameraLib Camera Gh3 Cm3 ${catkin_LIBRARIES})
8286

8387
add_executable(spinnaker_camera_node src/node.cpp)
8488
target_link_libraries(spinnaker_camera_node SpinnakerCameraLib ${catkin_LIBRARIES})
@@ -89,6 +93,7 @@ install(TARGETS
8993
SpinnakerCameraNodelet
9094
Camera
9195
Cm3
96+
Gh3
9297
Diagnostics
9398
spinnaker_camera_node
9499
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}

spinnaker_camera_driver/include/spinnaker_camera_driver/SpinnakerCamera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5656
#include <spinnaker_camera_driver/SpinnakerConfig.h>
5757
#include "spinnaker_camera_driver/camera.h"
5858
#include "spinnaker_camera_driver/cm3.h"
59+
#include "spinnaker_camera_driver/gh3.h"
5960
#include "spinnaker_camera_driver/set_property.h"
6061

6162
// Spinnaker SDK
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
Software License Agreement (BSD)
3+
4+
\file cm3.h
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+
#ifndef SPINNAKER_CAMERA_DRIVER_GH3_H
26+
#define SPINNAKER_CAMERA_DRIVER_GH3_H
27+
#include "spinnaker_camera_driver/camera.h"
28+
29+
namespace spinnaker_camera_driver
30+
{
31+
class Gh3 : public Camera
32+
{
33+
public:
34+
explicit Gh3(Spinnaker::GenApi::INodeMap* node_map);
35+
~Gh3();
36+
void setFrameRate(const float frame_rate);
37+
void setNewConfiguration(const SpinnakerConfig& config, const uint32_t& level);
38+
39+
private:
40+
void setImageControlFormats(const spinnaker_camera_driver::SpinnakerConfig& config);
41+
};
42+
} // namespace spinnaker_camera_driver
43+
#endif // SPINNAKER_CAMERA_DRIVER_GH3_H

spinnaker_camera_driver/src/SpinnakerCamera.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ void SpinnakerCamera::connect()
231231
camera_.reset(new Camera(node_map_));
232232
else if (model_name_str.find("Chameleon3") != std::string::npos)
233233
camera_.reset(new Cm3(node_map_));
234+
else if (model_name_str.find("Grasshopper3") != std::string::npos)
235+
camera_.reset(new Gh3(node_map_));
234236
else
235237
{
236238
camera_.reset(new Camera(node_map_));
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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

Comments
 (0)