ros2_control - jazzy
Loading...
Searching...
No Matches
helpers.hpp
1// Copyright (c) 2021, Stogl Robotics Consulting UG (haftungsbeschränkt)
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 CONTROLLER_INTERFACE__HELPERS_HPP_
16#define CONTROLLER_INTERFACE__HELPERS_HPP_
17
18#include <algorithm>
19#include <functional>
20#include <string>
21#include <vector>
22
23// Add hardware interface helpers here, so all inherited controllers can use them
24#include "hardware_interface/helpers.hpp"
25
26namespace controller_interface
27{
44template <typename T>
45bool get_ordered_interfaces(
46 std::vector<T> & unordered_interfaces, const std::vector<std::string> & ordered_names,
47 const std::string & interface_type, std::vector<std::reference_wrapper<T>> & ordered_interfaces)
48{
49 ordered_interfaces.reserve(ordered_names.size());
50 for (const auto & name : ordered_names)
51 {
52 for (auto & interface : unordered_interfaces)
53 {
54 if (!interface_type.empty())
55 {
56 // check case where:
57 // (<joint> == <joint> AND <interface> == <interface>) OR <joint>/<interface> == 'full name'
58 if (
59 ((name == interface.get_prefix_name()) &&
60 (interface_type == interface.get_interface_name())) ||
61 ((name + "/" + interface_type) == interface.get_name()))
62 {
63 ordered_interfaces.push_back(std::ref(interface));
64 }
65 }
66 else
67 {
68 if (name == interface.get_name())
69 {
70 ordered_interfaces.push_back(std::ref(interface));
71 }
72 }
73 }
74 }
75
76 return ordered_names.size() == ordered_interfaces.size();
77}
78
79inline bool interface_list_contains_interface_type(
80 const std::vector<std::string> & interface_type_list, const std::string & interface_type)
81{
82 return std::find(interface_type_list.begin(), interface_type_list.end(), interface_type) !=
83 interface_type_list.end();
84}
85
86template <typename T>
87[[deprecated(
88 "Use ros2_control::add_item method instead. This method will be removed by the ROS 2 Kilted "
89 "Kaiju release.")]] void
90add_element_to_list(std::vector<T> & list, const T & element)
91{
92 ros2_control::add_item(list, element);
93}
94
95} // namespace controller_interface
96
97#endif // CONTROLLER_INTERFACE__HELPERS_HPP_