ros2_control - rolling
Loading...
Searching...
No Matches
tf_prefix.hpp
1// Copyright (c) 2025, ros2_control developers
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__TF_PREFIX_HPP_
16#define CONTROLLER_INTERFACE__TF_PREFIX_HPP_
17
18#include <string>
19
20namespace controller_interface
21{
28inline std::string resolve_tf_prefix(const std::string & prefix, const std::string & node_ns)
29{
30 if (prefix.empty())
31 {
32 return "";
33 }
34
35 std::string nprefix = prefix;
36 std::size_t pos = nprefix.find("~");
37 if (pos != std::string::npos)
38 {
39 nprefix.replace(pos, 1, node_ns);
40 }
41
42 // ensure trailing '/'
43 if (nprefix.back() != '/')
44 {
45 nprefix.push_back('/');
46 }
47 // remove leading '/'
48 if (nprefix.front() == '/')
49 {
50 nprefix.erase(0, 1);
51 }
52 return nprefix;
53}
54} // namespace controller_interface
55
56#endif // CONTROLLER_INTERFACE__TF_PREFIX_HPP_