Skip to content

Commit ba5c0f6

Browse files
committed
Update per review feedback to simplify param handling
1 parent 6364400 commit ba5c0f6

File tree

5 files changed

+190
-54
lines changed

5 files changed

+190
-54
lines changed

force_torque_sensor_broadcaster/doc/userdoc.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ Topics
6262
^^^^^^
6363
The node subscribes to:
6464

65-
- ``<broadcaster_namespace>/wrench`` (raw wrench messages) or ``<broadcaster_namespace>/wrench_filtered`` (filtered wrench messages) depending on the ``use_filtered_input`` parameter
65+
- ``~/wrench`` (raw wrench messages). To subscribe to filtered wrench messages, use topic remapping: ``ros2 run ... --ros-args -r ~/wrench:=<namespace>/wrench_filtered``
6666

6767
The node publishes:
6868

69-
- ``<output_topic_prefix>_<target_frame>`` for each target frame specified in ``target_frames``
69+
- ``<namespace>/<target_frame>/wrench`` for each target frame specified in ``target_frames``
70+
71+
- If the node is in the root namespace (``/``), the namespace defaults to the node name (e.g., ``/fts_wrench_transformer/<target_frame>/wrench``)
72+
- If the input topic is remapped to a filtered topic (contains "filtered" in the name), the output topics automatically append ``_filtered`` suffix (e.g., ``<namespace>/<target_frame>/wrench_filtered``)
73+
- This allows users to distinguish between transformed raw wrench data and transformed filtered wrench data

force_torque_sensor_broadcaster/include/force_torque_sensor_broadcaster/wrench_transformer.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ class WrenchTransformer : public rclcpp::Node
5454
void setup_subscriber();
5555
void setup_publishers();
5656

57+
/**
58+
* Normalize namespace for topic construction.
59+
* If namespace is empty or root ("/"), returns node name with leading "/".
60+
* Otherwise, normalizes namespace to start with "/" and not end with "/".
61+
* @return Normalized namespace string
62+
*/
63+
std::string normalize_namespace_for_topics() const;
64+
5765
std::shared_ptr<force_torque_wrench_transformer::ParamListener> param_listener_;
5866
force_torque_wrench_transformer::Params params_;
5967

@@ -65,6 +73,7 @@ class WrenchTransformer : public rclcpp::Node
6573
std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
6674

6775
std::string input_topic_;
76+
std::string output_topic_suffix_; // e.g., "" or "_filtered" based on input topic
6877
std::vector<std::string> target_frames_;
6978
};
7079

force_torque_sensor_broadcaster/src/wrench_transformer.cpp

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,7 @@ bool WrenchTransformer::transform_wrench(
112112

113113
void WrenchTransformer::setup_subscriber()
114114
{
115-
input_topic_ =
116-
params_.broadcaster_namespace.empty() ? "~/wrench" : params_.broadcaster_namespace + "/wrench";
117-
if (params_.use_filtered_input)
118-
{
119-
input_topic_ += "_filtered";
120-
}
115+
input_topic_ = "~/wrench";
121116
wrench_subscriber_ = this->create_subscription<geometry_msgs::msg::WrenchStamped>(
122117
input_topic_, rclcpp::SystemDefaultsQoS(),
123118
std::bind(&WrenchTransformer::wrench_callback, this, std::placeholders::_1));
@@ -127,13 +122,55 @@ void WrenchTransformer::setup_subscriber()
127122
this->get_logger(), *this->get_clock(), 5000, "Failed to create wrench subscriber");
128123
return;
129124
}
125+
126+
// Detect if input topic is filtered by checking the actual subscribed topic name
127+
// This handles remapping: if ~/wrench is remapped to wrench_filtered, output should reflect it
128+
try
129+
{
130+
const std::string actual_topic = wrench_subscriber_->get_topic_name();
131+
if (actual_topic.find("filtered") != std::string::npos)
132+
{
133+
output_topic_suffix_ = "_filtered";
134+
}
135+
else
136+
{
137+
output_topic_suffix_ = "";
138+
}
139+
}
140+
catch (const std::exception &)
141+
{
142+
// If we can't get topic name yet, default to empty suffix
143+
output_topic_suffix_ = "";
144+
}
145+
}
146+
147+
std::string WrenchTransformer::normalize_namespace_for_topics() const
148+
{
149+
std::string ns = this->get_namespace();
150+
// If namespace is empty or root ("/"), use node name as namespace
151+
if (ns.empty() || ns == "/")
152+
{
153+
return "/" + std::string(this->get_name());
154+
}
155+
// Otherwise, normalize the namespace (ensure it starts with / and doesn't end with /)
156+
if (ns.front() != '/')
157+
{
158+
ns = "/" + ns;
159+
}
160+
if (ns.back() == '/')
161+
{
162+
ns.pop_back();
163+
}
164+
return ns;
130165
}
131166

132167
void WrenchTransformer::setup_publishers()
133168
{
169+
const std::string ns = normalize_namespace_for_topics();
170+
134171
for (const auto & target_frame : params_.target_frames)
135172
{
136-
std::string topic_name = params_.output_topic_prefix + "_" + target_frame;
173+
std::string topic_name = ns + "/" + target_frame + "/wrench" + output_topic_suffix_;
137174
transformed_wrench_publishers_[target_frame] =
138175
this->create_publisher<geometry_msgs::msg::WrenchStamped>(
139176
topic_name, rclcpp::SystemDefaultsQoS());

force_torque_sensor_broadcaster/src/wrench_transformer_parameters.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
force_torque_wrench_transformer:
2-
broadcaster_namespace: {
3-
type: string,
4-
default_value: "",
5-
description: "Full namespace path to the force_torque_sensor_broadcaster controller node. The broadcaster publishes geometry_msgs::msg::WrenchStamped messages to topics ``wrench`` (raw) and ``wrench_filtered`` (filtered). Input topics will be constructed as ``<broadcaster_namespace>/wrench`` or ``<broadcaster_namespace>/wrench_filtered``. If empty, assumes the broadcaster is in the same namespace as this node and uses ``~/wrench``.",
6-
}
7-
use_filtered_input: {
8-
type: bool,
9-
default_value: false,
10-
description: "If true, subscribes to the filtered WrenchStamped topic (``<broadcaster_namespace>/wrench_filtered``), otherwise subscribes to the raw WrenchStamped topic (``<broadcaster_namespace>/wrench``). The filtered topic is only available if the broadcaster has a sensor_filter_chain configured.",
11-
}
122
target_frames: {
133
type: string_array,
144
default_value: [],
@@ -17,11 +7,6 @@ force_torque_wrench_transformer:
177
not_empty<>: null
188
}
199
}
20-
output_topic_prefix: {
21-
type: string,
22-
default_value: "~/wrench_transformed",
23-
description: "Prefix for output topic names. Each output topic publishes transformed WrenchStamped messages in a different frame. Output topics will be named as ``<output_topic_prefix>_<frame_name>``. Default uses node namespace.",
24-
}
2510
tf_timeout: {
2611
type: double,
2712
default_value: 0.1,

0 commit comments

Comments
 (0)