Skip to content

Commit 43029b2

Browse files
committed
tf prefix helper utilized
- control toolbox pkg already linked
1 parent c38468c commit 43029b2

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

diff_drive_controller/src/diff_drive_controller.cpp

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <utility>
2323
#include <vector>
2424

25+
#include "control_toolbox/tf_utils.hpp"
2526
#include "diff_drive_controller/diff_drive_controller.hpp"
2627
#include "hardware_interface/types/hardware_interface_type_values.hpp"
2728
#include "lifecycle_msgs/msg/state.hpp"
@@ -411,32 +412,17 @@ controller_interface::CallbackReturn DiffDriveController::on_configure(
411412
std::make_shared<realtime_tools::RealtimePublisher<nav_msgs::msg::Odometry>>(
412413
odometry_publisher_);
413414

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;
440426

441427
odometry_message_.header.frame_id = odom_frame_id;
442428
odometry_message_.child_frame_id = base_frame_id;

0 commit comments

Comments
 (0)