@@ -81,6 +81,7 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
81
81
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
82
82
position_controller_running_ = false ;
83
83
velocity_controller_running_ = false ;
84
+ torque_controller_running_ = false ;
84
85
freedrive_mode_controller_running_ = false ;
85
86
passthrough_trajectory_controller_running_ = false ;
86
87
tool_contact_controller_running_ = false ;
@@ -104,9 +105,9 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
104
105
trajectory_joint_accelerations_.reserve (32768 );
105
106
106
107
for (const hardware_interface::ComponentInfo& joint : info_.joints ) {
107
- if (joint.command_interfaces .size () != 2 ) {
108
+ if (joint.command_interfaces .size () != 3 ) {
108
109
RCLCPP_FATAL (rclcpp::get_logger (" URPositionHardwareInterface" ),
109
- " Joint '%s' has %zu command interfaces found. 2 expected." , joint.name .c_str (),
110
+ " Joint '%s' has %zu command interfaces found. 3 expected." , joint.name .c_str (),
110
111
joint.command_interfaces .size ());
111
112
return hardware_interface::CallbackReturn::ERROR;
112
113
}
@@ -289,6 +290,9 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
289
290
290
291
command_interfaces.emplace_back (hardware_interface::CommandInterface (
291
292
info_.joints [i].name , hardware_interface::HW_IF_VELOCITY, &urcl_velocity_commands_[i]));
293
+
294
+ command_interfaces.emplace_back (hardware_interface::CommandInterface (
295
+ info_.joints [i].name , hardware_interface::HW_IF_EFFORT, &urcl_torque_commands_[i]));
292
296
}
293
297
// Obtain the tf_prefix from the urdf so that we can have the general interface multiple times
294
298
// NOTE using the tf_prefix at this point is some kind of workaround. One should actually go through the list of gpio
@@ -771,6 +775,7 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
771
775
// initialize commands
772
776
urcl_position_commands_ = urcl_position_commands_old_ = urcl_joint_positions_;
773
777
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
778
+ urcl_torque_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
774
779
target_speed_fraction_cmd_ = NO_NEW_CMD_;
775
780
resend_robot_program_cmd_ = NO_NEW_CMD_;
776
781
zero_ftsensor_cmd_ = NO_NEW_CMD_;
@@ -805,7 +810,8 @@ hardware_interface::return_type URPositionHardwareInterface::write(const rclcpp:
805
810
806
811
} else if (velocity_controller_running_) {
807
812
ur_driver_->writeJointCommand (urcl_velocity_commands_, urcl::comm::ControlMode::MODE_SPEEDJ, receive_timeout_);
808
-
813
+ } else if (torque_controller_running_) {
814
+ ur_driver_->writeJointCommand (urcl_torque_commands_, urcl::comm::ControlMode::MODE_TORQUE, receive_timeout_);
809
815
} else if (freedrive_mode_controller_running_ && freedrive_activated_) {
810
816
ur_driver_->writeFreedriveControlMessage (urcl::control::FreedriveControlMessage::FREEDRIVE_NOOP);
811
817
@@ -1085,6 +1091,9 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1085
1091
if (velocity_controller_running_) {
1086
1092
control_modes[i] = { hardware_interface::HW_IF_VELOCITY };
1087
1093
}
1094
+ if (torque_controller_running_) {
1095
+ control_modes[i] = { hardware_interface::HW_IF_EFFORT };
1096
+ }
1088
1097
if (force_mode_controller_running_) {
1089
1098
control_modes[i].push_back (FORCE_MODE_GPIO);
1090
1099
}
@@ -1124,6 +1133,16 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1124
1133
return hardware_interface::return_type::ERROR;
1125
1134
}
1126
1135
start_modes_[i].push_back (hardware_interface::HW_IF_VELOCITY);
1136
+ } else if (key == info_.joints [i].name + " /" + hardware_interface::HW_IF_EFFORT) {
1137
+ if (std::any_of (start_modes_[i].begin (), start_modes_[i].end (), [&](const std::string& item) {
1138
+ return item == hardware_interface::HW_IF_POSITION || item == PASSTHROUGH_GPIO ||
1139
+ item == FORCE_MODE_GPIO || item == FREEDRIVE_MODE_GPIO;
1140
+ })) {
1141
+ RCLCPP_ERROR (get_logger (), " Attempting to start effort control while there is another control mode already "
1142
+ " requested." );
1143
+ return hardware_interface::return_type::ERROR;
1144
+ }
1145
+ start_modes_[i].push_back (hardware_interface::HW_IF_EFFORT);
1127
1146
} else if (key == tf_prefix + FORCE_MODE_GPIO + " /type" ) {
1128
1147
if (std::any_of (start_modes_[i].begin (), start_modes_[i].end (), [&](const std::string& item) {
1129
1148
return item == hardware_interface::HW_IF_POSITION || item == hardware_interface::HW_IF_VELOCITY;
@@ -1187,6 +1206,13 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1187
1206
[](const std::string& item) { return item == hardware_interface::HW_IF_VELOCITY; }),
1188
1207
control_modes[i].end ());
1189
1208
}
1209
+ if (key == info_.joints [i].name + " /" + hardware_interface::HW_IF_EFFORT) {
1210
+ stop_modes_[i].push_back (StoppingInterface::STOP_TORQUE);
1211
+ control_modes[i].erase (
1212
+ std::remove_if (control_modes[i].begin (), control_modes[i].end (),
1213
+ [](const std::string& item) { return item == hardware_interface::HW_IF_EFFORT; }),
1214
+ control_modes[i].end ());
1215
+ }
1190
1216
if (key == tf_prefix + FORCE_MODE_GPIO + " /disable_cmd" ) {
1191
1217
stop_modes_[i].push_back (StoppingInterface::STOP_FORCE_MODE);
1192
1218
control_modes[i].erase (std::remove_if (control_modes[i].begin (), control_modes[i].end (),
@@ -1312,6 +1338,24 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1312
1338
ret_val = hardware_interface::return_type::ERROR;
1313
1339
}
1314
1340
1341
+ // Effort mode requested to start
1342
+ if (std::any_of (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1343
+ [](auto & item) { return (item == hardware_interface::HW_IF_EFFORT); }) &&
1344
+ (std::any_of (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1345
+ [this ](auto & item) {
1346
+ return (item == hardware_interface::HW_IF_POSITION || item == hardware_interface::HW_IF_VELOCITY ||
1347
+ item == PASSTHROUGH_GPIO || item == FORCE_MODE_GPIO || item == FREEDRIVE_MODE_GPIO);
1348
+ }) ||
1349
+ std::any_of (control_modes[0 ].begin (), control_modes[0 ].end (), [this ](auto & item) {
1350
+ return (item == hardware_interface::HW_IF_EFFORT || item == hardware_interface::HW_IF_VELOCITY ||
1351
+ item == hardware_interface::HW_IF_POSITION || item == PASSTHROUGH_GPIO || item == FORCE_MODE_GPIO ||
1352
+ item == FREEDRIVE_MODE_GPIO);
1353
+ }))) {
1354
+ RCLCPP_ERROR (get_logger (), " Attempting to start velosity control while there is either trajectory passthrough or "
1355
+ " position mode or force_mode or freedrive mode running." );
1356
+ ret_val = hardware_interface::return_type::ERROR;
1357
+ }
1358
+
1315
1359
controllers_initialized_ = true ;
1316
1360
return ret_val;
1317
1361
}
@@ -1331,6 +1375,11 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
1331
1375
velocity_controller_running_ = false ;
1332
1376
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1333
1377
}
1378
+ if (stop_modes_[0 ].size () != 0 &&
1379
+ std::find (stop_modes_[0 ].begin (), stop_modes_[0 ].end (), StoppingInterface::STOP_TORQUE) != stop_modes_[0 ].end ()) {
1380
+ torque_controller_running_ = false ;
1381
+ urcl_torque_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1382
+ }
1334
1383
if (stop_modes_[0 ].size () != 0 && std::find (stop_modes_[0 ].begin (), stop_modes_[0 ].end (),
1335
1384
StoppingInterface::STOP_FORCE_MODE) != stop_modes_[0 ].end ()) {
1336
1385
force_mode_controller_running_ = false ;
@@ -1361,16 +1410,25 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
1361
1410
if (start_modes_.size () != 0 && std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1362
1411
hardware_interface::HW_IF_POSITION) != start_modes_[0 ].end ()) {
1363
1412
velocity_controller_running_ = false ;
1413
+ torque_controller_running_ = false ;
1364
1414
passthrough_trajectory_controller_running_ = false ;
1365
1415
urcl_position_commands_ = urcl_position_commands_old_ = urcl_joint_positions_;
1366
1416
position_controller_running_ = true ;
1367
1417
1368
1418
} else if (start_modes_[0 ].size () != 0 && std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1369
1419
hardware_interface::HW_IF_VELOCITY) != start_modes_[0 ].end ()) {
1370
1420
position_controller_running_ = false ;
1421
+ torque_controller_running_ = false ;
1371
1422
passthrough_trajectory_controller_running_ = false ;
1372
1423
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1373
1424
velocity_controller_running_ = true ;
1425
+ } else if (start_modes_[0 ].size () != 0 && std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1426
+ hardware_interface::HW_IF_EFFORT) != start_modes_[0 ].end ()) {
1427
+ position_controller_running_ = false ;
1428
+ velocity_controller_running_ = false ;
1429
+ torque_controller_running_ = true ;
1430
+ passthrough_trajectory_controller_running_ = false ;
1431
+ urcl_torque_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1374
1432
}
1375
1433
if (start_modes_[0 ].size () != 0 &&
1376
1434
std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (), FORCE_MODE_GPIO) != start_modes_[0 ].end ()) {
@@ -1380,13 +1438,15 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
1380
1438
std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (), PASSTHROUGH_GPIO) != start_modes_[0 ].end ()) {
1381
1439
velocity_controller_running_ = false ;
1382
1440
position_controller_running_ = false ;
1441
+ torque_controller_running_ = false ;
1383
1442
passthrough_trajectory_controller_running_ = true ;
1384
1443
passthrough_trajectory_abort_ = 0.0 ;
1385
1444
}
1386
1445
if (start_modes_[0 ].size () != 0 &&
1387
1446
std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (), FREEDRIVE_MODE_GPIO) != start_modes_[0 ].end ()) {
1388
1447
velocity_controller_running_ = false ;
1389
1448
position_controller_running_ = false ;
1449
+ torque_controller_running_ = false ;
1390
1450
freedrive_mode_controller_running_ = true ;
1391
1451
freedrive_activated_ = false ;
1392
1452
}
0 commit comments