Apollo  6.0
Open source self driving car software
transform_server.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 #pragma once
17 
18 #include <map>
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 #include "Eigen/Geometry"
24 
25 namespace apollo {
26 namespace perception {
27 namespace camera {
28 
29 struct Transform {
30  double timestamp;
31  double qw;
32  double qx;
33  double qy;
34  double qz;
35  double tx;
36  double ty;
37  double tz;
38 };
39 
41  public:
44 
45  inline const std::set<std::string> &vertices() { return vertices_; }
46 
47  bool Init(const std::vector<std::string> &camera_names,
48  const std::string &params_path);
49 
50  bool AddTransform(const std::string &child_frame_id,
51  const std::string &frame_id,
52  const Eigen::Affine3d &transform);
53 
54  bool QueryTransform(const std::string &child_frame_id,
55  const std::string &frame_id, Eigen::Affine3d *transform);
56 
57  void print();
58 
59  bool LoadFromFile(const std::string &tf_input, float frequency = 200.0f);
60 
61  bool QueryPos(double timestamp, Eigen::Affine3d *pose);
62 
63  private:
64  struct Edge {
65  std::string child_frame_id;
66  std::string frame_id;
67  Eigen::Affine3d transform;
68  };
69 
70  std::vector<Transform> tf_;
71 
72  double error_limit_ = 1.0;
73  // frame ids
74  std::set<std::string> vertices_;
75 
76  // multimap from child frame id to frame id
77  std::multimap<std::string, Edge> edges_;
78 
79  bool FindTransform(const std::string &child_frame_id,
80  const std::string &frame_id, Eigen::Affine3d *transform,
81  std::map<std::string, bool> *visited);
82 };
83 
84 } // namespace camera
85 } // namespace perception
86 } // namespace apollo
Definition: transform_server.h:29
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
~TransformServer()
Definition: transform_server.h:43
const std::set< std::string > & vertices()
Definition: transform_server.h:45
double qx
Definition: transform_server.h:32
double tx
Definition: transform_server.h:35
double qz
Definition: transform_server.h:34
Definition: transform_server.h:40
double timestamp
Definition: transform_server.h:30
double qw
Definition: transform_server.h:31
bool Init(const char *binary_name)
TransformServer()
Definition: transform_server.h:42
double qy
Definition: transform_server.h:33
double ty
Definition: transform_server.h:36
double tz
Definition: transform_server.h:37
Eigen::Affine3d Affine3d
Definition: base_map_fwd.h:34