Skip to content

Commit 1c419fc

Browse files
committed
Update to RTDE version and simplify urscript
- Update the pd_controller example to use the new RTDE version - Simplify direct_torque call in urscript
1 parent 1f3ac92 commit 1c419fc

File tree

3 files changed

+56
-44
lines changed

3 files changed

+56
-44
lines changed

examples/pd_controller_example.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ bool pd_control_loop(DataStorage& data_storage, const std::string& actual_data_n
103103

104104
urcl::vector6d_t actual, target, start = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
105105

106+
rtde_interface::DataPackage data_pkg(g_my_robot->getUrDriver()->getRTDEOutputRecipe());
107+
106108
bool first_pass = true;
107109
while (time < running_time)
108110
{
@@ -111,17 +113,17 @@ bool pd_control_loop(DataStorage& data_storage, const std::string& actual_data_n
111113
// robot will effectively be in charge of setting the frequency of this loop.
112114
// In a real-world application this thread should be scheduled with real-time priority in order
113115
// to ensure that this is called in time.
114-
std::unique_ptr<rtde_interface::DataPackage> data_pkg = g_my_robot->getUrDriver()->getDataPackage();
115-
if (!data_pkg)
116+
if (!g_my_robot->getUrDriver()->getDataPackage(data_pkg))
116117
{
117118
URCL_LOG_WARN("Could not get fresh data package from robot");
118119
return false;
119120
}
120121
// Read current joint positions from robot data
121-
if (!data_pkg->getData(actual_data_name, actual))
122+
if (!data_pkg.getData(actual_data_name, actual))
122123
{
123124
// This throwing should never happen unless misconfigured
124-
std::string error_msg = "Did not find" + actual_data_name + "in data sent from robot. This should not happen!";
125+
std::string error_msg =
126+
"Did not find '" + actual_data_name + "' in data sent from robot. This should not happen!";
125127
throw std::runtime_error(error_msg);
126128
}
127129

@@ -146,7 +148,8 @@ bool pd_control_loop(DataStorage& data_storage, const std::string& actual_data_n
146148
bool ret = g_my_robot->getUrDriver()->writeJointCommand(target, control_mode, RobotReceiveTimeout::millisec(100));
147149
if (!ret)
148150
{
149-
URCL_LOG_ERROR("Could not send joint command. Is the robot in remote control?");
151+
URCL_LOG_ERROR("Could not send joint command. Make sure that the robot is in remote control mode and connected "
152+
"with a network cable.");
150153
return false;
151154
}
152155

resources/external_control.urscript

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,41 @@ thread speedThread():
275275
stopj(STOPJ_ACCELERATION)
276276
end
277277

278+
# Helper function to call the direct torque control function depending on the software version
279+
def directTorqueControlCall(tau):
280+
{% if ROBOT_SOFTWARE_VERSION < v6.0.0 %}
281+
{% if ROBOT_SOFTWARE_VERSION >= v5.23.0 %}
282+
if friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_SCALES:
283+
{% if ROBOT_SOFTWARE_VERSION < v5.25.1 %}
284+
popup("Friction scales (viscous_scale/coulomb_scale) are supported from PolyScope 5.25.1. This robot runs an older version.", error=True, blocking=True)
285+
{% else %}
286+
direct_torque(tau, viscous_scale=viscous_scale, coulomb_scale=coulomb_scale)
287+
{% endif %}
288+
elif friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_LEGACY:
289+
direct_torque(tau, friction_comp=deprecated_friction_compensation_enabled)
290+
else:
291+
direct_torque(tau)
292+
end
293+
{% else %}
294+
popup("Torque control is only supported from software 5.23.0 and upwards.", error=True, blocking=True)
295+
{% endif %}
296+
{% elif ROBOT_SOFTWARE_VERSION >= v10.11.0 %}
297+
if friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_SCALES:
298+
{% if ROBOT_SOFTWARE_VERSION < v10.12.1 %}
299+
popup("Friction scales (viscous_scale/coulomb_scale) are supported from PolyScope X 10.12.1. This robot runs an older version.", error=True, blocking=True)
300+
{% else %}
301+
direct_torque(tau, viscous_scale=viscous_scale, coulomb_scale=coulomb_scale)
302+
{% endif %}
303+
elif friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_LEGACY:
304+
direct_torque(tau, friction_comp=deprecated_friction_compensation_enabled)
305+
else:
306+
direct_torque(tau)
307+
end
308+
{% else %}
309+
popup("Torque control is only supported from software 10.11.0 and upwards.", error=True, blocking=True)
310+
{% endif %}
311+
end
312+
278313
# Helpers for torque control
279314
def set_torque(target_torque):
280315
cmd_torque = target_torque
@@ -284,38 +319,8 @@ end
284319
thread torqueThread():
285320
textmsg("ExternalControl: Starting torque thread")
286321
while control_mode == MODE_TORQUE:
287-
torque = cmd_torque
288-
{% if ROBOT_SOFTWARE_VERSION < v6.0.0 %}
289-
{% if ROBOT_SOFTWARE_VERSION >= v5.23.0 %}
290-
if friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_SCALES:
291-
{% if ROBOT_SOFTWARE_VERSION < v5.25.1 %}
292-
popup("Friction scales (viscous_scale/coulomb_scale) are supported from PolyScope 5.25.1. This robot runs an older version.", error=True, blocking=True)
293-
{% else %}
294-
direct_torque(torque, viscous_scale=viscous_scale, coulomb_scale=coulomb_scale)
295-
{% endif %}
296-
elif friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_LEGACY:
297-
direct_torque(torque, friction_comp=deprecated_friction_compensation_enabled)
298-
else:
299-
direct_torque(torque) # Uses robot defaults
300-
end
301-
{% else %}
302-
popup("Torque control is only supported from software 5.23.0 and upwards.", error=True, blocking=True)
303-
{% endif %}
304-
{% elif ROBOT_SOFTWARE_VERSION >= v10.11.0 %}
305-
if friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_SCALES:
306-
{% if ROBOT_SOFTWARE_VERSION < v10.12.1 %}
307-
popup("Friction scales (viscous_scale/coulomb_scale) are supported from PolyScope X 10.12.1. This robot runs an older version.", error=True, blocking=True)
308-
{% else %}
309-
direct_torque(torque, viscous_scale=viscous_scale, coulomb_scale=coulomb_scale)
310-
{% endif %}
311-
elif friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_LEGACY:
312-
direct_torque(torque, friction_comp=deprecated_friction_compensation_enabled)
313-
else:
314-
direct_torque(torque) # Uses robot defaults
315-
end
316-
{% else %}
317-
popup("Torque control is only supported from software 10.11.0 and upwards.", error=True, blocking=True)
318-
{% endif %}
322+
local tau = cmd_torque
323+
directTorqueControlCall(tau)
319324
end
320325
textmsg("ExternalControl: torque thread ended")
321326
stopj(STOPJ_ACCELERATION)
@@ -782,13 +787,7 @@ thread PDControlThread():
782787
local q_err = cmd_servo_q - get_actual_joint_positions()
783788
local tau = pd_controller_gains.kp * q_err - pd_controller_gains.kd * get_actual_joint_speeds()
784789
tau = clamp_array(tau, max_joint_torques)
785-
if friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_SCALES:
786-
direct_torque(tau, viscous_scale=viscous_scale, coulomb_scale=coulomb_scale)
787-
elif friction_compensation_mode == FRICTION_COMP_MODE_FRICTION_LEGACY:
788-
direct_torque(tau, friction_comp=deprecated_friction_compensation_enabled)
789-
else:
790-
direct_torque(tau)
791-
end
790+
directTorqueControlCall(tau)
792791
end
793792
textmsg("PD Control thread ended")
794793
stopj(STOPJ_ACCELERATION)

tests/test_script_reader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ TEST_F(ScriptReaderTest, TestDirectTorquePopupOnOldVersion)
507507
data["SERVER_PORT_REPLACE"] = "50001";
508508
data["TRAJECTORY_SERVER_PORT_REPLACE"] = "50003";
509509
data["SCRIPT_COMMAND_SERVER_PORT_REPLACE"] = "50004";
510+
data["PD_CONTROLLER_GAINS_REPLACE"] = "struct(kp=100, kd=20)";
511+
data["MAX_JOINT_TORQUE_REPLACE"] = "[150, 150, 150, 28, 28, 28]";
510512

511513
data["ROBOT_SOFTWARE_VERSION"] = urcl::VersionInformation::fromString("5.22.0");
512514
std::string processed_script = reader.readScriptFile(existing_script_file, data);
@@ -534,6 +536,8 @@ TEST_F(ScriptReaderTest, TestFrictionCompensationConstantsAndHandlerPolyScope523
534536
data["SERVER_PORT_REPLACE"] = "50001";
535537
data["TRAJECTORY_SERVER_PORT_REPLACE"] = "50003";
536538
data["SCRIPT_COMMAND_SERVER_PORT_REPLACE"] = "50004";
539+
data["PD_CONTROLLER_GAINS_REPLACE"] = "struct(kp=100, kd=20)";
540+
data["MAX_JOINT_TORQUE_REPLACE"] = "[150, 150, 150, 28, 28, 28]";
537541
data["ROBOT_SOFTWARE_VERSION"] = urcl::VersionInformation::fromString("5.23.0");
538542

539543
std::string processed_script = reader.readScriptFile(existing_script_file, data);
@@ -564,6 +568,8 @@ TEST_F(ScriptReaderTest, TestFrictionCompensationConstantsAndHandlerPolyScope101
564568
data["SERVER_PORT_REPLACE"] = "50001";
565569
data["TRAJECTORY_SERVER_PORT_REPLACE"] = "50003";
566570
data["SCRIPT_COMMAND_SERVER_PORT_REPLACE"] = "50004";
571+
data["PD_CONTROLLER_GAINS_REPLACE"] = "struct(kp=100, kd=20)";
572+
data["MAX_JOINT_TORQUE_REPLACE"] = "[150, 150, 150, 28, 28, 28]";
567573
data["ROBOT_SOFTWARE_VERSION"] = urcl::VersionInformation::fromString("10.11.0");
568574

569575
std::string processed_script = reader.readScriptFile(existing_script_file, data);
@@ -595,6 +601,8 @@ TEST_F(ScriptReaderTest, TestFrictionScalesConstantsAndHandler)
595601
data["SERVER_PORT_REPLACE"] = "50001";
596602
data["TRAJECTORY_SERVER_PORT_REPLACE"] = "50003";
597603
data["SCRIPT_COMMAND_SERVER_PORT_REPLACE"] = "50004";
604+
data["PD_CONTROLLER_GAINS_REPLACE"] = "struct(kp=100, kd=20)";
605+
data["MAX_JOINT_TORQUE_REPLACE"] = "[150, 150, 150, 28, 28, 28]";
598606

599607
data["ROBOT_SOFTWARE_VERSION"] = urcl::VersionInformation::fromString("5.25.1");
600608
std::string processed_script = reader.readScriptFile(existing_script_file, data);
@@ -632,6 +640,8 @@ TEST_F(ScriptReaderTest, TestProduceAllScriptFiles)
632640
data["SERVER_PORT_REPLACE"] = "50001";
633641
data["TRAJECTORY_SERVER_PORT_REPLACE"] = "50003";
634642
data["SCRIPT_COMMAND_SERVER_PORT_REPLACE"] = "50004";
643+
data["PD_CONTROLLER_GAINS_REPLACE"] = "struct(kp=100, kd=20)";
644+
data["MAX_JOINT_TORQUE_REPLACE"] = "[150, 150, 150, 28, 28, 28]";
635645

636646
// List of software versions to test
637647
std::vector<urcl::VersionInformation> software_versions = {

0 commit comments

Comments
 (0)