Skip to content

Commit

Permalink
[moveit_servo] avoid race condition when calling ~/pause_servo (movei…
Browse files Browse the repository at this point in the history
…t#3059)

Co-authored-by: Sebastian Castro <[email protected]>
  • Loading branch information
patrickKXMD and sea-bass authored Nov 7, 2024
1 parent dfb3877 commit 1a77d7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class ServoNode
// Threads used by ServoNode
std::thread servo_loop_thread_;

// Locks for threads safety
std::mutex lock_;

// rolling window of joint commands
std::deque<KinematicState> joint_cmd_rolling_window_;
};
Expand Down
2 changes: 2 additions & 0 deletions moveit_ros/moveit_servo/src/servo_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void ServoNode::pauseServo(const std::shared_ptr<std_srvs::srv::SetBool::Request
}
else
{
std::lock_guard<std::mutex> lock_guard(lock_);
// Reset the smoothing plugin with the robot's current state in case the robot moved between pausing and unpausing.
last_commanded_state_ = servo_->getCurrentRobotState(true /* block for current robot state */);
servo_->resetSmoothing(last_commanded_state_);
Expand Down Expand Up @@ -320,6 +321,7 @@ void ServoNode::servoLoop()
continue;
}

std::lock_guard<std::mutex> lock_guard(lock_);
const bool use_trajectory = servo_params_.command_out_type == "trajectory_msgs/JointTrajectory";
const auto cur_time = node_->now();

Expand Down

0 comments on commit 1a77d7d

Please sign in to comment.