@@ -60,37 +60,50 @@ namespace ur_robot_driver
60
60
URPositionHardwareInterface::URPositionHardwareInterface ()
61
61
{
62
62
mode_compatibility_[hardware_interface::HW_IF_POSITION][hardware_interface::HW_IF_VELOCITY] = false ;
63
+ mode_compatibility_[hardware_interface::HW_IF_POSITION][hardware_interface::HW_IF_EFFORT] = false ;
63
64
mode_compatibility_[hardware_interface::HW_IF_POSITION][FORCE_MODE_GPIO] = false ;
64
65
mode_compatibility_[hardware_interface::HW_IF_POSITION][PASSTHROUGH_GPIO] = false ;
65
66
mode_compatibility_[hardware_interface::HW_IF_POSITION][FREEDRIVE_MODE_GPIO] = false ;
66
67
mode_compatibility_[hardware_interface::HW_IF_POSITION][TOOL_CONTACT_GPIO] = true ;
67
68
68
69
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][hardware_interface::HW_IF_POSITION] = false ;
70
+ mode_compatibility_[hardware_interface::HW_IF_VELOCITY][hardware_interface::HW_IF_EFFORT] = false ;
69
71
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][FORCE_MODE_GPIO] = false ;
70
72
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][PASSTHROUGH_GPIO] = false ;
71
73
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][FREEDRIVE_MODE_GPIO] = false ;
72
74
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][TOOL_CONTACT_GPIO] = true ;
73
75
76
+ mode_compatibility_[hardware_interface::HW_IF_EFFORT][hardware_interface::HW_IF_POSITION] = false ;
77
+ mode_compatibility_[hardware_interface::HW_IF_EFFORT][hardware_interface::HW_IF_VELOCITY] = false ;
78
+ mode_compatibility_[hardware_interface::HW_IF_EFFORT][FORCE_MODE_GPIO] = false ;
79
+ mode_compatibility_[hardware_interface::HW_IF_EFFORT][PASSTHROUGH_GPIO] = false ;
80
+ mode_compatibility_[hardware_interface::HW_IF_EFFORT][FREEDRIVE_MODE_GPIO] = false ;
81
+ mode_compatibility_[hardware_interface::HW_IF_EFFORT][TOOL_CONTACT_GPIO] = true ;
82
+
74
83
mode_compatibility_[FORCE_MODE_GPIO][hardware_interface::HW_IF_POSITION] = false ;
75
84
mode_compatibility_[FORCE_MODE_GPIO][hardware_interface::HW_IF_VELOCITY] = false ;
85
+ mode_compatibility_[FORCE_MODE_GPIO][hardware_interface::HW_IF_EFFORT] = false ;
76
86
mode_compatibility_[FORCE_MODE_GPIO][PASSTHROUGH_GPIO] = true ;
77
87
mode_compatibility_[FORCE_MODE_GPIO][FREEDRIVE_MODE_GPIO] = false ;
78
88
mode_compatibility_[FORCE_MODE_GPIO][TOOL_CONTACT_GPIO] = false ;
79
89
80
90
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_POSITION] = false ;
81
91
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_VELOCITY] = false ;
92
+ mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_EFFORT] = false ;
82
93
mode_compatibility_[PASSTHROUGH_GPIO][FORCE_MODE_GPIO] = true ;
83
94
mode_compatibility_[PASSTHROUGH_GPIO][FREEDRIVE_MODE_GPIO] = false ;
84
95
mode_compatibility_[PASSTHROUGH_GPIO][TOOL_CONTACT_GPIO] = true ;
85
96
86
97
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_POSITION] = false ;
87
98
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_VELOCITY] = false ;
99
+ mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_EFFORT] = false ;
88
100
mode_compatibility_[FREEDRIVE_MODE_GPIO][FORCE_MODE_GPIO] = false ;
89
101
mode_compatibility_[FREEDRIVE_MODE_GPIO][PASSTHROUGH_GPIO] = false ;
90
102
mode_compatibility_[FREEDRIVE_MODE_GPIO][TOOL_CONTACT_GPIO] = false ;
91
103
92
104
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_POSITION] = true ;
93
105
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_VELOCITY] = true ;
106
+ mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_EFFORT] = true ;
94
107
mode_compatibility_[TOOL_CONTACT_GPIO][FORCE_MODE_GPIO] = false ;
95
108
mode_compatibility_[TOOL_CONTACT_GPIO][PASSTHROUGH_GPIO] = true ;
96
109
mode_compatibility_[TOOL_CONTACT_GPIO][FREEDRIVE_MODE_GPIO] = false ;
@@ -120,6 +133,7 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
120
133
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
121
134
position_controller_running_ = false ;
122
135
velocity_controller_running_ = false ;
136
+ torque_controller_running_ = false ;
123
137
freedrive_mode_controller_running_ = false ;
124
138
passthrough_trajectory_controller_running_ = false ;
125
139
tool_contact_controller_running_ = false ;
@@ -143,9 +157,9 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
143
157
trajectory_joint_accelerations_.reserve (32768 );
144
158
145
159
for (const hardware_interface::ComponentInfo& joint : info_.joints ) {
146
- if (joint.command_interfaces .size () != 2 ) {
160
+ if (joint.command_interfaces .size () != 3 ) {
147
161
RCLCPP_FATAL (rclcpp::get_logger (" URPositionHardwareInterface" ),
148
- " Joint '%s' has %zu command interfaces found. 2 expected." , joint.name .c_str (),
162
+ " Joint '%s' has %zu command interfaces found. 3 expected." , joint.name .c_str (),
149
163
joint.command_interfaces .size ());
150
164
return hardware_interface::CallbackReturn::ERROR;
151
165
}
@@ -328,6 +342,9 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
328
342
329
343
command_interfaces.emplace_back (hardware_interface::CommandInterface (
330
344
info_.joints [i].name , hardware_interface::HW_IF_VELOCITY, &urcl_velocity_commands_[i]));
345
+
346
+ command_interfaces.emplace_back (hardware_interface::CommandInterface (
347
+ info_.joints [i].name , hardware_interface::HW_IF_EFFORT, &urcl_torque_commands_[i]));
331
348
}
332
349
// Obtain the tf_prefix from the urdf so that we can have the general interface multiple times
333
350
// NOTE using the tf_prefix at this point is some kind of workaround. One should actually go through the list of gpio
@@ -810,6 +827,7 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
810
827
// initialize commands
811
828
urcl_position_commands_ = urcl_position_commands_old_ = urcl_joint_positions_;
812
829
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
830
+ urcl_torque_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
813
831
target_speed_fraction_cmd_ = NO_NEW_CMD_;
814
832
resend_robot_program_cmd_ = NO_NEW_CMD_;
815
833
zero_ftsensor_cmd_ = NO_NEW_CMD_;
@@ -844,7 +862,8 @@ hardware_interface::return_type URPositionHardwareInterface::write(const rclcpp:
844
862
845
863
} else if (velocity_controller_running_) {
846
864
ur_driver_->writeJointCommand (urcl_velocity_commands_, urcl::comm::ControlMode::MODE_SPEEDJ, receive_timeout_);
847
-
865
+ } else if (torque_controller_running_) {
866
+ ur_driver_->writeJointCommand (urcl_torque_commands_, urcl::comm::ControlMode::MODE_TORQUE, receive_timeout_);
848
867
} else if (freedrive_mode_controller_running_ && freedrive_activated_) {
849
868
ur_driver_->writeFreedriveControlMessage (urcl::control::FreedriveControlMessage::FREEDRIVE_NOOP);
850
869
@@ -1124,6 +1143,9 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1124
1143
if (velocity_controller_running_) {
1125
1144
control_modes[i] = { hardware_interface::HW_IF_VELOCITY };
1126
1145
}
1146
+ if (torque_controller_running_) {
1147
+ control_modes[i] = { hardware_interface::HW_IF_EFFORT };
1148
+ }
1127
1149
if (force_mode_controller_running_) {
1128
1150
control_modes[i].push_back (FORCE_MODE_GPIO);
1129
1151
}
@@ -1159,6 +1181,7 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1159
1181
const std::vector<std::pair<std::string, std::string>> start_modes_to_check{
1160
1182
{ info_.joints [i].name + " /" + hardware_interface::HW_IF_POSITION, hardware_interface::HW_IF_POSITION },
1161
1183
{ info_.joints [i].name + " /" + hardware_interface::HW_IF_VELOCITY, hardware_interface::HW_IF_VELOCITY },
1184
+ { info_.joints [i].name + " /" + hardware_interface::HW_IF_EFFORT, hardware_interface::HW_IF_EFFORT },
1162
1185
{ tf_prefix + FORCE_MODE_GPIO + " /type" , FORCE_MODE_GPIO },
1163
1186
{ tf_prefix + PASSTHROUGH_GPIO + " /setpoint_positions_" + std::to_string (i), PASSTHROUGH_GPIO },
1164
1187
{ tf_prefix + FREEDRIVE_MODE_GPIO + " /async_success" , FREEDRIVE_MODE_GPIO },
@@ -1192,6 +1215,8 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
1192
1215
StoppingInterface::STOP_POSITION },
1193
1216
{ info_.joints [i].name + " /" + hardware_interface::HW_IF_VELOCITY, hardware_interface::HW_IF_VELOCITY,
1194
1217
StoppingInterface::STOP_VELOCITY },
1218
+ { info_.joints [i].name + " /" + hardware_interface::HW_IF_EFFORT, hardware_interface::HW_IF_EFFORT,
1219
+ StoppingInterface::STOP_TORQUE },
1195
1220
{ tf_prefix + FORCE_MODE_GPIO + " /disable_cmd" , FORCE_MODE_GPIO, StoppingInterface::STOP_FORCE_MODE },
1196
1221
{ tf_prefix + PASSTHROUGH_GPIO + " /setpoint_positions_" + std::to_string (i), PASSTHROUGH_GPIO,
1197
1222
StoppingInterface::STOP_PASSTHROUGH },
@@ -1237,6 +1262,11 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
1237
1262
velocity_controller_running_ = false ;
1238
1263
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1239
1264
}
1265
+ if (stop_modes_[0 ].size () != 0 &&
1266
+ std::find (stop_modes_[0 ].begin (), stop_modes_[0 ].end (), StoppingInterface::STOP_TORQUE) != stop_modes_[0 ].end ()) {
1267
+ torque_controller_running_ = false ;
1268
+ urcl_torque_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1269
+ }
1240
1270
if (stop_modes_[0 ].size () != 0 && std::find (stop_modes_[0 ].begin (), stop_modes_[0 ].end (),
1241
1271
StoppingInterface::STOP_FORCE_MODE) != stop_modes_[0 ].end ()) {
1242
1272
force_mode_controller_running_ = false ;
@@ -1267,16 +1297,25 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
1267
1297
if (start_modes_.size () != 0 && std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1268
1298
hardware_interface::HW_IF_POSITION) != start_modes_[0 ].end ()) {
1269
1299
velocity_controller_running_ = false ;
1300
+ torque_controller_running_ = false ;
1270
1301
passthrough_trajectory_controller_running_ = false ;
1271
1302
urcl_position_commands_ = urcl_position_commands_old_ = urcl_joint_positions_;
1272
1303
position_controller_running_ = true ;
1273
1304
1274
1305
} else if (start_modes_[0 ].size () != 0 && std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1275
1306
hardware_interface::HW_IF_VELOCITY) != start_modes_[0 ].end ()) {
1276
1307
position_controller_running_ = false ;
1308
+ torque_controller_running_ = false ;
1277
1309
passthrough_trajectory_controller_running_ = false ;
1278
1310
urcl_velocity_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1279
1311
velocity_controller_running_ = true ;
1312
+ } else if (start_modes_[0 ].size () != 0 && std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (),
1313
+ hardware_interface::HW_IF_EFFORT) != start_modes_[0 ].end ()) {
1314
+ position_controller_running_ = false ;
1315
+ velocity_controller_running_ = false ;
1316
+ torque_controller_running_ = true ;
1317
+ passthrough_trajectory_controller_running_ = false ;
1318
+ urcl_torque_commands_ = { { 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 } };
1280
1319
}
1281
1320
if (start_modes_[0 ].size () != 0 &&
1282
1321
std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (), FORCE_MODE_GPIO) != start_modes_[0 ].end ()) {
@@ -1286,13 +1325,15 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
1286
1325
std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (), PASSTHROUGH_GPIO) != start_modes_[0 ].end ()) {
1287
1326
velocity_controller_running_ = false ;
1288
1327
position_controller_running_ = false ;
1328
+ torque_controller_running_ = false ;
1289
1329
passthrough_trajectory_controller_running_ = true ;
1290
1330
passthrough_trajectory_abort_ = 0.0 ;
1291
1331
}
1292
1332
if (start_modes_[0 ].size () != 0 &&
1293
1333
std::find (start_modes_[0 ].begin (), start_modes_[0 ].end (), FREEDRIVE_MODE_GPIO) != start_modes_[0 ].end ()) {
1294
1334
velocity_controller_running_ = false ;
1295
1335
position_controller_running_ = false ;
1336
+ torque_controller_running_ = false ;
1296
1337
freedrive_mode_controller_running_ = true ;
1297
1338
freedrive_activated_ = false ;
1298
1339
}
0 commit comments