-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement individual exposure controller
- Loading branch information
1 parent
cb35a33
commit 9302d07
Showing
8 changed files
with
441 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...amera_driver/include/spinnaker_synchronized_camera_driver/exposure_controller_factory.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// -*-c++-*-------------------------------------------------------------------- | ||
// Copyright 2024 Bernd Pfrommer <bernd.pfrommer@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef SPINNAKER_SYNCHRONIZED_CAMERA_DRIVER__EXPOSURE_CONTROLLER_FACTORY_HPP_ | ||
#define SPINNAKER_SYNCHRONIZED_CAMERA_DRIVER__EXPOSURE_CONTROLLER_FACTORY_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace spinnaker_camera_driver | ||
{ | ||
class ExposureController; // forward decl | ||
} | ||
namespace rclcpp | ||
{ | ||
class Node; // forward decl | ||
} | ||
namespace spinnaker_synchronized_camera_driver | ||
{ | ||
namespace exposure_controller_factory | ||
{ | ||
std::shared_ptr<spinnaker_camera_driver::ExposureController> newInstance( | ||
const std::string & type, const std::string & name, rclcpp::Node * node); | ||
} // namespace exposure_controller_factory | ||
} // namespace spinnaker_synchronized_camera_driver | ||
#endif // SPINNAKER_SYNCHRONIZED_CAMERA_DRIVER__EXPOSURE_CONTROLLER_FACTORY_HPP_ |
71 changes: 71 additions & 0 deletions
71
...ra_driver/include/spinnaker_synchronized_camera_driver/individual_exposure_controller.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// -*-c++-*-------------------------------------------------------------------- | ||
// Copyright 2024 Bernd Pfrommer <bernd.pfrommer@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef SPINNAKER_SYNCHRONIZED_CAMERA_DRIVER__INDIVIDUAL_EXPOSURE_CONTROLLER_HPP_ | ||
#define SPINNAKER_SYNCHRONIZED_CAMERA_DRIVER__INDIVIDUAL_EXPOSURE_CONTROLLER_HPP_ | ||
|
||
#include <limits> | ||
#include <rclcpp/rclcpp.hpp> | ||
#include <spinnaker_camera_driver/exposure_controller.hpp> | ||
|
||
namespace spinnaker_synchronized_camera_driver | ||
{ | ||
class IndividualExposureController : public spinnaker_camera_driver::ExposureController | ||
{ | ||
public: | ||
explicit IndividualExposureController(const std::string & name, rclcpp::Node * n); | ||
void update( | ||
spinnaker_camera_driver::Camera * cam, | ||
const std::shared_ptr<const spinnaker_camera_driver::Image> & img) final; | ||
void addCamera(const std::shared_ptr<spinnaker_camera_driver::Camera> & cam) final; | ||
|
||
private: | ||
double calculateGain(double brightRatio) const; | ||
double calculateExposureTime(double brightRatio) const; | ||
bool changeExposure(double brightRatio, double minTime, double maxTime, const char * debugMsg); | ||
bool changeGain(double brightRatio, double minGain, double maxGain, const char * debugMsg); | ||
bool updateExposureWithGainPriority(double brightRatio); | ||
bool updateExposureWithTimePriority(double brightRatio); | ||
bool updateExposure(double b); | ||
rclcpp::Logger get_logger() { return (rclcpp::get_logger(cameraName_)); } | ||
|
||
template <class T> | ||
T declare_param(const std::string & n, const T & def) | ||
{ | ||
return (node_->declare_parameter<T>(name_ + "." + n, def)); | ||
} | ||
|
||
// ----------------- variables -------------------- | ||
std::string name_; | ||
std::string cameraName_; | ||
rclcpp::Node * node_{0}; | ||
int32_t targetBrightness_{128}; | ||
std::string exposureParameterName_; | ||
std::string gainParameterName_; | ||
|
||
int brightnessTarget_{128}; | ||
int brightnessTolerance_{5}; | ||
double maxExposureTime_{1000}; | ||
double minExposureTime_{0}; | ||
double maxGain_{30}; | ||
int currentBrightness_; | ||
double currentExposureTime_{0}; | ||
double currentGain_{std::numeric_limits<float>::lowest()}; | ||
int numFramesSkip_{0}; | ||
int maxFramesSkip_{10}; | ||
bool gainPriority_{false}; | ||
}; | ||
} // namespace spinnaker_synchronized_camera_driver | ||
#endif // SPINNAKER_SYNCHRONIZED_CAMERA_DRIVER__INDIVIDUAL_EXPOSURE_CONTROLLER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
spinnaker_synchronized_camera_driver/src/exposure_controller_factory.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// -*-c++-*-------------------------------------------------------------------- | ||
// Copyright 2024 Bernd Pfrommer <bernd.pfrommer@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <spinnaker_synchronized_camera_driver/exposure_controller_factory.hpp> | ||
#include <spinnaker_synchronized_camera_driver/individual_exposure_controller.hpp> | ||
#include <spinnaker_synchronized_camera_driver/logging.hpp> | ||
|
||
namespace spinnaker_synchronized_camera_driver | ||
{ | ||
namespace exposure_controller_factory | ||
{ | ||
static rclcpp::Logger get_logger() { return (rclcpp::get_logger("cam_sync")); } | ||
std::shared_ptr<spinnaker_camera_driver::ExposureController> newInstance( | ||
const std::string & type, const std::string & name, rclcpp::Node * node) | ||
{ | ||
if (type == "individual") { | ||
return (std::make_shared<IndividualExposureController>(name, node)); | ||
} | ||
BOMB_OUT("unknown exposure controller type: " << type); | ||
return (nullptr); | ||
} | ||
} // namespace exposure_controller_factory | ||
} // namespace spinnaker_synchronized_camera_driver |
Oops, something went wrong.