@@ -151,11 +151,8 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
151151 current_moprim_execution_status_ = MoprimExecutionState::IDLE;
152152 ready_for_new_moprim_ = false ;
153153 motion_primitives_forward_controller_running_ = false ;
154- // 2 States: execution_status, ready_for_new_primitive
155- hw_moprim_states_.resize (2 , std::numeric_limits<double >::quiet_NaN ());
156- // 25 Commands: // motion_type + 6 joints + 2*7 positions (goal and via) + blend_radius + velocity + acceleration +
157- // move_time
158- hw_moprim_commands_.resize (25 , std::numeric_limits<double >::quiet_NaN ());
154+ hw_moprim_states_.fill (std::numeric_limits<double >::quiet_NaN ());
155+ hw_moprim_commands_.fill (std::numeric_limits<double >::quiet_NaN ());
159156
160157 for (const hardware_interface::ComponentInfo& joint : info_.joints ) {
161158 if (joint.command_interfaces .size () != 2 ) {
@@ -1617,9 +1614,9 @@ void URPositionHardwareInterface::handleMoprimCommands()
16171614 RCLCPP_INFO (rclcpp::get_logger (" URPositionHardwareInterface" ), " Received Motion Primitives STOP command" );
16181615 resetMoprimCmdInterfaces ();
16191616 build_moprim_sequence_ = false ;
1620- moprim_sequence_.clear (); // delete motion sequence
1617+ moprim_sequence_.clear (); // delete motion sequence
16211618 ur_driver_->writeTrajectoryControlMessage (urcl::control::TrajectoryControlMessage::TRAJECTORY_CANCEL, -1 ,
1622- urcl::RobotReceiveTimeout::millisec (2000 ));
1619+ urcl::RobotReceiveTimeout::millisec (2000 ));
16231620 current_moprim_execution_status_ = MoprimExecutionState::STOPPING;
16241621 ready_for_new_moprim_ = false ;
16251622 break ;
@@ -1634,10 +1631,12 @@ void URPositionHardwareInterface::handleMoprimCommands()
16341631 }
16351632 default :
16361633 {
1637- std::lock_guard<std::mutex> guard (moprim_cmd_mutex_);
16381634 if (!new_moprim_cmd_available_) {
1639- // Copy command to thread-safe buffer
1640- pending_moprim_cmd_ = hw_moprim_commands_;
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+ }
16411640 new_moprim_cmd_available_ = true ;
16421641 resetMoprimCmdInterfaces ();
16431642 }
@@ -1661,13 +1660,12 @@ void URPositionHardwareInterface::asyncMoprimCmdThread()
16611660 while (!async_moprim_thread_shutdown_) {
16621661 // Check for new commands
16631662 if (new_moprim_cmd_available_) {
1664- // RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "[asyncMoprimCmdThread] New command available");
1665- std::vector<double > current_command;
1666- {
1667- std::lock_guard<std::mutex> guard (moprim_cmd_mutex_);
1668- current_command = pending_moprim_cmd_;
1669- new_moprim_cmd_available_ = false ;
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_." );
16701667 }
1668+ new_moprim_cmd_available_ = false ;
16711669
16721670 // Process the command
16731671 processMoprimMotionCmd (current_command);
@@ -1679,9 +1677,9 @@ void URPositionHardwareInterface::asyncMoprimCmdThread()
16791677 RCLCPP_INFO (rclcpp::get_logger (" URPositionHardwareInterface" ), " [asyncMoprimCmdThread] Exiting" );
16801678}
16811679
1682- void URPositionHardwareInterface::processMoprimMotionCmd (const std::vector <double >& command)
1680+ void URPositionHardwareInterface::processMoprimMotionCmd (const std::array <double , 25 >& command)
16831681{
1684- if (command. empty () || std::isnan (command[0 ])) {
1682+ if (std::isnan (command[0 ])) {
16851683 return ;
16861684 }
16871685 double velocity, acceleration, move_time;
@@ -1906,7 +1904,7 @@ void URPositionHardwareInterface::quaternionToRotVec(double qx, double qy, doubl
19061904 rz = axis.z () * angle; // rz
19071905}
19081906
1909- bool URPositionHardwareInterface::getMoprimTimeOrVelAndAcc (const std::vector <double >& command, double & velocity,
1907+ bool URPositionHardwareInterface::getMoprimTimeOrVelAndAcc (const std::array <double , 25 >& command, double & velocity,
19101908 double & acceleration, double & move_time)
19111909{
19121910 // Check if move_time is valid
@@ -1931,7 +1929,7 @@ bool URPositionHardwareInterface::getMoprimTimeOrVelAndAcc(const std::vector<dou
19311929 }
19321930}
19331931
1934- bool URPositionHardwareInterface::getMoprimVelAndAcc (const std::vector <double >& command, double & velocity,
1932+ bool URPositionHardwareInterface::getMoprimVelAndAcc (const std::array <double , 25 >& command, double & velocity,
19351933 double & acceleration, double & move_time)
19361934{
19371935 // Check if velocity and acceleration are valid
0 commit comments