Apollo  6.0
Open source self driving car software
buffer_interface.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
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 
17 #pragma once
18 
19 #include <algorithm>
20 #include <string>
21 
22 #include "modules/transform/proto/transform.pb.h"
23 
24 namespace apollo {
25 namespace transform {
26 
27 // extend the TFCore class and the TFCpp class
29  public:
41  virtual TransformStamped lookupTransform(
42  const std::string& target_frame, const std::string& source_frame,
43  const cyber::Time& time, const float timeout_second = 0.01f) const = 0;
44 
61  virtual TransformStamped lookupTransform(
62  const std::string& target_frame, const cyber::Time& target_time,
63  const std::string& source_frame, const cyber::Time& source_time,
64  const std::string& fixed_frame,
65  const float timeout_second = 0.01f) const = 0;
66 
76  virtual bool canTransform(const std::string& target_frame,
77  const std::string& source_frame,
78  const cyber::Time& time,
79  const float timeout_second = 0.01f,
80  std::string* errstr = nullptr) const = 0;
81 
94  virtual bool canTransform(const std::string& target_frame,
95  const cyber::Time& target_time,
96  const std::string& source_frame,
97  const cyber::Time& source_time,
98  const std::string& fixed_frame,
99  const float timeout_second = 0.01f,
100  std::string* errstr = nullptr) const = 0;
101 
102  // Transform, simple api, with pre-allocation
103  template <typename T>
104  T& transform(const T& in, T& out, const std::string& target_frame, // NOLINT
105  float timeout = 0.0f) const {
106  // do the transform
107  tf2::doTransform(in, out,
108  lookupTransform(target_frame, tf2::getFrameId(in),
109  tf2::getTimestamp(in), timeout));
110  return out;
111  }
112 
113  // transform, simple api, no pre-allocation
114  template <typename T>
115  T transform(const T& in, const std::string& target_frame,
116  float timeout = 0.0f) const {
117  T out;
118  return transform(in, out, target_frame, timeout);
119  }
120 
121  // transform, simple api, different types, pre-allocation
122  template <typename A, typename B>
123  B& transform(const A& in, B& out, const std::string& target_frame, // NOLINT
124  float timeout = 0.0f) const {
125  A copy = transform(in, target_frame, timeout);
126  tf2::convert(copy, out);
127  return out;
128  }
129 
130  // Transform, advanced api, with pre-allocation
131  template <typename T>
132  T& transform(const T& in, T& out, const std::string& target_frame, // NOLINT
133  const cyber::Time& target_time, const std::string& fixed_frame,
134  float timeout = 0.0f) const {
135  // do the transform
136  tf2::doTransform(
137  in, out,
138  lookupTransform(target_frame, target_time, tf2::getFrameId(in),
139  tf2::getTimestamp(in), fixed_frame, timeout));
140  return out;
141  }
142 
143  // transform, advanced api, no pre-allocation
144  template <typename T>
145  T transform(const T& in, const std::string& target_frame,
146  const cyber::Time& target_time, const std::string& fixed_frame,
147  float timeout = 0.0f) const {
148  T out;
149  return transform(in, out, target_frame, target_time, fixed_frame, timeout);
150  }
151 
152  // Transform, advanced api, different types, with pre-allocation
153  template <typename A, typename B>
154  B& transform(const A& in, B& out, const std::string& target_frame, // NOLINT
155  const cyber::Time& target_time, const std::string& fixed_frame,
156  float timeout = 0.0f) const {
157  // do the transform
158  A copy = transform(in, target_frame, target_time, fixed_frame, timeout);
159  tf2::convert(copy, out);
160  return out;
161  }
162 }; // class
163 
164 } // namespace transform
165 } // namespace apollo
T transform(const T &in, const std::string &target_frame, const cyber::Time &target_time, const std::string &fixed_frame, float timeout=0.0f) const
Definition: buffer_interface.h:145
virtual bool canTransform(const std::string &target_frame, const std::string &source_frame, const cyber::Time &time, const float timeout_second=0.01f, std::string *errstr=nullptr) const =0
Test if a transform is possible.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
T & transform(const T &in, T &out, const std::string &target_frame, const cyber::Time &target_time, const std::string &fixed_frame, float timeout=0.0f) const
Definition: buffer_interface.h:132
const size_t A
Definition: util.h:160
T transform(const T &in, const std::string &target_frame, float timeout=0.0f) const
Definition: buffer_interface.h:115
virtual TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const cyber::Time &time, const float timeout_second=0.01f) const =0
Get the transform between two frames by frame ID.
Definition: buffer_interface.h:28
B & transform(const A &in, B &out, const std::string &target_frame, float timeout=0.0f) const
Definition: buffer_interface.h:123
T & transform(const T &in, T &out, const std::string &target_frame, float timeout=0.0f) const
Definition: buffer_interface.h:104
Cyber has builtin time type Time.
Definition: time.h:31
B & transform(const A &in, B &out, const std::string &target_frame, const cyber::Time &target_time, const std::string &fixed_frame, float timeout=0.0f) const
Definition: buffer_interface.h:154