Apollo  6.0
Open source self driving car software
buffer.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 <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "tf2/buffer_core.h"
24 #include "tf2/convert.h"
25 
26 #include "cyber/node/node.h"
28 
29 namespace apollo {
30 namespace transform {
31 
32 // extend the BufferInterface class and BufferCore class
33 class Buffer : public BufferInterface, public tf2::BufferCore {
34  public:
42  int Init();
43 
55  virtual TransformStamped lookupTransform(
56  const std::string& target_frame, const std::string& source_frame,
57  const cyber::Time& time, const float timeout_second = 0.01f) const;
58 
75  virtual TransformStamped lookupTransform(
76  const std::string& target_frame, const cyber::Time& target_time,
77  const std::string& source_frame, const cyber::Time& source_time,
78  const std::string& fixed_frame, const float timeout_second = 0.01f) const;
79 
89  virtual bool canTransform(const std::string& target_frame,
90  const std::string& source_frame,
91  const cyber::Time& target_time,
92  const float timeout_second = 0.01f,
93  std::string* errstr = nullptr) const;
94 
107  virtual bool canTransform(const std::string& target_frame,
108  const cyber::Time& target_time,
109  const std::string& source_frame,
110  const cyber::Time& source_time,
111  const std::string& fixed_frame,
112  const float timeout_second = 0.01f,
113  std::string* errstr = nullptr) const;
114 
115  bool GetLatestStaticTF(const std::string& frame_id,
116  const std::string& child_frame_id,
117  TransformStamped* tf);
118 
119  private:
120  void SubscriptionCallback(
121  const std::shared_ptr<const TransformStampeds>& transform);
122  void StaticSubscriptionCallback(
123  const std::shared_ptr<const TransformStampeds>& transform);
124  void SubscriptionCallbackImpl(
125  const std::shared_ptr<const TransformStampeds>& transform,
126  bool is_static);
127 
128  void TF2MsgToCyber(const geometry_msgs::TransformStamped& tf2_trans_stamped,
129  TransformStamped& trans_stamped) const; // NOLINT
130 
131  std::unique_ptr<cyber::Node> node_;
132  std::shared_ptr<cyber::Reader<TransformStampeds>> message_subscriber_tf_;
133  std::shared_ptr<cyber::Reader<TransformStampeds>>
134  message_subscriber_tf_static_;
135 
136  cyber::Time last_update_;
137  std::vector<geometry_msgs::TransformStamped> static_msgs_;
138 
140 }; // class
141 
142 } // namespace transform
143 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
virtual bool canTransform(const std::string &target_frame, const std::string &source_frame, const cyber::Time &target_time, const float timeout_second=0.01f, std::string *errstr=nullptr) const
Test if a transform is possible.
virtual TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const cyber::Time &time, const float timeout_second=0.01f) const
Get the transform between two frames by frame ID.
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
Definition: buffer.h:33
Definition: buffer_interface.h:28
T & transform(const T &in, T &out, const std::string &target_frame, float timeout=0.0f) const
Definition: buffer_interface.h:104
int Init()
Constructor for a Buffer object.
bool GetLatestStaticTF(const std::string &frame_id, const std::string &child_frame_id, TransformStamped *tf)
Cyber has builtin time type Time.
Definition: time.h:31