From fb5a1715e2af614d7b867ba3b0fdcf2031f9a025 Mon Sep 17 00:00:00 2001 From: Berkay Karaman Date: Mon, 17 Apr 2023 05:04:16 +0300 Subject: [PATCH] feat(default_ad_api): update pause interface request Signed-off-by: Berkay Karaman --- system/default_ad_api/src/motion.cpp | 9 ++++++--- system/default_ad_api/src/motion.hpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/system/default_ad_api/src/motion.cpp b/system/default_ad_api/src/motion.cpp index b02fd43e9be44..32e99bf214127 100644 --- a/system/default_ad_api/src/motion.cpp +++ b/system/default_ad_api/src/motion.cpp @@ -42,12 +42,12 @@ MotionNode::MotionNode(const rclcpp::NodeOptions & options) void MotionNode::update_state() { - if (!is_paused_ || !is_start_requested_) { + if (!is_paused_by_node_ || !is_start_requested_) { return; } const auto get_next_state = [this]() { - if (is_paused_.value()) { + if (is_paused_by_node_.value()) { if (!is_start_requested_.value()) { return State::Paused; } else { @@ -112,6 +112,7 @@ void MotionNode::change_pause(bool pause) if (!is_calling_set_pause_ && cli_set_pause_->service_is_ready()) { const auto req = std::make_shared(); req->pause = pause; + req->request_source = "default_ad_api"; is_calling_set_pause_ = true; cli_set_pause_->async_send_request(req, [this](auto) { is_calling_set_pause_ = false; }); } @@ -131,7 +132,9 @@ void MotionNode::on_timer() void MotionNode::on_is_paused(const control_interface::IsPaused::Message::ConstSharedPtr msg) { - is_paused_ = msg->data; + is_paused_by_node_ = msg->data && std::find( + msg->requested_sources.begin(), msg->requested_sources.end(), + "default_ad_api") != msg->requested_sources.end(); } void MotionNode::on_is_start_requested( diff --git a/system/default_ad_api/src/motion.hpp b/system/default_ad_api/src/motion.hpp index 4d929d80c9655..710930bd6dc63 100644 --- a/system/default_ad_api/src/motion.hpp +++ b/system/default_ad_api/src/motion.hpp @@ -45,7 +45,7 @@ class MotionNode : public rclcpp::Node enum class State { Unknown, Pausing, Paused, Starting, Resuming, Resumed, Moving }; State state_; - std::optional is_paused_; + std::optional is_paused_by_node_; std::optional is_start_requested_; double stop_check_duration_;