@@ -12,6 +12,27 @@ SystemInterface::on_init(const hardware_interface::HardwareInfo &system_info) {
12
12
}
13
13
14
14
// parameters_ from config/lbr_system_interface.xacro
15
+ std::string client_command_mode = system_info.hardware_parameters .at (" client_command_mode" );
16
+ if (client_command_mode == " position" ) {
17
+ #if FRICLIENT_VERSION_MAJOR == 1
18
+ parameters_.client_command_mode = KUKA::FRI::EClientCommandMode::POSITION;
19
+ #endif
20
+ #if FRICLIENT_VERSION_MAJOR == 2
21
+ parameters_.client_command_mode = KUKA::FRI::EClientCommandMode::JOINT_POSITION;
22
+ #endif
23
+ } else if (client_command_mode == " torque" ) {
24
+ parameters_.client_command_mode = KUKA::FRI::EClientCommandMode::TORQUE;
25
+ } else if (client_command_mode == " wrench" ) {
26
+ parameters_.client_command_mode = KUKA::FRI::EClientCommandMode::WRENCH;
27
+ } else {
28
+ RCLCPP_ERROR_STREAM (
29
+ rclcpp::get_logger (LOGGER_NAME),
30
+ lbr_fri_ros2::ColorScheme::ERROR
31
+ << " Expected client_command_mode 'position', 'torque' or 'wrench', got '"
32
+ << lbr_fri_ros2::ColorScheme::BOLD << parameters_.client_command_mode << " '"
33
+ << lbr_fri_ros2::ColorScheme::ENDC);
34
+ return controller_interface::CallbackReturn::ERROR;
35
+ }
15
36
parameters_.port_id = std::stoul (info_.hardware_parameters [" port_id" ]);
16
37
if (parameters_.port_id < 30200 || parameters_.port_id > 30209 ) {
17
38
RCLCPP_ERROR_STREAM (rclcpp::get_logger (LOGGER_NAME),
@@ -72,8 +93,8 @@ SystemInterface::on_init(const hardware_interface::HardwareInfo &system_info) {
72
93
73
94
try {
74
95
async_client_ptr_ = std::make_shared<lbr_fri_ros2::AsyncClient>(
75
- pid_parameters, command_guard_parameters, parameters_. command_guard_variant ,
76
- state_interface_parameters, parameters_.open_loop );
96
+ parameters_. client_command_mode , pid_parameters, command_guard_parameters ,
97
+ parameters_. command_guard_variant , state_interface_parameters, parameters_.open_loop );
77
98
app_ptr_ = std::make_unique<lbr_fri_ros2::App>(async_client_ptr_);
78
99
} catch (const std::exception &e) {
79
100
RCLCPP_ERROR_STREAM (rclcpp::get_logger (LOGGER_NAME),
@@ -231,9 +252,9 @@ controller_interface::CallbackReturn SystemInterface::on_activate(const rclcpp_l
231
252
if (!app_ptr_->open_udp_socket (parameters_.port_id , parameters_.remote_host )) {
232
253
return controller_interface::CallbackReturn::ERROR;
233
254
}
234
- app_ptr_->run (parameters_.rt_prio );
255
+ app_ptr_->run_async (parameters_.rt_prio );
235
256
int attempt = 0 ;
236
- while (!async_client_ptr_->get_state_interface (). is_initialized () && rclcpp::ok ()) {
257
+ while (!async_client_ptr_->get_state_interface ()-> is_initialized () && rclcpp::ok ()) {
237
258
RCLCPP_INFO_STREAM (
238
259
rclcpp::get_logger (LOGGER_NAME),
239
260
" Awaiting robot heartbeat. Attempt "
@@ -246,7 +267,7 @@ controller_interface::CallbackReturn SystemInterface::on_activate(const rclcpp_l
246
267
std::this_thread::sleep_for (std::chrono::seconds (1 ));
247
268
}
248
269
if (!async_client_ptr_->get_state_interface ()
249
- . is_initialized ()) { // check connection should rclcpp::ok() fail
270
+ -> is_initialized ()) { // check connection should rclcpp::ok() fail
250
271
RCLCPP_INFO (rclcpp::get_logger (LOGGER_NAME), " Failed to connect" );
251
272
return controller_interface::CallbackReturn::ERROR;
252
273
}
@@ -256,13 +277,13 @@ controller_interface::CallbackReturn SystemInterface::on_activate(const rclcpp_l
256
277
RCLCPP_INFO_STREAM (rclcpp::get_logger (LOGGER_NAME),
257
278
" Control mode '"
258
279
<< lbr_fri_ros2::EnumMaps::control_mode_map (
259
- async_client_ptr_->get_state_interface (). get_state ().control_mode )
280
+ async_client_ptr_->get_state_interface ()-> get_state ().control_mode )
260
281
.c_str ()
261
282
<< " '" );
262
283
RCLCPP_INFO (rclcpp::get_logger (LOGGER_NAME), " Sample time %.3f s / %.1f Hz" ,
263
- async_client_ptr_->get_state_interface (). get_state ().sample_time ,
264
- 1 . / async_client_ptr_->get_state_interface (). get_state ().sample_time );
265
- while (!(async_client_ptr_->get_state_interface (). get_state ().session_state >=
284
+ async_client_ptr_->get_state_interface ()-> get_state ().sample_time ,
285
+ 1 . / async_client_ptr_->get_state_interface ()-> get_state ().sample_time );
286
+ while (!(async_client_ptr_->get_state_interface ()-> get_state ().session_state >=
266
287
KUKA::FRI::ESessionState::COMMANDING_WAIT) &&
267
288
rclcpp::ok ()) {
268
289
RCLCPP_INFO_STREAM (
@@ -273,7 +294,7 @@ controller_interface::CallbackReturn SystemInterface::on_activate(const rclcpp_l
273
294
<< lbr_fri_ros2::ColorScheme::ENDC << " ' state. Current state '"
274
295
<< lbr_fri_ros2::ColorScheme::BOLD << lbr_fri_ros2::ColorScheme::OKBLUE
275
296
<< lbr_fri_ros2::EnumMaps::session_state_map (
276
- async_client_ptr_->get_state_interface (). get_state ().session_state )
297
+ async_client_ptr_->get_state_interface ()-> get_state ().session_state )
277
298
<< lbr_fri_ros2::ColorScheme::ENDC << " '." );
278
299
std::this_thread::sleep_for (std::chrono::seconds (1 ));
279
300
}
@@ -285,18 +306,18 @@ controller_interface::CallbackReturn SystemInterface::on_activate(const rclcpp_l
285
306
286
307
controller_interface::CallbackReturn
287
308
SystemInterface::on_deactivate (const rclcpp_lifecycle::State &) {
288
- app_ptr_->stop_run ();
309
+ app_ptr_->request_stop ();
289
310
app_ptr_->close_udp_socket ();
290
311
return controller_interface::CallbackReturn::SUCCESS;
291
312
}
292
313
293
314
hardware_interface::return_type SystemInterface::read (const rclcpp::Time & /* time*/ ,
294
315
const rclcpp::Duration &period) {
295
- if (!async_client_ptr_->get_state_interface (). is_initialized ()) {
316
+ if (!async_client_ptr_->get_state_interface ()-> is_initialized ()) {
296
317
return hardware_interface::return_type::OK;
297
318
}
298
319
299
- hw_lbr_state_ = async_client_ptr_->get_state_interface (). get_state ();
320
+ hw_lbr_state_ = async_client_ptr_->get_state_interface ()-> get_state ();
300
321
301
322
if (period.seconds () - hw_lbr_state_.sample_time * 0.2 > hw_lbr_state_.sample_time ) {
302
323
RCLCPP_WARN_STREAM (rclcpp::get_logger (LOGGER_NAME),
@@ -313,7 +334,7 @@ hardware_interface::return_type SystemInterface::read(const rclcpp::Time & /*tim
313
334
lbr_fri_ros2::ColorScheme::ERROR
314
335
<< " LBR left COMMANDING_ACTIVE. Please re-run lbr_bringup"
315
336
<< lbr_fri_ros2::ColorScheme::ENDC);
316
- app_ptr_->stop_run ();
337
+ app_ptr_->request_stop ();
317
338
app_ptr_->close_udp_socket ();
318
339
return hardware_interface::return_type::ERROR;
319
340
}
@@ -345,49 +366,8 @@ hardware_interface::return_type SystemInterface::write(const rclcpp::Time & /*ti
345
366
if (hw_session_state_ != KUKA::FRI::COMMANDING_ACTIVE) {
346
367
return hardware_interface::return_type::OK;
347
368
}
348
- #if FRICLIENT_VERSION_MAJOR == 1
349
- if (hw_client_command_mode_ == KUKA::FRI::EClientCommandMode::POSITION)
350
- #endif
351
- #if FRICLIENT_VERSION_MAJOR == 2
352
- if (hw_client_command_mode_ == KUKA::FRI::EClientCommandMode::JOINT_POSITION)
353
- #endif
354
- {
355
- if (std::any_of (hw_lbr_command_.joint_position .cbegin (),
356
- hw_lbr_command_.joint_position .cend (),
357
- [](const double &v) { return std::isnan (v); })) {
358
- return hardware_interface::return_type::OK;
359
- }
360
- async_client_ptr_->get_command_interface ().set_command_target (hw_lbr_command_);
361
- return hardware_interface::return_type::OK;
362
- }
363
- if (hw_client_command_mode_ == KUKA::FRI::EClientCommandMode::TORQUE) {
364
- if (std::any_of (hw_lbr_command_.joint_position .cbegin (), hw_lbr_command_.joint_position .cend (),
365
- [](const double &v) { return std::isnan (v); }) ||
366
- std::any_of (hw_lbr_command_.torque .cbegin (), hw_lbr_command_.torque .cend (),
367
- [](const double &v) { return std::isnan (v); })) {
368
- return hardware_interface::return_type::OK;
369
- }
370
- async_client_ptr_->get_command_interface ().set_command_target (hw_lbr_command_);
371
- return hardware_interface::return_type::OK;
372
- }
373
- if (hw_client_command_mode_ == KUKA::FRI::EClientCommandMode::WRENCH) {
374
- if (std::any_of (hw_lbr_command_.wrench .cbegin (), hw_lbr_command_.wrench .cend (),
375
- [](const double &v) { return std::isnan (v); }) ||
376
- std::any_of (hw_lbr_command_.joint_position .cbegin (), hw_lbr_command_.joint_position .cend (),
377
- [](const double &v) { return std::isnan (v); })) {
378
- return hardware_interface::return_type::OK;
379
- }
380
- async_client_ptr_->get_command_interface ().set_command_target (hw_lbr_command_);
381
- return hardware_interface::return_type::OK;
382
- }
383
- #if FRICLIENT_VERSION_MAJOR == 2
384
- if (hw_client_command_mode_ == KUKA::FRI::EClientCommandMode::CARTESIAN_POSE) {
385
- throw std::runtime_error (
386
- lbr_fri_ros2::EnumMaps::client_command_mode_map (hw_client_command_mode_) +
387
- " command mode currently not implemented." );
388
- }
389
- #endif
390
- return hardware_interface::return_type::ERROR;
369
+ async_client_ptr_->get_command_interface ()->buffer_command_target (hw_lbr_command_);
370
+ return hardware_interface::return_type::OK;
391
371
}
392
372
393
373
void SystemInterface::nan_command_interfaces_ () {
0 commit comments