Skip to content

Commit

Permalink
switch cb confs
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Nov 23, 2024
1 parent cde65d2 commit b2a2f8a
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 105 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ find_package(camera_info_manager REQUIRED)
find_package(cv_bridge REQUIRED)
pkg_check_modules(libcamera REQUIRED libcamera>=0.1)

# new param callbacks need at least 17.0.0
if(${rclcpp_VERSION} VERSION_GREATER_EQUAL "17")
add_compile_definitions(RCLCPP_HAS_PARAM_EXT_CB)
endif()

# library with common utility functions for type conversions
add_library(utils OBJECT
src/format_mapping.cpp
Expand All @@ -37,7 +42,7 @@ set_property(TARGET utils PROPERTY POSITION_INDEPENDENT_CODE ON)
add_library(param OBJECT
src/clamp.cpp
src/cv_to_pv.cpp
src/parameter_conflict_check.cpp
# src/parameter_conflict_check.cpp
src/pv_to_cv.cpp
src/types.cpp
src/type_extent.cpp
Expand Down
35 changes: 31 additions & 4 deletions src/CameraNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ class CameraNode : public rclcpp::Node

ParameterHandler parameter_handler;

#ifdef RCLCPP_HAS_PARAM_EXT_CB
// use new "post_set" callback to apply parameters
PostSetParametersCallbackHandle::SharedPtr param_cb_change;
#else
OnSetParametersCallbackHandle::SharedPtr param_cb_change;
#endif

// map parameter names to libcamera control id
std::unordered_map<std::string, const libcamera::ControlId *> parameter_ids;
Expand All @@ -117,8 +122,13 @@ class CameraNode : public rclcpp::Node
void
process(libcamera::Request *const request);

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

#ifndef RCLCPP_HAS_PARAM_EXT_CB
rcl_interfaces::msg::SetParametersResult
onParameterChange(const std::vector<rclcpp::Parameter> &parameters);
#endif
};

RCLCPP_COMPONENTS_REGISTER_NODE(camera::CameraNode)
Expand Down Expand Up @@ -184,8 +194,13 @@ CameraNode::CameraNode(const rclcpp::NodeOptions &options)
: Node("camera", options),
cim(this),
parameter_handler(this),
param_cb_change(add_post_set_parameters_callback(
std::bind(&CameraNode::onParameterChange, this, std::placeholders::_1)))
param_cb_change(
#ifdef RCLCPP_HAS_PARAM_EXT_CB
add_post_set_parameters_callback(std::bind(&CameraNode::postParameterChange, this, std::placeholders::_1))
#else
add_on_set_parameters_callback(std::bind(&CameraNode::onParameterChange, this, std::placeholders::_1))
#endif
)
{
// pixel format
rcl_interfaces::msg::ParameterDescriptor param_descr_format;
Expand Down Expand Up @@ -565,19 +580,31 @@ CameraNode::process(libcamera::Request *const request)
}
}

rcl_interfaces::msg::SetParametersResult
CameraNode::onParameterChange(const std::vector<rclcpp::Parameter> &parameters)
void
CameraNode::postParameterChange(const std::vector<rclcpp::Parameter> &parameters)
{
std::cout << "postParameterChange" << std::endl;

// check non-controls parameters
for (const rclcpp::Parameter &parameter : parameters) {
if (parameter.get_name() == "jpeg_quality") {
jpeg_quality = parameter.get_parameter_value().get<uint8_t>();
}
}
}

#ifndef RCLCPP_HAS_PARAM_EXT_CB
rcl_interfaces::msg::SetParametersResult
CameraNode::onParameterChange(const std::vector<rclcpp::Parameter> &parameters)
{
std::cout << "onParameterChange" << std::endl;

postParameterChange(parameters);

rcl_interfaces::msg::SetParametersResult result;
result.successful = true;
return result;
}
#endif

} // namespace camera
Loading

0 comments on commit b2a2f8a

Please sign in to comment.