3 #include "SettingsConfigUtils.h" 4 #include "SettingsAcquisitionConfigUtils.h" 5 #include "Settings2DConfigUtils.h" 6 #include "Settings2DAcquisitionConfigUtils.h" 8 #include <Zivid/Camera.h> 9 #include <Zivid/Experimental/SettingsInfo.h> 11 #include <dynamic_reconfigure/server.h> 15 template <
typename ConfigType,
typename Ziv
idSettings>
22 static_assert(std::is_same_v<ZividSettings, Zivid::Settings> || std::is_same_v<ZividSettings, Zivid::Settings2D> ||
23 std::is_same_v<ZividSettings, Zivid::Settings::Acquisition> ||
24 std::is_same_v<ZividSettings, Zivid::Settings2D::Acquisition>);
26 const auto config_min = zividSettingsMinConfig<ConfigType, ZividSettings>(camera);
29 const auto config_max = zividSettingsMaxConfig<ConfigType, ZividSettings>(camera);
32 const auto config_default = zividSettingsToConfig<ConfigType>(
33 Zivid::Experimental::SettingsInfo::defaultValue<ZividSettings>(camera.info()));
37 auto cb = [
this](
const ConfigType&
config, uint32_t ) {
41 using CallbackType =
typename decltype(
dr_server_)::CallbackType;
56 const std::string&
name()
const 68 template <
typename Ziv
idSettingsType,
typename SettingsConfigType,
typename SettingsAcquisitionConfigType>
71 Zivid::Camera& camera,
72 const std::string& config_node_name,
73 std::size_t num_acquisition_servers)
74 : config_node_name_(config_node_name)
78 ROS_INFO(
"Setting up %ld %s/acquisition_<n> dynamic_reconfigure servers", num_acquisition_servers,
79 config_node_name_.c_str());
80 for (std::size_t i = 0; i < num_acquisition_servers; i++)
83 config_node_name_ +
"/acquisition_" + std::to_string(i), nh, camera));
87 template <
typename Ziv
idSettingsType,
typename SettingsConfigType,
typename SettingsAcquisitionConfigType>
91 template <
typename Ziv
idSettingsType,
typename SettingsConfigType,
typename SettingsAcquisitionConfigType>
95 ZividSettingsType settings;
100 if (dr_config_server->config().enabled)
102 ROS_DEBUG(
"Config %s is enabled", dr_config_server->name().c_str());
103 typename ZividSettingsType::Acquisition acquisition;
104 applyConfigToZividSettings(dr_config_server->config(), acquisition);
105 settings.acquisitions().emplaceBack(std::move(acquisition));
111 template <
typename Ziv
idSettingsType,
typename SettingsConfigType,
typename SettingsAcquisitionConfigType>
113 const ZividSettingsType& settings)
115 const auto& acquisitions = settings.acquisitions();
119 std::stringstream error;
120 error <<
"The number of acquisitions (" + std::to_string(acquisitions.size()) +
") " 121 <<
"is larger than the number of dynamic_reconfigure " +
config_node_name_ +
"/acquisition_<n> servers (" 123 if constexpr (std::is_same_v<ZividSettingsType, Zivid::Settings>)
125 error <<
"Increase launch parameter max_capture_acquisitions. " 126 <<
"See README.md for more information.";
128 else if constexpr (std::is_same_v<ZividSettingsType, Zivid::Settings2D>)
130 error <<
"In 2D mode only a single acquisiton is supported.";
132 throw std::runtime_error(error.str());
138 for (std::size_t i = 0; i < acquisitions.size(); i++)
140 auto config = zividSettingsToConfig<SettingsAcquisitionConfigType>(acquisitions.at(i));
141 config.enabled =
true;
150 ROS_INFO_STREAM(
"Acquisition " << i <<
" was enabled, so disabling it");
152 config.enabled =
false;
158 template <
typename Ziv
idSettingsType,
typename SettingsConfigType,
typename SettingsAcquisitionConfigType>
166 zivid_camera::SettingsAcquisitionConfig>;
168 zivid_camera::Settings2DAcquisitionConfig>;
~CaptureSettingsController()
const std::string & name() const
ZividSettingsType zividSettings() const
void setZividSettings(const ZividSettingsType &settings)
std::size_t numAcquisitionConfigServers() const
std::unique_ptr< SettingsConfigTypeDRServer > general_config_dr_server_
std::string config_node_name_
ConfigDRServer(const std::string &name, ros::NodeHandle &nh, const Zivid::Camera &camera)
#define ROS_DEBUG_STREAM(args)
std::vector< std::unique_ptr< SettingsAcquisitionConfigTypeDRServer > > acquisition_config_dr_servers_
Controller that manages dynamic_reconfigure nodes for Settings and Settings2D
#define ROS_INFO_STREAM(args)
boost::recursive_mutex dr_server_mutex_
void setConfig(const ConfigType &cfg)
dynamic_reconfigure::Server< ConfigType > dr_server_
const ConfigType & config() const