42 const std::string&
name,
44 bool default_continuous_value,
double default_timeout)
57 std_msgs::msg::String msg;
65 std::string keep_open_param =
name_ +
"_continuous";
66 if (!
node_->has_parameter(keep_open_param))
68 node_->declare_parameter(keep_open_param, rclcpp::ParameterType::PARAMETER_BOOL);
71 node_->get_parameter_or(keep_open_param, keep_open, default_continuous_value);
73 std::string timeout_param =
name_ +
"_timeout";
74 if (!
node_->has_parameter(timeout_param))
76 node_->declare_parameter(timeout_param, rclcpp::ParameterType::PARAMETER_DOUBLE);
79 node_->get_parameter_or(timeout_param, d_timeout, default_timeout);
80 rclcpp::Duration timeout = rclcpp::Duration::from_seconds(d_timeout);
84 RCLCPP_ERROR_ONCE(
node_->get_logger(),
85 "Could not find parameter %s and did not receive %s via std_msgs::msg::String subscription "
101 node_->declare_parameter(
name_, rclcpp::ParameterType::PARAMETER_STRING);
111 std::string publish_param =
"publish_" +
name_;
113 if (!
node_->has_parameter(publish_param))
115 node_->declare_parameter(publish_param, rclcpp::ParameterType::PARAMETER_BOOL);
117 node_->get_parameter_or(publish_param, publish_string,
false);
118 return publish_string;
123 auto const nd_name = std::string(
node_->get_name()).append(
"_ssp_").append(
name_);
124 auto const temp_node = std::make_shared<rclcpp::Node>(nd_name);
127 rclcpp::QoS(1).transient_local().reliable(),
128 [
this](
const std_msgs::msg::String::ConstSharedPtr& msg) {
return stringCallback(msg); });
130 rclcpp::WaitSet wait_set;
133 auto ret = wait_set.wait(timeout.to_chrono<std::chrono::duration<double>>());
134 if (ret.kind() == rclcpp::WaitResultKind::Ready)
136 std_msgs::msg::String msg;
137 rclcpp::MessageInfo info;
rclcpp::Subscription< std_msgs::msg::String >::SharedPtr string_subscriber_
std::string loadInitialValue(const std::shared_ptr< rclcpp::Node > &node, const std::string &name, const StringCallback &parent_callback={}, bool default_continuous_value=false, double default_timeout=10.0)
std::shared_ptr< rclcpp::Node > node_
bool waitForMessage(const rclcpp::Duration &timeout)
rclcpp::Publisher< std_msgs::msg::String >::SharedPtr string_publisher_
StringCallback parent_callback_
void stringCallback(const std_msgs::msg::String::ConstSharedPtr &msg)
std::function< void(const std::string &)> StringCallback