3
3
namespace lbr_ros2_control {
4
4
controller_interface::CallbackReturn
5
5
SystemInterface::on_init (const hardware_interface::HardwareInfo &system_info) {
6
- auto ret = hardware_interface::SystemInterface::on_init (system_info);
6
+ auto ret =
7
+ hardware_interface::SystemInterface::on_init (system_info); // parses system_info to info_
7
8
if (ret != controller_interface::CallbackReturn::SUCCESS) {
8
9
RCLCPP_ERROR_STREAM (rclcpp::get_logger (LOGGER_NAME),
9
10
lbr_fri_ros2::ColorScheme::ERROR << " Failed to initialize SystemInterface"
@@ -13,23 +14,23 @@ SystemInterface::on_init(const hardware_interface::HardwareInfo &system_info) {
13
14
14
15
// parameters_ from lbr_system_interface.xacro (default configurations located in
15
16
// lbr_description/ros2_control/lbr_system_interface.xacro)
16
- if (!parse_parameters_ (system_info )) {
17
+ if (!parse_parameters_ ()) {
17
18
return controller_interface::CallbackReturn::ERROR;
18
19
}
19
20
20
21
// setup driver
21
22
lbr_fri_ros2::CommandGuardParameters command_guard_parameters;
22
23
lbr_fri_ros2::StateInterfaceParameters state_interface_parameters;
23
- for (std::size_t idx = 0 ; idx < system_info .joints .size (); ++idx) {
24
- command_guard_parameters.joint_names [idx] = system_info .joints [idx].name ;
24
+ for (std::size_t idx = 0 ; idx < info_ .joints .size (); ++idx) {
25
+ command_guard_parameters.joint_names [idx] = info_ .joints [idx].name ;
25
26
command_guard_parameters.max_positions [idx] =
26
- std::stod (system_info .joints [idx].parameters .at (" max_position" ));
27
+ std::stod (info_ .joints [idx].parameters .at (" max_position" ));
27
28
command_guard_parameters.min_positions [idx] =
28
- std::stod (system_info .joints [idx].parameters .at (" min_position" ));
29
+ std::stod (info_ .joints [idx].parameters .at (" min_position" ));
29
30
command_guard_parameters.max_velocities [idx] =
30
- std::stod (system_info .joints [idx].parameters .at (" max_velocity" ));
31
+ std::stod (info_ .joints [idx].parameters .at (" max_velocity" ));
31
32
command_guard_parameters.max_torques [idx] =
32
- std::stod (system_info .joints [idx].parameters .at (" max_torque" ));
33
+ std::stod (info_ .joints [idx].parameters .at (" max_torque" ));
33
34
}
34
35
state_interface_parameters.external_torque_tau = parameters_.external_torque_tau ;
35
36
state_interface_parameters.measured_torque_tau = parameters_.measured_torque_tau ;
@@ -52,22 +53,9 @@ SystemInterface::on_init(const hardware_interface::HardwareInfo &system_info) {
52
53
nan_last_hw_states_ ();
53
54
54
55
// setup force-torque estimator
55
- std::transform (info_.sensors [1 ].parameters .at (" enabled" ).begin (),
56
- info_.sensors [1 ].parameters .at (" enabled" ).end (),
57
- info_.sensors [1 ].parameters .at (" enabled" ).begin (),
58
- ::tolower); // convert to lower case
59
- ft_parameters_.enabled = info_.sensors [1 ].parameters .at (" enabled" ) == " true" ;
60
- ft_parameters_.update_rate = std::stoul (info_.sensors [1 ].parameters .at (" update_rate" ));
61
- ft_parameters_.rt_prio = std::stoi (info_.sensors [1 ].parameters .at (" rt_prio" ));
62
- ft_parameters_.chain_root = info_.sensors [1 ].parameters .at (" chain_root" );
63
- ft_parameters_.chain_tip = info_.sensors [1 ].parameters .at (" chain_tip" );
64
- ft_parameters_.damping = std::stod (info_.sensors [1 ].parameters .at (" damping" ));
65
- ft_parameters_.force_x_th = std::stod (info_.sensors [1 ].parameters .at (" force_x_th" ));
66
- ft_parameters_.force_y_th = std::stod (info_.sensors [1 ].parameters .at (" force_y_th" ));
67
- ft_parameters_.force_z_th = std::stod (info_.sensors [1 ].parameters .at (" force_z_th" ));
68
- ft_parameters_.torque_x_th = std::stod (info_.sensors [1 ].parameters .at (" torque_x_th" ));
69
- ft_parameters_.torque_y_th = std::stod (info_.sensors [1 ].parameters .at (" torque_y_th" ));
70
- ft_parameters_.torque_z_th = std::stod (info_.sensors [1 ].parameters .at (" torque_z_th" ));
56
+ if (!parse_ft_parameters_ ()) {
57
+ return controller_interface::CallbackReturn::ERROR;
58
+ }
71
59
if (ft_parameters_.enabled ) {
72
60
ft_estimator_impl_ptr_ = std::make_shared<lbr_fri_ros2::FTEstimatorImpl>(
73
61
info_.original_xml , ft_parameters_.chain_root , ft_parameters_.chain_tip ,
@@ -338,12 +326,12 @@ hardware_interface::return_type SystemInterface::write(const rclcpp::Time & /*ti
338
326
return hardware_interface::return_type::OK;
339
327
}
340
328
341
- bool SystemInterface::parse_parameters_ (const hardware_interface::HardwareInfo &system_info ) {
329
+ bool SystemInterface::parse_parameters_ () {
342
330
try {
343
331
parameters_.fri_client_sdk_major_version =
344
- std::stoul (system_info .hardware_parameters .at (" fri_client_sdk_major_version" ));
332
+ std::stoul (info_ .hardware_parameters .at (" fri_client_sdk_major_version" ));
345
333
parameters_.fri_client_sdk_minor_version =
346
- std::stoul (system_info .hardware_parameters .at (" fri_client_sdk_minor_version" ));
334
+ std::stoul (info_ .hardware_parameters .at (" fri_client_sdk_minor_version" ));
347
335
if (parameters_.fri_client_sdk_major_version != FRI_CLIENT_VERSION_MAJOR) {
348
336
RCLCPP_ERROR_STREAM (
349
337
rclcpp::get_logger (LOGGER_NAME),
@@ -354,7 +342,7 @@ bool SystemInterface::parse_parameters_(const hardware_interface::HardwareInfo &
354
342
<< lbr_fri_ros2::ColorScheme::ENDC);
355
343
return false ;
356
344
}
357
- std::string client_command_mode = system_info .hardware_parameters .at (" client_command_mode" );
345
+ std::string client_command_mode = info_ .hardware_parameters .at (" client_command_mode" );
358
346
if (client_command_mode == " position" ) {
359
347
#if FRI_CLIENT_VERSION_MAJOR == 1
360
348
parameters_.client_command_mode = KUKA::FRI::EClientCommandMode::POSITION;
@@ -375,7 +363,7 @@ bool SystemInterface::parse_parameters_(const hardware_interface::HardwareInfo &
375
363
<< lbr_fri_ros2::ColorScheme::ENDC);
376
364
return false ;
377
365
}
378
- parameters_.port_id = std::stoul (info_.hardware_parameters [ " port_id" ] );
366
+ parameters_.port_id = std::stoul (info_.hardware_parameters . at ( " port_id" ) );
379
367
if (parameters_.port_id < 30200 || parameters_.port_id > 30209 ) {
380
368
RCLCPP_ERROR_STREAM (rclcpp::get_logger (LOGGER_NAME),
381
369
lbr_fri_ros2::ColorScheme::ERROR
@@ -384,19 +372,21 @@ bool SystemInterface::parse_parameters_(const hardware_interface::HardwareInfo &
384
372
<< lbr_fri_ros2::ColorScheme::ENDC);
385
373
return false ;
386
374
}
387
- info_.hardware_parameters [ " remote_host" ] == " INADDR_ANY"
375
+ info_.hardware_parameters . at ( " remote_host" ) == " INADDR_ANY"
388
376
? parameters_.remote_host = NULL
389
- : parameters_.remote_host = info_.hardware_parameters [" remote_host" ].c_str ();
390
- parameters_.rt_prio = std::stoul (info_.hardware_parameters [" rt_prio" ]);
391
- std::transform (info_.hardware_parameters [" open_loop" ].begin (),
392
- info_.hardware_parameters [" open_loop" ].end (),
393
- info_.hardware_parameters [" open_loop" ].begin (),
377
+ : parameters_.remote_host = info_.hardware_parameters .at (" remote_host" ).c_str ();
378
+ parameters_.rt_prio = std::stoul (info_.hardware_parameters .at (" rt_prio" ));
379
+ parameters_.joint_position_tau = std::stod (info_.hardware_parameters .at (" joint_position_tau" ));
380
+ parameters_.command_guard_variant = info_.hardware_parameters .at (" command_guard_variant" );
381
+ parameters_.external_torque_tau =
382
+ std::stod (info_.hardware_parameters .at (" external_torque_tau" ));
383
+ parameters_.measured_torque_tau =
384
+ std::stod (info_.hardware_parameters .at (" measured_torque_tau" ));
385
+ std::transform (info_.hardware_parameters .at (" open_loop" ).begin (),
386
+ info_.hardware_parameters .at (" open_loop" ).end (),
387
+ info_.hardware_parameters .at (" open_loop" ).begin (),
394
388
::tolower); // convert to lower case
395
- parameters_.open_loop = info_.hardware_parameters [" open_loop" ] == " true" ;
396
- parameters_.joint_position_tau = std::stod (info_.hardware_parameters [" joint_position_tau" ]);
397
- parameters_.command_guard_variant = system_info.hardware_parameters .at (" command_guard_variant" );
398
- parameters_.external_torque_tau = std::stod (info_.hardware_parameters [" external_torque_tau" ]);
399
- parameters_.measured_torque_tau = std::stod (info_.hardware_parameters [" measured_torque_tau" ]);
389
+ parameters_.open_loop = info_.hardware_parameters .at (" open_loop" ) == " true" ;
400
390
} catch (const std::out_of_range &e) {
401
391
RCLCPP_ERROR_STREAM (rclcpp::get_logger (LOGGER_NAME),
402
392
lbr_fri_ros2::ColorScheme::ERROR
@@ -407,6 +397,35 @@ bool SystemInterface::parse_parameters_(const hardware_interface::HardwareInfo &
407
397
return true ;
408
398
}
409
399
400
+ bool SystemInterface::parse_ft_parameters_ () {
401
+ try {
402
+ std::transform (info_.sensors [1 ].parameters .at (" enabled" ).begin (),
403
+ info_.sensors [1 ].parameters .at (" enabled" ).end (),
404
+ info_.sensors [1 ].parameters .at (" enabled" ).begin (),
405
+ ::tolower); // convert to lower case
406
+ const auto &estimated_ft_sensor = info_.sensors [1 ];
407
+ ft_parameters_.enabled = estimated_ft_sensor.parameters .at (" enabled" ) == " true" ;
408
+ ft_parameters_.update_rate = std::stoul (estimated_ft_sensor.parameters .at (" update_rate" ));
409
+ ft_parameters_.rt_prio = std::stoi (estimated_ft_sensor.parameters .at (" rt_prio" ));
410
+ ft_parameters_.chain_root = estimated_ft_sensor.parameters .at (" chain_root" );
411
+ ft_parameters_.chain_tip = estimated_ft_sensor.parameters .at (" chain_tip" );
412
+ ft_parameters_.damping = std::stod (estimated_ft_sensor.parameters .at (" damping" ));
413
+ ft_parameters_.force_x_th = std::stod (estimated_ft_sensor.parameters .at (" force_x_th" ));
414
+ ft_parameters_.force_y_th = std::stod (estimated_ft_sensor.parameters .at (" force_y_th" ));
415
+ ft_parameters_.force_z_th = std::stod (estimated_ft_sensor.parameters .at (" force_z_th" ));
416
+ ft_parameters_.torque_x_th = std::stod (estimated_ft_sensor.parameters .at (" torque_x_th" ));
417
+ ft_parameters_.torque_y_th = std::stod (estimated_ft_sensor.parameters .at (" torque_y_th" ));
418
+ ft_parameters_.torque_z_th = std::stod (estimated_ft_sensor.parameters .at (" torque_z_th" ));
419
+ } catch (const std::out_of_range &e) {
420
+ RCLCPP_ERROR_STREAM (rclcpp::get_logger (LOGGER_NAME),
421
+ lbr_fri_ros2::ColorScheme::ERROR
422
+ << " Failed to parse force-torque sensor parameters with: " << e.what ()
423
+ << lbr_fri_ros2::ColorScheme::ENDC);
424
+ return false ;
425
+ }
426
+ return true ;
427
+ }
428
+
410
429
void SystemInterface::nan_command_interfaces_ () {
411
430
hw_lbr_command_.joint_position .fill (std::numeric_limits<double >::quiet_NaN ());
412
431
hw_lbr_command_.torque .fill (std::numeric_limits<double >::quiet_NaN ());
0 commit comments