Skip to content

Commit

Permalink
[moveit_servo] avoid race condition when calling ~/pause_servo
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickKXMD committed Nov 5, 2024
1 parent b3b1f73 commit 2bd78f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class ServoNode

// Threads used by ServoNode
std::thread servo_loop_thread_;
std::mutex lock_;

// rolling window of joint commands
std::deque<KinematicState> joint_cmd_rolling_window_;
Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -319,7 +320,7 @@ void ServoNode::servoLoop()
servo_frequency.sleep();
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 2bd78f8

Please sign in to comment.