Skip to content

Commit be5ee47

Browse files
committed
Allow using the actual torques as joint efforts
1 parent 4b618c0 commit be5ee47

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
324324
const std::string TOOL_CONTACT_GPIO = "tool_contact";
325325

326326
std::unordered_map<std::string, std::unordered_map<std::string, bool>> mode_compatibility_;
327+
328+
bool use_currents_as_efforts_ = false;
327329
};
328330
} // namespace ur_robot_driver
329331

ur_robot_driver/launch/ur_rsp.launch.py

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

7778
script_filename = PathJoinSubstitution(
7879
[
@@ -184,6 +185,8 @@ def generate_launch_description():
184185
"trajectory_port:=",
185186
trajectory_port,
186187
" ",
188+
"use_currents_as_efforts:=",
189+
use_currents_as_efforts,
187190
]
188191
)
189192
robot_description = {
@@ -442,6 +445,13 @@ def generate_launch_description():
442445
description="Port that will be opened for trajectory control.",
443446
)
444447
)
448+
declared_arguments.append(
449+
DeclareLaunchArgument(
450+
"use_currents_as_efforts",
451+
default_value="true",
452+
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.",
453+
)
454+
)
445455

446456
return LaunchDescription(
447457
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,4 +26,5 @@ safety_mode
2626
robot_status_bits
2727
safety_status_bits
2828
actual_current
29+
actual_current_as_torque
2930
tcp_offset

ur_robot_driver/src/hardware_interface.cpp

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

514+
// Newer software version (5.23.0 / 10.11.0) support reporting the actual joint torques. On older
515+
// versions fall back to the currents, instead.
516+
use_currents_as_efforts_ = ((info_.hardware_parameters["use_currents_as_efforts"] == "true") ||
517+
(info_.hardware_parameters["use_currents_as_efforts"] == "True"));
518+
514519
// The ip address of the host the driver runs on
515520
std::string reverse_ip = info_.hardware_parameters["reverse_ip"];
516521
if (reverse_ip == "0.0.0.0") {
@@ -664,6 +669,17 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
664669
get_robot_software_version_build_ = version_info_.build;
665670
get_robot_software_version_bugfix_ = version_info_.bugfix;
666671

672+
if (!use_currents_as_efforts_) {
673+
if ((version_info_.major == 5 && version_info_.minor < 23) ||
674+
(version_info_.major == 10 && version_info_.minor < 11) || version_info_.major < 5) {
675+
RCLCPP_ERROR(get_logger(),
676+
"Driver configured to use actual torques as efforts, which is not supported by this software "
677+
"version %s. Please use version 5.23.0 / 10.11.0 or newer for this feature.",
678+
version_info_.toString().c_str());
679+
return hardware_interface::CallbackReturn::ERROR;
680+
}
681+
}
682+
667683
async_thread_ = std::make_shared<std::thread>(&URPositionHardwareInterface::asyncThread, this);
668684

669685
RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "System successfully started!");
@@ -774,7 +790,11 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
774790
packet_read_ = true;
775791
readData(data_pkg, "actual_q", urcl_joint_positions_);
776792
readData(data_pkg, "actual_qd", urcl_joint_velocities_);
777-
readData(data_pkg, "actual_current", urcl_joint_efforts_);
793+
if (use_currents_as_efforts_) {
794+
readData(data_pkg, "actual_current", urcl_joint_efforts_);
795+
} else {
796+
readData(data_pkg, "actual_current_as_torque", urcl_joint_efforts_);
797+
}
778798

779799
readData(data_pkg, "target_speed_fraction", target_speed_fraction_);
780800
readData(data_pkg, "speed_scaling", speed_scaling_);

ur_robot_driver/urdf/ur.ros2_control.xacro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
trajectory_port:=50003
2727
non_blocking_read:=true
2828
robot_receive_timeout:=0.04
29+
use_currents_as_efforts:=true
2930
">
3031

3132
<xacro:property name="config_kinematics_parameters" value="${xacro.load_yaml(kinematics_parameters_file)}"/>
@@ -71,6 +72,7 @@
7172
<param name="tool_device_name">${tool_device_name}</param>
7273
<param name="tool_tcp_port">${tool_tcp_port}</param>
7374
<param name="robot_receive_timeout">${robot_receive_timeout}</param>
75+
<param name="use_currents_as_efforts">${use_currents_as_efforts}</param>
7476
</xacro:unless>
7577
</hardware>
7678

ur_robot_driver/urdf/ur.urdf.xacro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<xacro:arg name="reverse_port" default="50001"/>
3434
<xacro:arg name="script_sender_port" default="50002"/>
3535
<xacro:arg name="trajectory_port" default="50003"/>
36+
<xacro:arg name="use_currents_as_efforts" default="true"/>
37+
3638
<!-- tool communication related parameters-->
3739
<xacro:arg name="use_tool_communication" default="false" />
3840
<xacro:arg name="tool_voltage" default="0" />
@@ -101,6 +103,7 @@
101103
reverse_port="$(arg reverse_port)"
102104
script_sender_port="$(arg script_sender_port)"
103105
trajectory_port="$(arg trajectory_port)"
106+
use_currents_as_efforts="$(arg use_currents_as_efforts)"
104107
/>
105108

106109
</robot>

0 commit comments

Comments
 (0)