Skip to content

Commit

Permalink
redeclare implicitly undeclared parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Feb 9, 2025
1 parent fbceb8a commit f122b30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/CameraNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ CameraNode::process(libcamera::Request *const request)
RCLCPP_ERROR_STREAM(get_logger(), "request '" << request->toString() << "' cancelled");
}

// redeclare implicitly undeclared parameters
parameter_handler.redeclare();

// queue the request again for the next frame
request->reuse(libcamera::Request::ReuseBuffers);

Expand Down
13 changes: 13 additions & 0 deletions src/ParameterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ ParameterHandler::declare(const libcamera::ControlInfoMap &controls)
"}..{" + info.max().toString() + "}" +
(info.def().isNone() ? std::string {} : " (default: {" + info.def().toString() + "})");

// store descriptor for later re-declaration
parameter_descriptors[id->name()] = descriptor;

// Camera controls can have arrays for minimum and maximum values, but the parameter descriptor
// only supports scalar bounds. Get smallest bounds for minimum and maximum set and warn user.
if (info.min().isArray() || info.max().isArray()) {
Expand Down Expand Up @@ -199,6 +202,16 @@ ParameterHandler::move_control_values(libcamera::ControlList &controls)
controls = std::move(control_values);
}

void
ParameterHandler::redeclare()
{
for (const auto &[name, _] : camera_controls) {
if (!node->has_parameter(name)) {
node->declare_parameter(name, rclcpp::ParameterValue {}, parameter_descriptors.at(name), true);
}
}
}

void
ParameterHandler::PreSetResolve(std::vector<rclcpp::Parameter> &parameters)
{
Expand Down
5 changes: 5 additions & 0 deletions src/ParameterHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ParameterHandler
void
move_control_values(libcamera::ControlList &controls);

void
redeclare();

private:
struct control_info_t
{
Expand All @@ -51,6 +54,8 @@ class ParameterHandler
libcamera::ControlList control_values;
std::mutex control_values_lock;

std::unordered_map<std::string, rcl_interfaces::msg::ParameterDescriptor> parameter_descriptors;

void
PreSetResolve(std::vector<rclcpp::Parameter> &parameters);

Expand Down

0 comments on commit f122b30

Please sign in to comment.