Skip to content

Commit

Permalink
Add custom validator excluding NaN values and update parameter descri…
Browse files Browse the repository at this point in the history
…ption
  • Loading branch information
christophfroehlich committed Dec 1, 2024
1 parent bb56bda commit 0eda373
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
58 changes: 58 additions & 0 deletions include/control_filters/custom_validators.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 AIT - Austrian Institute of Technology GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_
#define CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_

#include <fmt/core.h>

#include <string>

#include <rclcpp/rclcpp.hpp>
#include <rsl/parameter_validators.hpp>
#include <tl_expected/expected.hpp>

namespace control_filters {

/**
* @brief gt_eq, but check only if the value is not NaN
*/
template <typename T>
tl::expected<void, std::string> gt_eq_or_nan(
rclcpp::Parameter const& parameter, T expected_value) {
auto param_value = parameter.as_double();
if (!std::isnan(param_value)) {
// check only if the value is not NaN
return rsl::gt_eq<T>(parameter, expected_value);
}
return {};
}

/**
* @brief lt_eq, but check only if the value is not NaN
*/
template <typename T>
tl::expected<void, std::string> lt_eq_or_nan(
rclcpp::Parameter const& parameter, T expected_value) {
auto param_value = parameter.as_double();
if (!std::isnan(param_value)) {
// check only if the value is not NaN
return rsl::lt_eq<T>(parameter, expected_value);
}
return {};
}

} // namespace control_filters

#endif // CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_
1 change: 1 addition & 0 deletions include/control_filters/rate_limiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "filters/filter_base.hpp"

#include "control_toolbox/rate_limiter.hpp"
#include "custom_validators.hpp"
#include "rate_limiter_parameters.hpp"

namespace control_filters
Expand Down
34 changes: 33 additions & 1 deletion src/control_filters/rate_limiter_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,70 @@ rate_limiter:
type: double,
description: "Sampling interval in seconds",
validation: {
gt<>: [0.0]
gt<>: [0.0],
},
}
max_value: {
type: double,
default_value: .NAN,
description: "Maximum value, e.g. [m/s]",
validation: {
"control_filters::gt_eq_or_nan<>": [0.0]
},
}
min_value: {
type: double,
default_value: .NAN,
description: "Minimum value, e.g. [m/s]",
validation: {
"control_filters::lt_eq_or_nan<>": [0.0]
},
}
max_first_derivative_pos: {
type: double,
default_value: .NAN,
description: "Maximum value of the first derivative if **value** is positive, e.g. [m/s^2]",
validation: {
"control_filters::gt_eq_or_nan<>": [0.0]
},
}
min_first_derivative_pos: {
type: double,
default_value: .NAN,
description: "Minimum value of the first derivative if **value** is positive, e.g. [m/s^2]",
validation: {
"control_filters::lt_eq_or_nan<>": [0.0]
},
}
max_first_derivative_neg: {
type: double,
default_value: .NAN,
description: "Maximum value of the first derivative if **value** is negative, e.g. [m/s^2]",
validation: {
"control_filters::gt_eq_or_nan<>": [0.0]
},
}
min_first_derivative_neg: {
type: double,
default_value: .NAN,
description: "Minimum value of the first derivative if **value** is negative, e.g. [m/s^2]",
validation: {
"control_filters::lt_eq_or_nan<>": [0.0]
},
}
max_second_derivative: {
type: double,
default_value: .NAN,
description: "Maximum value of the second derivative, e.g. [m/s^3]",
validation: {
"control_filters::gt_eq_or_nan<>": [0.0]
},
}
min_second_derivative: {
type: double,
default_value: .NAN,
description: "Minimum value of the second derivative, e.g. [m/s^3]",
validation: {
"control_filters::lt_eq_or_nan<>": [0.0]
},
}

0 comments on commit 0eda373

Please sign in to comment.