15 #include "nav2_util/node_utils.hpp"
21 using std::chrono::high_resolution_clock;
24 using std::replace_if;
30 string sanitize_node_name(
const string & potential_node_name)
32 string node_name(potential_node_name);
36 begin(node_name), end(node_name),
37 [](
auto c) {
return !isalnum(c);},
42 string add_namespaces(
const string & top_ns,
const string & sub_ns)
44 if (!top_ns.empty() && top_ns.back() ==
'/') {
45 if (top_ns.front() ==
'/') {
46 return top_ns + sub_ns;
48 return "/" + top_ns + sub_ns;
52 return top_ns +
"/" + sub_ns;
55 std::string time_to_string(
size_t len)
57 string output(len,
'0');
58 auto timepoint = high_resolution_clock::now();
59 auto timecount = timepoint.time_since_epoch().count();
60 auto timestring = to_string(timecount);
61 if (timestring.length() >= len) {
66 timestring.length() - len, len);
70 len - timestring.length(), timestring.length(),
72 0, timestring.length());
77 std::string generate_internal_node_name(
const std::string & prefix)
79 return sanitize_node_name(prefix) +
"_" + time_to_string(8);
82 rclcpp::Node::SharedPtr generate_internal_node(
const std::string & prefix)
86 .start_parameter_services(
false)
87 .start_parameter_event_publisher(
false)
88 .arguments({
"--ros-args",
"-r",
"__node:=" + generate_internal_node_name(prefix),
"--"});
89 return rclcpp::Node::make_shared(
"_", options);