Skip to content

Commit 1a77d7d

Browse files
[moveit_servo] avoid race condition when calling ~/pause_servo (#3059)
Co-authored-by: Sebastian Castro <[email protected]>
1 parent dfb3877 commit 1a77d7d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class ServoNode
133133
// Threads used by ServoNode
134134
std::thread servo_loop_thread_;
135135

136+
// Locks for threads safety
137+
std::mutex lock_;
138+
136139
// rolling window of joint commands
137140
std::deque<KinematicState> joint_cmd_rolling_window_;
138141
};

moveit_ros/moveit_servo/src/servo_node.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ void ServoNode::pauseServo(const std::shared_ptr<std_srvs::srv::SetBool::Request
151151
}
152152
else
153153
{
154+
std::lock_guard<std::mutex> lock_guard(lock_);
154155
// Reset the smoothing plugin with the robot's current state in case the robot moved between pausing and unpausing.
155156
last_commanded_state_ = servo_->getCurrentRobotState(true /* block for current robot state */);
156157
servo_->resetSmoothing(last_commanded_state_);
@@ -320,6 +321,7 @@ void ServoNode::servoLoop()
320321
continue;
321322
}
322323

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

0 commit comments

Comments
 (0)