diff --git a/moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp b/moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp index 56ba8f595b..b825c0664b 100644 --- a/moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp +++ b/moveit_ros/moveit_servo/include/moveit_servo/servo_node.hpp @@ -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 joint_cmd_rolling_window_; }; diff --git a/moveit_ros/moveit_servo/src/servo_node.cpp b/moveit_ros/moveit_servo/src/servo_node.cpp index 9eae434869..0226472215 100644 --- a/moveit_ros/moveit_servo/src/servo_node.cpp +++ b/moveit_ros/moveit_servo/src/servo_node.cpp @@ -151,6 +151,7 @@ void ServoNode::pauseServo(const std::shared_ptr 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_); @@ -320,6 +321,7 @@ void ServoNode::servoLoop() continue; } + std::lock_guard lock_guard(lock_); const bool use_trajectory = servo_params_.command_out_type == "trajectory_msgs/JointTrajectory"; const auto cur_time = node_->now();