ros2_control - jazzy
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{
28
32template <typename T>
33tl::expected<void, std::string> gt_eq_or_nan(rclcpp::Parameter const & parameter, T expected_value)
34{
35 auto param_value = parameter.as_double();
36 if (!std::isnan(param_value))
37 {
38 // check only if the value is not NaN
39 return rsl::gt_eq<T>(parameter, expected_value);
40 }
41 return {};
42}
43
47template <typename T>
48tl::expected<void, std::string> lt_eq_or_nan(rclcpp::Parameter const & parameter, T expected_value)
49{
50 auto param_value = parameter.as_double();
51 if (!std::isnan(param_value))
52 {
53 // check only if the value is not NaN
54 return rsl::lt_eq<T>(parameter, expected_value);
55 }
56 return {};
57}
58
59} // namespace control_filters
60
61#endif // CONTROL_FILTERS__CUSTOM_VALIDATORS_HPP_