Skip to content

Commit 6048c06

Browse files
jacobperronclalancette
authored andcommitted
Always publish fixed frames to /tf_static
Remove the deprecated 'use_tf_static' parameter. Now fixed transforms will always be published to the topic /tf_static. This change also avoid repeatedly publishing the same transforms. This restores the behavior from ROS 1; now a single "latched" message is published over /tf_static. Signed-off-by: Jacob Perron <[email protected]>
1 parent 7d3ecb3 commit 6048c06

File tree

3 files changed

+13
-40
lines changed

3 files changed

+13
-40
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ Robot State Publisher
22
=====================
33

44
This package contains the Robot State Publisher, a node and a class to publish the state of a robot to tf2.
5-
Once the state gets published, it is available to all components in the system that also use tf2.
6-
The package takes the joint angles of the robot as input and publishes the 3D poses of the robot links, using a kinematic tree model of the robot.
5+
At startup time, Robot State Publisher is supplied with a kinematic tree model (URDF) of the robot.
6+
It then subscribes to the `joint_states` message (of type `sensor_msgs/msg/JointState`) to get individual joint states.
7+
These joint states are used to update the kinematic tree model, and the resulting 3D poses are then published to tf2.
8+
9+
Robot State Publisher deals with two different "classes" of joint types: fixed and movable.
10+
Fixed joints (with the type "fixed") are published to the transient_local `/tf_static` topic once on startup (transient_local topics keep a history of what they published, so a later subscription can always get the latest state of the world).
11+
Movable joints are published to the regular `/tf` topic any time the appropriate joint is updated in the `joint_states` message.
712

813
Examples showing how to pass the `robot_description` parameter using a launch file are available in the 'launch' subdirectory.
914

@@ -20,7 +25,6 @@ Subscribed Topics
2025
Parameters
2126
----------
2227
* `robot_description` (string) - The original description of the robot in URDF form. This *must* be set at robot_state_publisher startup time, or the node will fail to start. Updates to this parameter will be reflected in the `robot_description` topic.
23-
* `publish_frequency` (double) - The frequency at which fixed transforms will be republished to the network. Defaults to 20.0 Hz.
24-
* `use_tf_static` (bool) - Whether to publish fixed joints on the static broadcaster (`/tf_static` topic) or on the dynamic one (`/tf` topic). Defaults to true, so it publishes on the `/tf_static` topic.
28+
* `publish_frequency` (double) - The maximum frequency at which non-static transforms (e.g. joint states) will be published to `/tf`. Defaults to 20.0 Hz.
2529
* `ignore_timestamp` (bool) - Whether to accept all joint states no matter what the timestamp (true), or to only publish joint state updates if they are newer than the last publish_frequency (false). Defaults to false.
2630
* `frame_prefix` (string) - An arbitrary prefix to add to the published tf2 frames. Defaults to the empty string.

include/robot_state_publisher/robot_state_publisher.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ class RobotStatePublisher : public rclcpp::Node
9595
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr description_pub_;
9696
std::chrono::milliseconds publish_interval_ms_;
9797
rclcpp::Subscription<sensor_msgs::msg::JointState>::SharedPtr joint_state_sub_;
98-
rclcpp::TimerBase::SharedPtr timer_;
9998
rclcpp::Time last_callback_time_;
10099
std::map<std::string, builtin_interfaces::msg::Time> last_publish_time_;
101100
MimicMap mimic_;
102-
bool use_tf_static_;
103101
bool ignore_timestamp_;
104102
std::string frame_prefix_;
105103
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr param_cb_;

src/robot_state_publisher.cpp

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ RobotStatePublisher::RobotStatePublisher(const rclcpp::NodeOptions & options)
120120
publish_interval_ms_ =
121121
std::chrono::milliseconds(static_cast<uint64_t>(1000.0 / publish_freq));
122122

123-
// set whether to use the /tf_static latched static transform broadcaster
124-
use_tf_static_ = this->declare_parameter("use_tf_static", true);
125-
if (!use_tf_static_) {
126-
RCLCPP_WARN(get_logger(), "use_tf_static is deprecated and will be removed in the future");
127-
}
128-
129123
// set frame_prefix
130124
frame_prefix_ = this->declare_parameter("frame_prefix", "");
131125

@@ -148,9 +142,7 @@ RobotStatePublisher::RobotStatePublisher(const rclcpp::NodeOptions & options)
148142
&RobotStatePublisher::callbackJointState, this,
149143
std::placeholders::_1));
150144

151-
// trigger to publish fixed joints
152-
timer_ = this->create_wall_timer(
153-
publish_interval_ms_, std::bind(&RobotStatePublisher::publishFixedTransforms, this));
145+
publishFixedTransforms();
154146

155147
// Now that we have successfully declared the parameters and done all
156148
// necessary setup, install the callback for updating parameters.
@@ -260,23 +252,16 @@ void RobotStatePublisher::publishFixedTransforms()
260252
std::vector<geometry_msgs::msg::TransformStamped> tf_transforms;
261253

262254
// loop over all fixed segments
255+
rclcpp::Time now = this->now();
263256
for (const std::pair<const std::string, SegmentPair> & seg : segments_fixed_) {
264257
geometry_msgs::msg::TransformStamped tf_transform = kdlToTransform(seg.second.segment.pose(0));
265-
rclcpp::Time now = this->now();
266-
if (!use_tf_static_) {
267-
now = now + rclcpp::Duration(std::chrono::milliseconds(500));
268-
}
269258
tf_transform.header.stamp = now;
270259

271260
tf_transform.header.frame_id = frame_prefix_ + seg.second.root;
272261
tf_transform.child_frame_id = frame_prefix_ + seg.second.tip;
273262
tf_transforms.push_back(tf_transform);
274263
}
275-
if (use_tf_static_) {
276-
static_tf_broadcaster_->sendTransform(tf_transforms);
277-
} else {
278-
tf_broadcaster_->sendTransform(tf_transforms);
279-
}
264+
static_tf_broadcaster_->sendTransform(tf_transforms);
280265
}
281266

282267
void RobotStatePublisher::callbackJointState(const sensor_msgs::msg::JointState::SharedPtr state)
@@ -370,13 +355,6 @@ rcl_interfaces::msg::SetParametersResult RobotStatePublisher::parameterUpdate(
370355
result.reason = err.what();
371356
break;
372357
}
373-
} else if (parameter.get_name() == "use_tf_static") {
374-
if (parameter.get_type() != rclcpp::ParameterType::PARAMETER_BOOL) {
375-
result.successful = false;
376-
result.reason = "use_tf_static must be a boolean";
377-
break;
378-
}
379-
use_tf_static_ = parameter.as_bool();
380358
} else if (parameter.get_name() == "frame_prefix") {
381359
if (parameter.get_type() != rclcpp::ParameterType::PARAMETER_STRING) {
382360
result.successful = false;
@@ -401,18 +379,11 @@ rcl_interfaces::msg::SetParametersResult RobotStatePublisher::parameterUpdate(
401379
double publish_freq = parameter.as_double();
402380
if (publish_freq < 0.0 || publish_freq > 1000.0) {
403381
result.successful = false;
404-
result.reason = "publish_frequency must be between 0 and 1000";
382+
result.reason = "publish_frequency must be between 0.0 and 1000.0";
405383
break;
406384
}
407-
std::chrono::milliseconds new_publish_interval =
385+
publish_interval_ms_ =
408386
std::chrono::milliseconds(static_cast<uint64_t>(1000.0 / publish_freq));
409-
410-
if (new_publish_interval != publish_interval_ms_) {
411-
publish_interval_ms_ = new_publish_interval;
412-
timer_->cancel();
413-
timer_ = this->create_wall_timer(
414-
publish_interval_ms_, std::bind(&RobotStatePublisher::publishFixedTransforms, this));
415-
}
416387
}
417388
}
418389

0 commit comments

Comments
 (0)