Skip to content

Commit 46c1dd6

Browse files
authored
Add torque_command statement only on supported software versions (#348)
This way all non-torque-control-related things should work on software versions not supporting torque control
1 parent 5b55989 commit 46c1dd6

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

examples/pd_controller_example.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ int main(int argc, char* argv[])
185185
return 1;
186186
}
187187

188+
{
189+
auto robot_version = g_my_robot->getUrDriver()->getVersion();
190+
if (robot_version < urcl::VersionInformation::fromString("5.23.0") ||
191+
(robot_version.major > 5 && robot_version < urcl::VersionInformation::fromString("10.10.0")))
192+
{
193+
URCL_LOG_ERROR("This example requires a robot with at least version 5.23.0 / 10.10.0. Your robot has version %s.",
194+
robot_version.toString().c_str());
195+
return 0;
196+
}
197+
}
198+
188199
auto instruction_executor = std::make_shared<urcl::InstructionExecutor>(g_my_robot->getUrDriver());
189200

190201
URCL_LOG_INFO("Move the robot to initial position");

examples/script_command_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void sendScriptCommands()
7878
g_my_robot->getUrDriver()->setPDControllerGains({ 500.0, 500.0, 300.0, 124.0, 124.0, 124.0 },
7979
{ 44.72, 44.72, 34.64, 22.27, 22.27, 22.27 });
8080
});
81+
// The following will have no effect on PolyScope < 5.23 / 10.10
8182
run_cmd("Setting max joint torques",
8283
[]() { g_my_robot->getUrDriver()->setMaxJointTorques({ 27.0, 27.0, 14.0, 4.5, 4.5, 4.5 }); });
8384
}

include/ur_client_library/control/script_command_interface.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "ur_client_library/control/reverse_interface.h"
3333
#include "ur_client_library/ur/tool_communication.h"
34+
#include "ur_client_library/ur/version_information.h"
3435

3536
namespace urcl
3637
{
@@ -235,6 +236,25 @@ class ScriptCommandInterface : public ReverseInterface
235236
SET_MAX_JOINT_TORQUES = 9, ///< Set max joint torques
236237
};
237238

239+
/*!
240+
* \brief Checks if the robot version is higher than the minimum required version for Polyscope 5
241+
* or Polyscope X.
242+
*
243+
* If the robot version is lower than the minimum required version, this function
244+
* will log a warning message.
245+
* In case of a PolyScope 5 robot, the robot's software version will be checked against \p
246+
* min_polyscope5, and in case of a PolyScope X robot, it will be checked against \p
247+
* min_polyscopeX.
248+
*
249+
* \param min_polyscope5 Minimum required version for PolyScope 5
250+
* \param min_polyscopeX Minimum required version for PolyScope X
251+
* \param command_name Name of the command being checked, used for logging
252+
*
253+
* \returns True if the robot version is higher than the versions provided, false otherwise.
254+
*/
255+
bool robotVersionSupportsCommandOrWarn(const VersionInformation& min_polyscope5,
256+
const VersionInformation& min_polyscopeX, const std::string& command_name);
257+
238258
bool client_connected_;
239259
static const int MAX_MESSAGE_LENGTH = 28;
240260

resources/external_control.urscript

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,17 @@ thread torqueThread():
270270
textmsg("ExternalControl: Starting torque thread")
271271
while control_mode == MODE_TORQUE:
272272
torque = cmd_torque
273+
{% if ROBOT_SOFTWARE_VERSION >= v5.23.0 %}
274+
{% if ROBOT_SOFTWARE_VERSION < v6.0.0 %}
273275
torque_command(torque, friction_comp=friction_compensation_enabled)
276+
{% elif ROBOT_SOFTWARE_VERSION >= v10.10.0 %}
277+
torque_command(torque, friction_comp=friction_compensation_enabled)
278+
{% else %}
279+
popup("Torque control is only supported from software 10.10.0 and upwards.", error=True, blocking=True)
280+
{% endif %}
281+
{% else %}
282+
popup("Torque control is only supported from software 5.23.0 and upwards.", error=True, blocking=True)
283+
{% endif %}
274284
end
275285
textmsg("ExternalControl: torque thread ended")
276286
stopj(STOPJ_ACCELERATION)
@@ -678,9 +688,21 @@ end
678688
thread PDControlThread():
679689
while control_mode == MODE_PD_CONTROLLER_JOINT or control_mode == MODE_PD_CONTROLLER_TASK:
680690
local q_err = cmd_servo_q - get_actual_joint_positions()
691+
{% if ROBOT_SOFTWARE_VERSION >= v5.23.0 %}
692+
{% if ROBOT_SOFTWARE_VERSION < v6.0.0 %}
693+
local tau = pd_controller_gains.kp * q_err - pd_controller_gains.kd * get_actual_joint_speeds()
694+
tau = clamp_array(tau, max_joint_torques)
695+
torque_command(tau, friction_comp=friction_compensation_enabled)
696+
{% elif ROBOT_SOFTWARE_VERSION >= v10.10.0 %}
681697
local tau = pd_controller_gains.kp * q_err - pd_controller_gains.kd * get_actual_joint_speeds()
682698
tau = clamp_array(tau, max_joint_torques)
683699
torque_command(tau, friction_comp=friction_compensation_enabled)
700+
{% else %}
701+
popup("Torque control is only supported from software 10.10.0 and upwards.", error=True, blocking=True)
702+
{% endif %}
703+
{% else %}
704+
popup("Torque control is only supported from software 5.23.0 and upwards.", error=True, blocking=True)
705+
{% endif %}
684706
end
685707
textmsg("PD Control thread ended")
686708
stopj(STOPJ_ACCELERATION)
@@ -760,8 +782,10 @@ thread script_commands():
760782
friction_compensation_enabled = True
761783
end
762784
elif command == SET_PD_CONTROLLER_GAINS:
785+
{% if ROBOT_SOFTWARE_VERSION > v5.10.0 %}
763786
pd_controller_gains.kp = [raw_command[2] / MULT_jointstate, raw_command[3] / MULT_jointstate, raw_command[4] / MULT_jointstate, raw_command[5] / MULT_jointstate, raw_command[6] / MULT_jointstate, raw_command[7] / MULT_jointstate]
764787
pd_controller_gains.kd = [raw_command[8] / MULT_jointstate, raw_command[9] / MULT_jointstate, raw_command[10] / MULT_jointstate, raw_command[11] / MULT_jointstate, raw_command[12] / MULT_jointstate, raw_command[13] / MULT_jointstate]
788+
{% endif %}
765789
elif command == SET_MAX_JOINT_TORQUES:
766790
max_joint_torques = [raw_command[2] / MULT_jointstate, raw_command[3] / MULT_jointstate, raw_command[4] / MULT_jointstate, raw_command[5] / MULT_jointstate, raw_command[6] / MULT_jointstate, raw_command[7] / MULT_jointstate]
767791
end

src/control/script_command_interface.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ bool ScriptCommandInterface::endToolContact()
228228

229229
bool ScriptCommandInterface::setFrictionCompensation(const bool friction_compensation_enabled)
230230
{
231+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
232+
urcl::VersionInformation::fromString("10.10.0"), __func__);
231233
const int message_length = 2;
232234
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
233235
uint8_t* b_pos = buffer;
@@ -251,6 +253,8 @@ bool ScriptCommandInterface::setFrictionCompensation(const bool friction_compens
251253

252254
bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, const urcl::vector6d_t* kd)
253255
{
256+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
257+
urcl::VersionInformation::fromString("10.10.0"), __func__);
254258
const int message_length = 13;
255259
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
256260
uint8_t* b_pos = buffer;
@@ -283,6 +287,8 @@ bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, co
283287

284288
bool ScriptCommandInterface::setMaxJointTorques(const urcl::vector6d_t* max_joint_torques)
285289
{
290+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
291+
urcl::VersionInformation::fromString("10.10.0"), __func__);
286292
const int message_length = 7;
287293
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
288294
uint8_t* b_pos = buffer;
@@ -356,6 +362,21 @@ void ScriptCommandInterface::messageCallback(const socket_t filedescriptor, char
356362
nbytesrecv);
357363
}
358364
}
365+
bool ScriptCommandInterface::robotVersionSupportsCommandOrWarn(const VersionInformation& min_polyscope5,
366+
const VersionInformation& min_polyscopeX,
367+
const std::string& command_name)
368+
{
369+
if (robot_software_version_ < min_polyscope5 ||
370+
(robot_software_version_.major > 5 && robot_software_version_ < min_polyscopeX))
371+
{
372+
URCL_LOG_WARN("%s is only available for robots with PolyScope %s / %s or "
373+
"later. This robot's version is %s. This command will have no effect.",
374+
command_name.c_str(), min_polyscope5.toString().c_str(), min_polyscopeX.toString().c_str(),
375+
robot_software_version_.toString().c_str());
376+
return false;
377+
}
378+
return true;
379+
}
359380

360381
} // namespace control
361-
} // namespace urcl
382+
} // namespace urcl

src/ur/ur_driver.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,23 @@ void UrDriver::init(const UrDriverConfiguration& config)
147147

148148
const control::PDControllerGains pd_gains = control::getPdGainsFromRobotType(robot_type);
149149
std::stringstream pd_gains_ss;
150-
pd_gains_ss << "struct(kp=" << pd_gains.kp << ", kd=" << pd_gains.kd << ")";
150+
if (robot_version_ < urcl::VersionInformation::fromString("5.10.0"))
151+
{
152+
// Structs are only available in URScript 5.10 and later. It isn't used pre 5.23, so we can safely set it to 0.
153+
pd_gains_ss << 0;
154+
}
155+
else
156+
{
157+
pd_gains_ss << "struct(kp=" << pd_gains.kp << ", kd=" << pd_gains.kd << ")";
158+
}
151159
data[PD_CONTROLLER_GAINS_REPLACE] = pd_gains_ss.str();
152160

153161
std::stringstream max_torques_ss;
154162
max_torques_ss << control::getMaxTorquesFromRobotType(robot_type);
155163
data[MAX_JOINT_TORQUE_REPLACE] = max_torques_ss.str();
156164

165+
data["ROBOT_SOFTWARE_VERSION"] = getVersion();
166+
157167
script_reader_.reset(new control::ScriptReader());
158168
std::string prog = script_reader_->readScriptFile(config.script_file, data);
159169

0 commit comments

Comments
 (0)