ros2_control - humble
Loading...
Searching...
No Matches
custom_validators.hpp
1// Copyright 2024 AIT - Austrian Institute of Technology GmbH
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_
16#define CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_
17
18#include <fmt/core.h>
19
20#include <string>
21
22#include <rclcpp/rclcpp.hpp>
23#include <rsl/parameter_validators.hpp>
24#include <tl_expected/expected.hpp>
25
26namespace control_filters {
27
31template <typename T>
32tl::expected<void, std::string> gt_eq_or_nan(
33 rclcpp::Parameter const& parameter, T expected_value) {
34 auto param_value = parameter.as_double();
35 if (!std::isnan(param_value)) {
36 // check only if the value is not NaN
37 return rsl::gt_eq<T>(parameter, expected_value);
38 }
39 return {};
40}
41
45template <typename T>
46tl::expected<void, std::string> lt_eq_or_nan(
47 rclcpp::Parameter const& parameter, T expected_value) {
48 auto param_value = parameter.as_double();
49 if (!std::isnan(param_value)) {
50 // check only if the value is not NaN
51 return rsl::lt_eq<T>(parameter, expected_value);
52 }
53 return {};
54}
55
56} // namespace control_filters
57
58#endif // CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_