Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Use rclcpp::Time for stamping transforms #20

Merged
merged 2 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/robot_state_publisher/robot_state_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class RobotStatePublisher
std_msgs::msg::String model_xml_;
bool description_published_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr description_pub_;
rclcpp::Clock::SharedPtr clock_;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks ABI by changing the size of RobotStatePublisher. This is fine for Eloquent, but is an issue for including in a dashing patch release. This bug might be important enough to warrant breaking ABI.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably makes sense to break ABI and release this to Dashing, see also #21.

};

} // namespace robot_state_publisher
Expand Down
11 changes: 5 additions & 6 deletions src/robot_state_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ RobotStatePublisher::RobotStatePublisher(
: model_(model),
tf_broadcaster_(node_handle),
static_tf_broadcaster_(node_handle),
description_published_(false)
description_published_(false),
clock_(node_handle->get_clock())
{
// walk the tree and add segments to segments_
addChildren(tree.getRootSegment());
Expand Down Expand Up @@ -160,13 +161,11 @@ void RobotStatePublisher::publishFixedTransforms(const std::string & tf_prefix,
// loop over all fixed segments
for (auto seg = segments_fixed_.begin(); seg != segments_fixed_.end(); seg++) {
geometry_msgs::msg::TransformStamped tf_transform = kdlToTransform(seg->second.segment.pose(0));
std::chrono::nanoseconds now = std::chrono::high_resolution_clock::now().time_since_epoch();
rclcpp::Time now = clock_->now();
if (!use_tf_static) {
now += std::chrono::milliseconds(500); // 0.5sec in NS
now = now + rclcpp::Duration(std::chrono::milliseconds(500)); // 0.5sec in NS
}
tf_transform.header.stamp.sec =
static_cast<builtin_interfaces::msg::Time::_sec_type>(now.count() / 1000000000);
tf_transform.header.stamp.nanosec = now.count() % 1000000000;
tf_transform.header.stamp = now;

tf_transform.header.frame_id = tf_prefix + "/" + seg->second.root;
tf_transform.child_frame_id = tf_prefix + "/" + seg->second.tip;
Expand Down