Skip to content

Commit

Permalink
Update plugin lib exception handling (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliaj authored Jan 8, 2025
1 parent e7049ab commit ec19b21
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
9 changes: 5 additions & 4 deletions include/control_filters/exponential_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ bool ExponentialFilter<T>::configure()
std::make_shared<exponential_filter::ParamListener>(this->params_interface_,
this->param_prefix_);
}
catch (rclcpp::exceptions::ParameterUninitializedException & ex) {
RCLCPP_ERROR((*logger_), "Exponential filter cannot be configured: %s", ex.what());
catch (const std::exception & ex) {
RCLCPP_ERROR((*logger_),
"Exponential filter cannot be configured: %s (type : %s)", ex.what(), typeid(ex).name());
parameter_handler_.reset();
return false;
}
catch (rclcpp::exceptions::InvalidParameterValueException & ex) {
RCLCPP_ERROR((*logger_), "Exponential filter cannot be configured: %s", ex.what());
catch (...) {
RCLCPP_ERROR((*logger_), "Caught unknown exception while configuring Exponential filter");
parameter_handler_.reset();
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions include/control_filters/low_pass_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ bool LowPassFilter<T>::configure()
std::make_shared<low_pass_filter::ParamListener>(this->params_interface_,
this->param_prefix_);
}
catch (rclcpp::exceptions::ParameterUninitializedException & ex) {
RCLCPP_ERROR((*logger_), "LowPass filter cannot be configured: %s", ex.what());
catch (const std::exception & ex) {
RCLCPP_ERROR((*logger_),
"LowPass filter cannot be configured: %s (type : %s)", ex.what(), typeid(ex).name());
parameter_handler_.reset();
return false;
}
catch (rclcpp::exceptions::InvalidParameterValueException & ex) {
RCLCPP_ERROR((*logger_), "LowPass filter cannot be configured: %s", ex.what());
catch (...) {
RCLCPP_ERROR((*logger_), "Caught unknown exception while configuring LowPass filter");
parameter_handler_.reset();
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions include/control_filters/rate_limiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ bool RateLimiter<T>::configure()
std::make_shared<rate_limiter::ParamListener>(this->params_interface_,
this->param_prefix_);
}
catch (rclcpp::exceptions::ParameterUninitializedException & ex) {
RCLCPP_ERROR((*logger_), "Rate limiter cannot be configured: %s", ex.what());
catch (const std::exception & ex) {
RCLCPP_ERROR((*logger_),
"Rate Limiter filter cannot be configured: %s (type : %s)", ex.what(), typeid(ex).name());
parameter_handler_.reset();
return false;
}
catch (rclcpp::exceptions::InvalidParameterValueException & ex) {
RCLCPP_ERROR((*logger_), "Rate limiter cannot be configured: %s", ex.what());
catch (...) {
RCLCPP_ERROR((*logger_), "Caught unknown exception while configuring Rate Limiter filter");
parameter_handler_.reset();
return false;
}
Expand Down
17 changes: 12 additions & 5 deletions test/control_filters/test_exponential_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ TEST_F(FilterTest, TestExponentialFilterThrowsUnconfigured)
ASSERT_THROW(filter_->update(in, out), std::runtime_error);
}

TEST_F(FilterTest, TestExponentialFilterInvalidParameterValue)
{
std::shared_ptr<filters::FilterBase<double>> filter_ =
std::make_shared<control_filters::ExponentialFilter<double>>();
ASSERT_FALSE(filter_->configure("", "TestExponentialFilter",
node_->get_node_logging_interface(), node_->get_node_parameters_interface()));
}

TEST_F(FilterTest, TestExponentialFilterComputation)
{
Expand All @@ -47,13 +54,13 @@ TEST_F(FilterTest, TestExponentialFilterComputation)
ASSERT_EQ(out, 1.0);

// second filter pass with same values: no change
// check equality with low-pass-filter
ASSERT_TRUE(filter_->update(in, out));
calculated = in;
ASSERT_EQ(calculated, out);
// check equality with low-pass-filter
ASSERT_TRUE(filter_->update(in, out));
calculated = in;
ASSERT_EQ(calculated, out);

// input change
in = 0.0;
in = 0.0;
for (int i = 0; i < 100; ++i){
ASSERT_TRUE(filter_->update(in, out));
calculated = alpha * in + (1 - alpha) * calculated;
Expand Down
4 changes: 4 additions & 0 deletions test/control_filters/test_exponential_filter_parameters.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
TestExponentialFilterComputation:
ros__parameters:
alpha: 0.7

TestExponentialInvalidParameterValue:
ros__parameters:
alpha: "a"

0 comments on commit ec19b21

Please sign in to comment.