Skip to content

Commit 941448f

Browse files
committed
Allow using the actual torques as joint efforts
1 parent 08bab9a commit 941448f

6 files changed

Lines changed: 39 additions & 1 deletion

File tree

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
400400

401401
std::unique_ptr<urcl::rtde_interface::DataPackage> data_package_buffer_;
402402
std::function<bool()> get_data_package;
403+
404+
bool use_currents_as_efforts_ = false;
403405
};
404406
} // namespace ur_robot_driver
405407

ur_robot_driver/launch/ur_rsp.launch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def generate_launch_description():
7474
reverse_port = LaunchConfiguration("reverse_port")
7575
script_sender_port = LaunchConfiguration("script_sender_port")
7676
trajectory_port = LaunchConfiguration("trajectory_port")
77+
use_currents_as_efforts = LaunchConfiguration("use_currents_as_efforts")
7778

7879
script_filename = PathJoinSubstitution(
7980
[
@@ -191,6 +192,8 @@ def generate_launch_description():
191192
"trajectory_port:=",
192193
trajectory_port,
193194
" ",
195+
"use_currents_as_efforts:=",
196+
use_currents_as_efforts,
194197
]
195198
)
196199
robot_description = {
@@ -457,6 +460,13 @@ def generate_launch_description():
457460
description="Port that will be opened for trajectory control.",
458461
)
459462
)
463+
declared_arguments.append(
464+
DeclareLaunchArgument(
465+
"use_currents_as_efforts",
466+
default_value="true",
467+
description="Report motor currents as efforts. When set to false, the torques as reported from the robot are used. Note that this requires software 5.23.0 / 10.11.0.",
468+
)
469+
)
460470

461471
return LaunchDescription(
462472
declared_arguments

ur_robot_driver/resources/rtde_output_recipe.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ safety_mode
2626
robot_status_bits
2727
safety_status_bits
2828
actual_current
29+
actual_current_as_torque
2930
tcp_offset
3031
payload
3132
payload_cog

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
676676
// The driver will offer an interface to receive the program's URScript on this port.
677677
const int script_sender_port = stoi(info_.hardware_parameters["script_sender_port"]);
678678

679+
// Newer software version (5.23.0 / 10.11.0) support reporting the actual joint torques. On older
680+
// versions fall back to the currents, instead.
681+
use_currents_as_efforts_ = ((info_.hardware_parameters["use_currents_as_efforts"] == "true") ||
682+
(info_.hardware_parameters["use_currents_as_efforts"] == "True"));
683+
679684
// The ip address of the host the driver runs on
680685
std::string reverse_ip = info_.hardware_parameters["reverse_ip"];
681686
if (reverse_ip == "0.0.0.0") {
@@ -858,6 +863,17 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
858863
RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "Initializing InstructionExecutor");
859864
instruction_executor_ = std::make_shared<urcl::InstructionExecutor>(ur_driver_);
860865

866+
if (!use_currents_as_efforts_) {
867+
if ((version_info_.major == 5 && version_info_.minor < 23) ||
868+
(version_info_.major == 10 && version_info_.minor < 11) || version_info_.major < 5) {
869+
RCLCPP_ERROR(get_logger(),
870+
"Driver configured to use actual torques as efforts, which is not supported by this software "
871+
"version %s. Please use version 5.23.0 / 10.11.0 or newer for this feature.",
872+
version_info_.toString().c_str());
873+
return hardware_interface::CallbackReturn::ERROR;
874+
}
875+
}
876+
861877
async_thread_ = std::make_shared<std::thread>(&URPositionHardwareInterface::asyncThread, this);
862878

863879
// Start async thread for sending motion primitives
@@ -971,7 +987,11 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
971987
packet_read_ = true;
972988
readData(data_package_buffer_, "actual_q", urcl_joint_positions_);
973989
readData(data_package_buffer_, "actual_qd", urcl_joint_velocities_);
974-
readData(data_package_buffer_, "actual_current", urcl_joint_efforts_);
990+
if (use_currents_as_efforts_) {
991+
readData(data_package_buffer_, "actual_current", urcl_joint_efforts_);
992+
} else {
993+
readData(data_package_buffer_, "actual_current_as_torque", urcl_joint_efforts_);
994+
}
975995
readData(data_package_buffer_, "target_speed_fraction", target_speed_fraction_);
976996
readData(data_package_buffer_, "speed_scaling", speed_scaling_);
977997
readData(data_package_buffer_, "runtime_state", runtime_state_);

ur_robot_driver/urdf/ur.ros2_control.xacro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
robot_receive_timeout:=0.04
3030
rw_rate:=0
3131
verify_robot_model:=true
32+
use_currents_as_efforts:=true
3233
">
3334
<!-- rw_rate of 0 uses the rate of the controller_manager -->
3435

@@ -77,6 +78,7 @@
7778
<param name="tool_tcp_port">${tool_tcp_port}</param>
7879
<param name="robot_receive_timeout">${robot_receive_timeout}</param>
7980
<param name="verify_robot_model">${verify_robot_model}</param>
81+
<param name="use_currents_as_efforts">${use_currents_as_efforts}</param>
8082
</xacro:unless>
8183
</hardware>
8284

ur_robot_driver/urdf/ur.urdf.xacro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<xacro:arg name="script_sender_port" default="50002"/>
3535
<xacro:arg name="trajectory_port" default="50003"/>
3636
<xacro:arg name="verify_robot_model" default="true" />
37+
<xacro:arg name="use_currents_as_efforts" default="true"/>
38+
3739
<!-- tool communication related parameters-->
3840
<xacro:arg name="use_tool_communication" default="false" />
3941
<xacro:arg name="tool_voltage" default="0" />
@@ -104,6 +106,7 @@
104106
trajectory_port="$(arg trajectory_port)"
105107
ur_type="$(arg ur_type)"
106108
verify_robot_model="$(arg verify_robot_model)"
109+
use_currents_as_efforts="$(arg use_currents_as_efforts)"
107110
/>
108111

109112
</robot>

0 commit comments

Comments
 (0)