Skip to content

Commit

Permalink
feat(default_ad_api): update pause interface request
Browse files Browse the repository at this point in the history
Signed-off-by: Berkay Karaman <[email protected]>
  • Loading branch information
brkay54 committed Apr 18, 2023
1 parent cab563a commit 25f5a1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions system/default_ad_api/src/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<control_interface::SetPause::Service::Request>();
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; });
}
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion system/default_ad_api/src/motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MotionNode : public rclcpp::Node

enum class State { Unknown, Pausing, Paused, Starting, Resuming, Resumed, Moving };
State state_;
std::optional<bool> is_paused_;
std::optional<bool> is_paused_by_node_;
std::optional<bool> is_start_requested_;

double stop_check_duration_;
Expand Down

0 comments on commit 25f5a1a

Please sign in to comment.