Apollo 11.0
自动驾驶开放平台
transform_wrapper.h
浏览该文件的文档.
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#pragma once
17
18#include <deque>
19#include <memory>
20#include <string>
21
22#include "Eigen/Core"
23#include "Eigen/Dense"
24#include "gflags/gflags.h"
25
27
28namespace apollo {
29namespace perception {
30namespace onboard {
31
33
34DECLARE_string(obs_sensor2novatel_tf2_frame_id);
35DECLARE_string(obs_novatel2world_tf2_frame_id);
36DECLARE_string(obs_novatel2world_tf2_child_frame_id);
37DECLARE_double(obs_tf2_buff_size);
38DECLARE_bool(hardware_trigger);
39
41 double timestamp = 0.0; // in second
42 Eigen::Translation3d translation;
43 Eigen::Quaterniond rotation;
44
45 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
46};
47
49 public:
50 TransformCache() = default;
51 ~TransformCache() = default;
52
53 void AddTransform(const StampedTransform& transform);
54 bool QueryTransform(double timestamp, StampedTransform* transform,
55 double max_duration = 0.0);
56
57 inline void SetCacheDuration(double duration) { cache_duration_ = duration; }
58
59 protected:
60 // in ascending order of time
61 std::deque<StampedTransform> transforms_;
62 double cache_duration_ = 1.0;
63};
64
66 public:
68 ~TransformWrapper() = default;
69
70 void Init(const std::string& sensor2novatel_tf2_child_frame_id);
71 void Init(const std::string& sensor2novatel_tf2_frame_id,
72 const std::string& sensor2novatel_tf2_child_frame_id,
73 const std::string& novatel2world_tf2_frame_id,
74 const std::string& novatel2world_tf2_child_frame_id);
75
76 // Attention: must initialize TransformWrapper first
77 bool GetSensor2worldTrans(double timestamp,
78 Eigen::Affine3d* sensor2world_trans,
79 Eigen::Affine3d* novatel2world_trans = nullptr);
80
81 bool GetExtrinsics(Eigen::Affine3d* trans);
82
83 bool GetExtrinsics(double timestamp, Eigen::Affine3d* trans);
84
85 // Attention: can be called without initlization
86 bool GetTrans(double timestamp, Eigen::Affine3d* trans,
87 const std::string& frame_id, const std::string& child_frame_id);
88
89 bool GetExtrinsicsBySensorId(const std::string& from_sensor_id,
90 const std::string& to_sensor_id,
91 Eigen::Affine3d* trans);
92
93 protected:
94 bool QueryTrans(double timestamp, StampedTransform* trans,
95 const std::string& frame_id,
96 const std::string& child_frame_id);
97
98 private:
99 bool inited_ = false;
100
101 Buffer* tf2_buffer_ = Buffer::Instance();
102
103 std::string sensor2novatel_tf2_frame_id_;
104 std::string sensor2novatel_tf2_child_frame_id_;
105 std::string novatel2world_tf2_frame_id_;
106 std::string novatel2world_tf2_child_frame_id_;
107
108 std::unique_ptr<Eigen::Affine3d> sensor2novatel_extrinsics_;
109
110 TransformCache transform_cache_;
111};
112
113} // namespace onboard
114} // namespace perception
115} // namespace apollo
bool QueryTransform(double timestamp, StampedTransform *transform, double max_duration=0.0)
void AddTransform(const StampedTransform &transform)
std::deque< StampedTransform > transforms_
bool QueryTrans(double timestamp, StampedTransform *trans, const std::string &frame_id, const std::string &child_frame_id)
bool GetExtrinsicsBySensorId(const std::string &from_sensor_id, const std::string &to_sensor_id, Eigen::Affine3d *trans)
bool GetTrans(double timestamp, Eigen::Affine3d *trans, const std::string &frame_id, const std::string &child_frame_id)
bool GetSensor2worldTrans(double timestamp, Eigen::Affine3d *sensor2world_trans, Eigen::Affine3d *novatel2world_trans=nullptr)
void Init(const std::string &sensor2novatel_tf2_child_frame_id)
DECLARE_bool(obs_enable_hdmap_input)
DECLARE_string(obs_screen_output_dir)
DECLARE_double(obs_buffer_match_precision)
class register implement
Definition arena_queue.h:37