Skip to content

Commit 1f3ac92

Browse files
urfeexurrsk
authored andcommitted
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 15ae64d commit 1f3ac92

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
@@ -93,6 +93,7 @@ void sendScriptCommands()
9393
g_my_robot->getUrDriver()->setPDControllerGains({ 500.0, 500.0, 300.0, 124.0, 124.0, 124.0 },
9494
{ 44.72, 44.72, 34.64, 22.27, 22.27, 22.27 });
9595
});
96+
// The following will have no effect on PolyScope < 5.23 / 10.10
9697
run_cmd("Setting max joint torques",
9798
[]() { g_my_robot->getUrDriver()->setMaxJointTorques({ 27.0, 27.0, 14.0, 4.5, 4.5, 4.5 }); });
9899
}

src/control/script_command_interface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ bool ScriptCommandInterface::setTcpOffset(const vector6d_t& offset)
387387

388388
bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, const urcl::vector6d_t* kd)
389389
{
390+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
391+
urcl::VersionInformation::fromString("10.10.0"), __func__);
390392
const int message_length = 13;
391393
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
392394
uint8_t* b_pos = buffer;
@@ -419,6 +421,8 @@ bool ScriptCommandInterface::setPDControllerGains(const urcl::vector6d_t* kp, co
419421

420422
bool ScriptCommandInterface::setMaxJointTorques(const urcl::vector6d_t* max_joint_torques)
421423
{
424+
robotVersionSupportsCommandOrWarn(urcl::VersionInformation::fromString("5.23.0"),
425+
urcl::VersionInformation::fromString("10.10.0"), __func__);
422426
const int message_length = 7;
423427
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
424428
uint8_t* b_pos = buffer;

src/ur/ur_driver.cpp

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

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

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

167172
if (in_headless_mode_)
168173
{

0 commit comments

Comments
 (0)