Skip to content

Commit e0066d1

Browse files
committed
removed new_moprim_cmd_available_
1 parent b414756 commit e0066d1

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
294294
// Async thread handling
295295
std::shared_ptr<std::thread> async_moprim_cmd_thread_;
296296
std::atomic_bool async_moprim_thread_shutdown_;
297-
realtime_tools::LockFreeSPSCQueue<std::array<double, 25>, 1> moprim_cmd_queue_;
298-
std::atomic_bool new_moprim_cmd_available_;
297+
realtime_tools::LockFreeSPSCQueue<std::array<double, 25>, 1024> moprim_cmd_queue_;
298+
std::array<double, 25> current_moprim_command_;
299299

300300
// Status for communication with controller
301301
bool motion_primitives_forward_controller_running_;

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
147147

148148
// Motion primitives stuff
149149
async_moprim_thread_shutdown_ = false;
150-
new_moprim_cmd_available_ = false;
151150
current_moprim_execution_status_ = MoprimExecutionState::IDLE;
152151
ready_for_new_moprim_ = false;
153152
motion_primitives_forward_controller_running_ = false;
@@ -1631,15 +1630,15 @@ void URPositionHardwareInterface::handleMoprimCommands()
16311630
}
16321631
default:
16331632
{
1634-
if (!new_moprim_cmd_available_) {
1635-
// Push command to thread-safe queue
1636-
if (!moprim_cmd_queue_.push(hw_moprim_commands_)) {
1637-
RCLCPP_ERROR(rclcpp::get_logger("URPositionHardwareInterface"), "Failed to push command to "
1638-
"moprim_cmd_queue_");
1639-
}
1640-
new_moprim_cmd_available_ = true;
1641-
resetMoprimCmdInterfaces();
1633+
RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "Received moprim command");
1634+
// Push command to thread-safe queue
1635+
if (!moprim_cmd_queue_.push(hw_moprim_commands_)) {
1636+
RCLCPP_ERROR(rclcpp::get_logger("URPositionHardwareInterface"), "Failed to push command to "
1637+
"moprim_cmd_queue_");
1638+
return;
16421639
}
1640+
resetMoprimCmdInterfaces();
1641+
ready_for_new_moprim_ = true; // set to true to allow sending new commands
16431642
break;
16441643
}
16451644
}
@@ -1659,18 +1658,9 @@ void URPositionHardwareInterface::asyncMoprimCmdThread()
16591658
{
16601659
while (!async_moprim_thread_shutdown_) {
16611660
// Check for new commands
1662-
if (new_moprim_cmd_available_) {
1663-
std::array<double, 25> current_command;
1664-
if (!moprim_cmd_queue_.pop(current_command)) {
1665-
RCLCPP_ERROR(rclcpp::get_logger("URPositionHardwareInterface"), "Failed to pop the command from "
1666-
"moprim_cmd_queue_.");
1667-
}
1668-
new_moprim_cmd_available_ = false;
1669-
1670-
// Process the command
1671-
processMoprimMotionCmd(current_command);
1661+
if (moprim_cmd_queue_.pop(current_moprim_command_)) {
1662+
processMoprimMotionCmd(current_moprim_command_);
16721663
}
1673-
16741664
// Small sleep to prevent busy waiting
16751665
std::this_thread::sleep_for(std::chrono::milliseconds(10));
16761666
}
@@ -1694,7 +1684,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
16941684
"following commands to the motion sequence.");
16951685
build_moprim_sequence_ = true; // set flag to put all following commands into the motion sequence
16961686
moprim_sequence_.clear();
1697-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
16981687
return;
16991688
}
17001689

@@ -1709,7 +1698,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
17091698
moprim_sequence_.clear();
17101699
if (success) {
17111700
current_moprim_execution_status_ = MoprimExecutionState::SUCCESS;
1712-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
17131701
}
17141702
return;
17151703
}
@@ -1745,7 +1733,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
17451733
"velocity: %f, acceleration: %f, move_time: %f, blend_radius: %f",
17461734
joint_positions[0], joint_positions[1], joint_positions[2], joint_positions[3],
17471735
joint_positions[4], joint_positions[5], velocity, acceleration, move_time, blend_radius);
1748-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
17491736
return;
17501737
} else { // execute single primitive directly
17511738
current_moprim_execution_status_ = MoprimExecutionState::EXECUTING;
@@ -1757,7 +1744,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
17571744
bool success = instruction_executor_->moveJ(joint_positions, acceleration, velocity, move_time, blend_radius);
17581745
if (success) {
17591746
current_moprim_execution_status_ = MoprimExecutionState::SUCCESS;
1760-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
17611747
}
17621748
return;
17631749
}
@@ -1797,7 +1783,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
17971783
"velocity: %f, acceleration: %f, move_time: %f, blend_radius: %f",
17981784
pose.x, pose.y, pose.z, pose.rx, pose.ry, pose.rz, velocity, acceleration, move_time,
17991785
blend_radius);
1800-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
18011786
return;
18021787
} else { // execute single primitive directly
18031788
current_moprim_execution_status_ = MoprimExecutionState::EXECUTING;
@@ -1809,7 +1794,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
18091794
bool success = instruction_executor_->moveL(pose, acceleration, velocity, move_time, blend_radius);
18101795
if (success) {
18111796
current_moprim_execution_status_ = MoprimExecutionState::SUCCESS;
1812-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
18131797
}
18141798
return;
18151799
}
@@ -1858,7 +1842,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
18581842
via_pose.x, via_pose.y, via_pose.z, via_pose.rx, via_pose.ry, via_pose.rz, goal_pose.x,
18591843
goal_pose.y, goal_pose.z, goal_pose.rx, goal_pose.ry, goal_pose.rz, velocity, acceleration,
18601844
blend_radius, mode);
1861-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
18621845
return;
18631846
} else { // execute single primitive directly
18641847
current_moprim_execution_status_ = MoprimExecutionState::EXECUTING;
@@ -1872,7 +1855,6 @@ void URPositionHardwareInterface::processMoprimMotionCmd(const std::array<double
18721855
bool success = instruction_executor_->moveC(via_pose, goal_pose, acceleration, velocity, blend_radius, mode);
18731856
if (success) {
18741857
current_moprim_execution_status_ = MoprimExecutionState::SUCCESS;
1875-
ready_for_new_moprim_ = true; // set to true to allow sending new commands
18761858
}
18771859
return;
18781860
}

0 commit comments

Comments
 (0)