Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic setting of params in speckle filter #204

Open
wants to merge 3 commits into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if(${rclcpp_VERSION_MAJOR} GREATER_EQUAL 20)
add_compile_definitions(RCLCPP_SUPPORTS_MATCHED_CALLBACKS)
endif()

if(${rclcpp_VERSION_MAJOR} GREATER_EQUAL 17)
add_compile_definitions(RCLCPP_SUPPORTS_POST_SET_PARAMS_CALLBACK)
endif()

ament_auto_add_library(laser_scan_filters SHARED src/laser_scan_filters.cpp)
ament_auto_add_library(laser_filter_chains SHARED
src/scan_to_cloud_filter_chain.cpp
Expand Down
29 changes: 22 additions & 7 deletions include/laser_filters/speckle_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ class LaserScanSpeckleFilter : public filters::FilterBase<sensor_msgs::msg::Lase

///////////////////////////////////////////////////////////////
bool configure(){

#ifdef RCLCPP_SUPPORTS_POST_SET_PARAMS_CALLBACK
// Declare parameters as writeable. Otherwise, the first time we call FilterBase::getParam() for each one,
// it will get declared as write only.
rcl_interfaces::msg::ParameterDescriptor desc;
desc.read_only = true;
params_interface_->declare_parameter("filter_type", rclcpp::ParameterType::PARAMETER_INTEGER, desc);
params_interface_->declare_parameter("max_range", rclcpp::ParameterType::PARAMETER_DOUBLE, desc);
params_interface_->declare_parameter("max_range_difference", rclcpp::ParameterType::PARAMETER_DOUBLE, desc);
params_interface_->declare_parameter("filter_window", rclcpp::ParameterType::PARAMETER_INTEGER, desc);
#endif

// get params
if (!filters::FilterBase<sensor_msgs::msg::LaserScan>::getParam(std::string("filter_type"), filter_type))
{
Expand Down Expand Up @@ -214,6 +226,11 @@ class LaserScanSpeckleFilter : public filters::FilterBase<sensor_msgs::msg::Lase
break;
}

#ifdef RCLCPP_SUPPORTS_POST_SET_PARAMS_CALLBACK
post_set_parameters_callback_handle_ = params_interface_->add_post_set_parameters_callback(
std::bind(&LaserScanSpeckleFilter::reconfigureCB, this, std::placeholders::_1));
#endif

return true;
}
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -248,11 +265,8 @@ class LaserScanSpeckleFilter : public filters::FilterBase<sensor_msgs::msg::Lase
return true;
}

rcl_interfaces::msg::SetParametersResult reconfigureCB(std::vector<rclcpp::Parameter> parameters)
void reconfigureCB(std::vector<rclcpp::Parameter> parameters)
{
auto result = rcl_interfaces::msg::SetParametersResult();
result.successful = true;

for (auto parameter : parameters)
{
if(logging_interface_ != nullptr)
Expand Down Expand Up @@ -289,9 +303,6 @@ class LaserScanSpeckleFilter : public filters::FilterBase<sensor_msgs::msg::Lase
default:
break;
}

return result;

}

////////////////////////////////////////////////////
Expand All @@ -303,6 +314,10 @@ class LaserScanSpeckleFilter : public filters::FilterBase<sensor_msgs::msg::Lase
double max_range = 0;
double max_range_difference = 0;
int filter_window = 0;

#ifdef RCLCPP_SUPPORTS_POST_SET_PARAMS_CALLBACK
rclcpp::node_interfaces::PostSetParametersCallbackHandle::SharedPtr post_set_parameters_callback_handle_;
#endif // RCLCPP_SUPPORTS_POST_SET_PARAMS_CALLBACK
};
}
#endif /* speckle_filter.h */
Loading