Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Fix crashing kick after duplicate call
Browse files Browse the repository at this point in the history
  • Loading branch information
Flova committed Oct 23, 2023
1 parent c130413 commit 6d2bb64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class KickNode : public rclcpp::Node{
moveit::core::RobotStatePtr goal_state_;
moveit::core::RobotStatePtr current_state_;
OnSetParametersCallbackHandle::SharedPtr callback_handle_;
bool currently_kicking_ = false;

std::string base_link_frame_, base_footprint_frame_, l_sole_frame_, r_sole_frame_;

Expand Down
8 changes: 8 additions & 0 deletions bitbots_dynamic_kick/src/kick_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ rclcpp_action::CancelResponse KickNode::cancelCb(std::shared_ptr<rclcpp_action::
}

void KickNode::acceptedCb(const std::shared_ptr<KickGoalHandle> goal) {
// Set flag so no other goal can be accepted
currently_kicking_ = true;
// this needs to return quickly to avoid blocking the executor, so spin up a new thread
std::thread{std::bind(&KickNode::executeCb, this, std::placeholders::_1), goal}.detach();
}
Expand All @@ -269,6 +271,10 @@ rclcpp_action::GoalResponse KickNode::goalCb(
std::shared_ptr<const bitbots_msgs::action::Kick::Goal> goal) {
RCLCPP_INFO(this->get_logger(), "Received goal request");
(void) uuid;
if (currently_kicking_) {
RCLCPP_INFO(this->get_logger(), "Already kicking, rejecting new goal");
return rclcpp_action::GoalResponse::REJECT;
}
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
}

Expand Down Expand Up @@ -312,6 +318,8 @@ void KickNode::executeCb(const std::shared_ptr<KickGoalHandle> goal_handle) {
result->result = bitbots_msgs::action::Kick::Result::SUCCESS;
goal_handle->succeed(result);
}
// Reset flag so new goals can be accepted
currently_kicking_ = false;
}

void KickNode::loopEngine(const std::shared_ptr<rclcpp_action::ServerGoalHandle<bitbots_msgs::action::Kick>> goal_handle) {
Expand Down

0 comments on commit 6d2bb64

Please sign in to comment.