Skip to content

Commit 11bd2e9

Browse files
committed
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 a457828 commit 11bd2e9

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
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
}

src/control/script_command_interface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ bool ScriptCommandInterface::ftRtdeInputEnable(const bool enabled, const double
295295

296296
bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, const urcl::vector6d_t* kd)
297297
{
298+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
299+
urcl::VersionInformation::fromString("10.10.0"), __func__);
298300
const int message_length = 13;
299301
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
300302
uint8_t* b_pos = buffer;
@@ -327,6 +329,8 @@ bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, co
327329

328330
bool ScriptCommandInterface::setMaxJointTorques(const urcl::vector6d_t* max_joint_torques)
329331
{
332+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
333+
urcl::VersionInformation::fromString("10.10.0"), __func__);
330334
const int message_length = 7;
331335
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
332336
uint8_t* b_pos = buffer;

src/ur/ur_driver.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,29 @@ void UrDriver::init(const UrDriverConfiguration& config)
144144
data[BEGIN_REPLACE] = begin_replace.str();
145145

146146
data["ROBOT_SOFTWARE_VERSION"] = getVersion();
147-
148-
script_reader_.reset(new control::ScriptReader());
149-
std::string prog = script_reader_->readScriptFile(config.script_file, data);
150-
151147
const RobotType robot_type = primary_client_->getRobotType();
152148

153149
const control::PDControllerGains pd_gains = control::getPdGainsFromRobotType(robot_type);
150+
std::stringstream pd_gains_ss;
151+
if (robot_version_ < urcl::VersionInformation::fromString("5.10.0"))
154152
{
155-
std::stringstream ss;
156-
ss << "struct(kp=" << pd_gains.kp << ", kd=" << pd_gains.kd << ")";
157-
data[PD_CONTROLLER_GAINS_REPLACE] = ss.str();
153+
// 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.
154+
pd_gains_ss << 0;
158155
}
159-
156+
else
160157
{
161-
std::stringstream ss;
162-
ss << control::getMaxTorquesFromRobotType(robot_type);
163-
data[MAX_JOINT_TORQUE_REPLACE] = ss.str();
158+
pd_gains_ss << "struct(kp=" << pd_gains.kp << ", kd=" << pd_gains.kd << ")";
164159
}
160+
data[PD_CONTROLLER_GAINS_REPLACE] = pd_gains_ss.str();
161+
162+
std::stringstream max_torques_ss;
163+
max_torques_ss << control::getMaxTorquesFromRobotType(robot_type);
164+
data[MAX_JOINT_TORQUE_REPLACE] = max_torques_ss.str();
165+
166+
data["ROBOT_SOFTWARE_VERSION"] = getVersion();
167+
168+
script_reader_.reset(new control::ScriptReader());
169+
std::string prog = script_reader_->readScriptFile(config.script_file, data);
165170

166171
if (in_headless_mode_)
167172
{

0 commit comments

Comments
 (0)