4545#include " ur_client_library/exceptions.h"
4646#include " ur_client_library/ur/tool_communication.h"
4747
48- #include " rclcpp/rclcpp .hpp"
48+ #include < rclcpp/logging .hpp>
4949#include " hardware_interface/types/hardware_interface_type_values.hpp"
5050#include " ur_robot_driver/hardware_interface.hpp"
5151#include " ur_robot_driver/urcl_log_handler.hpp"
@@ -101,9 +101,9 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
101101 trajectory_joint_accelerations_.clear ();
102102
103103 for (const hardware_interface::ComponentInfo& joint : info_.joints ) {
104- if (joint.command_interfaces .size () != 2 ) {
104+ if (joint.command_interfaces .size () != 5 ) {
105105 RCLCPP_FATAL (rclcpp::get_logger (" URPositionHardwareInterface" ),
106- " Joint '%s' has %zu command interfaces found. 2 expected." , joint.name .c_str (),
106+ " Joint '%s' has %zu command interfaces found. 5 expected." , joint.name .c_str (),
107107 joint.command_interfaces .size ());
108108 return hardware_interface::CallbackReturn::ERROR;
109109 }
@@ -236,6 +236,9 @@ std::vector<hardware_interface::StateInterface> URPositionHardwareInterface::exp
236236 state_interfaces.emplace_back (
237237 hardware_interface::StateInterface (tf_prefix + " gpio" , " program_running" , &robot_program_running_copy_));
238238
239+ state_interfaces.emplace_back (hardware_interface::StateInterface (
240+ tf_prefix + " passthrough_controller" , " passthrough_trajectory_abort" , &passthrough_trajectory_abort_));
241+
239242 return state_interfaces;
240243}
241244
@@ -248,6 +251,15 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
248251
249252 command_interfaces.emplace_back (hardware_interface::CommandInterface (
250253 info_.joints [i].name , hardware_interface::HW_IF_VELOCITY, &urcl_velocity_commands_[i]));
254+
255+ command_interfaces.emplace_back (hardware_interface::CommandInterface (info_.joints [i].name , " passthrough_position" ,
256+ &passthrough_trajectory_positions_[i]));
257+
258+ command_interfaces.emplace_back (hardware_interface::CommandInterface (info_.joints [i].name , " passthrough_velocity" ,
259+ &passthrough_trajectory_velocities_[i]));
260+
261+ command_interfaces.emplace_back (hardware_interface::CommandInterface (
262+ info_.joints [i].name , " passthrough_acceleration" , &passthrough_trajectory_accelerations_[i]));
251263 }
252264 // Obtain the tf_prefix from the urdf so that we can have the general interface multiple times
253265 // NOTE using the tf_prefix at this point is some kind of workaround. One should actually go through the list of gpio
@@ -283,6 +295,8 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
283295 hardware_interface::CommandInterface (tf_prefix + " payload" , " cog.z" , &payload_center_of_gravity_[2 ]));
284296 command_interfaces.emplace_back (
285297 hardware_interface::CommandInterface (tf_prefix + " payload" , " payload_async_success" , &payload_async_success_));
298+ command_interfaces.emplace_back (hardware_interface::CommandInterface (
299+ tf_prefix + " passthrough_controller" , " passthrough_trajectory_abort" , &passthrough_trajectory_abort_));
286300
287301 for (size_t i = 0 ; i < 18 ; ++i) {
288302 command_interfaces.emplace_back (hardware_interface::CommandInterface (
@@ -307,27 +321,6 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
307321 " passthrough_trajectory_transfer_state" ,
308322 &passthrough_trajectory_transfer_state_));
309323
310- command_interfaces.emplace_back (hardware_interface::CommandInterface (
311- tf_prefix + " passthrough_controller" , " passthrough_trajectory_abort" , &passthrough_trajectory_abort_));
312-
313- for (size_t i = 0 ; i < 6 ; ++i) {
314- command_interfaces.emplace_back (hardware_interface::CommandInterface (
315- tf_prefix + " passthrough_controller" , " passthrough_trajectory_positions_" + std::to_string (i),
316- &passthrough_trajectory_positions_[i]));
317- }
318-
319- for (size_t i = 0 ; i < 6 ; ++i) {
320- command_interfaces.emplace_back (hardware_interface::CommandInterface (
321- tf_prefix + " passthrough_controller" , " passthrough_trajectory_velocities_" + std::to_string (i),
322- &passthrough_trajectory_velocities_[i]));
323- }
324-
325- for (size_t i = 0 ; i < 6 ; ++i) {
326- command_interfaces.emplace_back (hardware_interface::CommandInterface (
327- tf_prefix + " passthrough_controller" , " passthrough_trajectory_accelerations_" + std::to_string (i),
328- &passthrough_trajectory_accelerations_[i]));
329- }
330-
331324 command_interfaces.emplace_back (hardware_interface::CommandInterface (tf_prefix + " passthrough_controller" ,
332325 " passthrough_trajectory_time_from_start" ,
333326 &passthrough_trajectory_time_from_start_));
@@ -853,20 +846,11 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
853846 if (key == info_.joints [i].name + " /" + hardware_interface::HW_IF_VELOCITY) {
854847 start_modes_.push_back (hardware_interface::HW_IF_VELOCITY);
855848 }
856- if (key == tf_prefix + PASSTHROUGH_TRAJECTORY_CONTROLLER + std::to_string (i) ) {
849+ if (key == info_. joints [i]. name + " / " + PASSTHROUGH_TRAJECTORY_CONTROLLER + " _position " ) {
857850 start_modes_.push_back (PASSTHROUGH_TRAJECTORY_CONTROLLER);
858851 }
859852 }
860853 }
861- // set new mode to all interfaces at the same time
862- if (start_modes_.size () != 0 && start_modes_.size () != 6 ) {
863- ret_val = hardware_interface::return_type::ERROR;
864- }
865-
866- // all start interfaces must be the same - can't mix position and velocity control
867- if (start_modes_.size () != 0 && !std::equal (start_modes_.begin () + 1 , start_modes_.end (), start_modes_.begin ())) {
868- ret_val = hardware_interface::return_type::ERROR;
869- }
870854
871855 // Stopping interfaces
872856 // add stop interface per joint in tmp var for later check
@@ -878,14 +862,61 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
878862 if (key == info_.joints [i].name + " /" + hardware_interface::HW_IF_VELOCITY) {
879863 stop_modes_.push_back (StoppingInterface::STOP_VELOCITY);
880864 }
881- if (key == PASSTHROUGH_TRAJECTORY_CONTROLLER + std::to_string (i) ) {
865+ if (key == info_. joints [i]. name + " / " + PASSTHROUGH_TRAJECTORY_CONTROLLER + " _position " ) {
882866 stop_modes_.push_back (StoppingInterface::STOP_PASSTHROUGH);
883867 }
884868 }
885869 }
870+
871+ // set new mode to all interfaces at the same time
872+ if (start_modes_.size () != 0 && start_modes_.size () != 6 ) {
873+ RCLCPP_ERROR (get_logger (), " Either none or all joint interfaces must be started at once." );
874+ ret_val = hardware_interface::return_type::ERROR;
875+ }
876+
877+ if (position_controller_running_ &&
878+ std::none_of (stop_modes_.begin (), stop_modes_.end (),
879+ [](auto item) { return item == StoppingInterface::STOP_POSITION; }) &&
880+ std::any_of (start_modes_.begin (), start_modes_.end (), [this ](auto & item) {
881+ return (item == hardware_interface::HW_IF_VELOCITY || item == PASSTHROUGH_TRAJECTORY_CONTROLLER);
882+ })) {
883+ RCLCPP_ERROR (get_logger (), " Start of velocity or passthrough interface requested while there is the position "
884+ " interface running." );
885+ ret_val = hardware_interface::return_type::ERROR;
886+ }
887+
888+ if (velocity_controller_running_ &&
889+ std::none_of (stop_modes_.begin (), stop_modes_.end (),
890+ [](auto item) { return item == StoppingInterface::STOP_VELOCITY; }) &&
891+ std::any_of (start_modes_.begin (), start_modes_.end (), [this ](auto & item) {
892+ return (item == hardware_interface::HW_IF_POSITION || item == PASSTHROUGH_TRAJECTORY_CONTROLLER);
893+ })) {
894+ RCLCPP_ERROR (get_logger (), " Start of position or passthrough interface requested while there is the velocity "
895+ " interface running." );
896+ ret_val = hardware_interface::return_type::ERROR;
897+ }
898+
899+ if (passthrough_trajectory_controller_running_ &&
900+ std::none_of (stop_modes_.begin (), stop_modes_.end (),
901+ [](auto item) { return item == StoppingInterface::STOP_PASSTHROUGH; }) &&
902+ std::any_of (start_modes_.begin (), start_modes_.end (), [](auto & item) {
903+ return (item == hardware_interface::HW_IF_VELOCITY || item == hardware_interface::HW_IF_POSITION);
904+ })) {
905+ RCLCPP_ERROR (get_logger (), " Start of position or velocity interface requested while there is the passthrough "
906+ " interface running." );
907+ ret_val = hardware_interface::return_type::ERROR;
908+ }
909+
910+ // all start interfaces must be the same - can't mix position and velocity control
911+ if (start_modes_.size () != 0 && !std::equal (start_modes_.begin () + 1 , start_modes_.end (), start_modes_.begin ())) {
912+ RCLCPP_ERROR (get_logger (), " Can't mix different control domains for joint control." );
913+ ret_val = hardware_interface::return_type::ERROR;
914+ }
915+
886916 // stop all interfaces at the same time
887917 if (stop_modes_.size () != 0 &&
888918 (stop_modes_.size () != 6 || !std::equal (stop_modes_.begin () + 1 , stop_modes_.end (), stop_modes_.begin ()))) {
919+ RCLCPP_ERROR (get_logger (), " Either none or all joint interfaces must be stopped at once." );
889920 ret_val = hardware_interface::return_type::ERROR;
890921 }
891922
0 commit comments