|
22 | 22 | #include <utility> |
23 | 23 | #include <vector> |
24 | 24 |
|
| 25 | +#include "control_toolbox/tf_utils.hpp" |
25 | 26 | #include "diff_drive_controller/diff_drive_controller.hpp" |
26 | 27 | #include "hardware_interface/types/hardware_interface_type_values.hpp" |
27 | 28 | #include "lifecycle_msgs/msg/state.hpp" |
@@ -411,32 +412,17 @@ controller_interface::CallbackReturn DiffDriveController::on_configure( |
411 | 412 | std::make_shared<realtime_tools::RealtimePublisher<nav_msgs::msg::Odometry>>( |
412 | 413 | odometry_publisher_); |
413 | 414 |
|
414 | | - // Append the tf prefix if there is one |
415 | | - std::string tf_prefix = ""; |
416 | | - if (params_.tf_frame_prefix_enable) |
417 | | - { |
418 | | - if (params_.tf_frame_prefix != "") |
419 | | - { |
420 | | - tf_prefix = params_.tf_frame_prefix; |
421 | | - } |
422 | | - else |
423 | | - { |
424 | | - tf_prefix = std::string(get_node()->get_namespace()); |
425 | | - } |
426 | | - |
427 | | - // Make sure prefix does not start with '/' and always ends with '/' |
428 | | - if (tf_prefix.back() != '/') |
429 | | - { |
430 | | - tf_prefix = tf_prefix + "/"; |
431 | | - } |
432 | | - if (tf_prefix.front() == '/') |
433 | | - { |
434 | | - tf_prefix.erase(0, 1); |
435 | | - } |
436 | | - } |
437 | | - |
438 | | - const auto odom_frame_id = tf_prefix + params_.odom_frame_id; |
439 | | - const auto base_frame_id = tf_prefix + params_.base_frame_id; |
| 415 | + // apply the TF prefix if not empty, otherwise use the node namespace |
| 416 | + const auto odom_frame_id = |
| 417 | + params_.tf_frame_prefix_enable |
| 418 | + ? control_toolbox::apply_tf_prefix( |
| 419 | + params_.tf_frame_prefix, get_node()->get_namespace(), params_.odom_frame_id) |
| 420 | + : params_.odom_frame_id; |
| 421 | + const auto base_frame_id = |
| 422 | + params_.tf_frame_prefix_enable |
| 423 | + ? control_toolbox::apply_tf_prefix( |
| 424 | + params_.tf_frame_prefix, get_node()->get_namespace(), params_.base_frame_id) |
| 425 | + : params_.base_frame_id; |
440 | 426 |
|
441 | 427 | odometry_message_.header.frame_id = odom_frame_id; |
442 | 428 | odometry_message_.child_frame_id = base_frame_id; |
|
0 commit comments