tf_bridge.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
21 
22 namespace cartographer_ros {
23 
24 TfBridge::TfBridge(const std::string& tracking_frame,
25  const double lookup_transform_timeout_sec,
26  const tf2_ros::Buffer* buffer)
27  : tracking_frame_(tracking_frame),
28  lookup_transform_timeout_sec_(lookup_transform_timeout_sec),
29  buffer_(buffer) {}
30 
31 std::unique_ptr<::cartographer::transform::Rigid3d> TfBridge::LookupToTracking(
32  const ::cartographer::common::Time time,
33  const std::string& frame_id) const {
35  std::unique_ptr<::cartographer::transform::Rigid3d> frame_id_to_tracking;
36  try {
37  const ::ros::Time latest_tf_time =
38  buffer_
39  ->lookupTransform(tracking_frame_, frame_id, ::ros::Time(0.),
40  timeout)
41  .header.stamp;
42  const ::ros::Time requested_time = ToRos(time);
43  if (latest_tf_time >= requested_time) {
44  // We already have newer data, so we do not wait. Otherwise, we would wait
45  // for the full 'timeout' even if we ask for data that is too old.
46  timeout = ::ros::Duration(0.);
47  }
48  return ::cartographer::common::make_unique<
50  tracking_frame_, frame_id, requested_time, timeout)));
51  } catch (const tf2::TransformException& ex) {
52  LOG(WARNING) << ex.what();
53  }
54  return nullptr;
55 }
56 
57 } // namespace cartographer_ros
TfBridge(const std::string &tracking_frame, double lookup_transform_timeout_sec, const tf2_ros::Buffer *buffer)
Definition: tf_bridge.cc:24
const tf2_ros::Buffer *const buffer_
Definition: tf_bridge.h:46
Rigid3d ToRigid3d(const geometry_msgs::TransformStamped &transform)
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
std::unique_ptr<::cartographer::transform::Rigid3d > LookupToTracking(::cartographer::common::Time time, const std::string &frame_id) const
Definition: tf_bridge.cc:31
const std::string tracking_frame_
Definition: tf_bridge.h:44
::ros::Time ToRos(::cartographer::common::Time time)
const double lookup_transform_timeout_sec_
Definition: tf_bridge.h:45


cartographer_ros
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:06:05