27 const std::string ¶ms_path) {
28 const std::string params_dir = params_path;
31 YAML::Node lidar_height =
32 YAML::LoadFile(params_dir +
"/" +
"velodyne128_height.yaml");
33 Eigen::Affine3d trans;
34 trans.linear() = Eigen::Matrix3d::Identity();
35 AINFO << trans.translation() <<
" "
36 << lidar_height[
"vehicle"][
"parameters"][
"height"];
37 trans.translation() << 0.0, 0.0,
38 lidar_height[
"vehicle"][
"parameters"][
"height"].as<
double>();
40 }
catch (YAML::InvalidNode &in) {
41 AERROR <<
"load velodyne128 extrisic file error"
42 <<
" YAML::InvalidNode exception";
44 }
catch (YAML::TypedBadConversion<float> &bc) {
45 AERROR <<
"load velodyne128 extrisic file error, "
46 <<
"YAML::TypedBadConversion exception";
48 }
catch (YAML::Exception &e) {
49 AERROR <<
"load velodyne128 extrisic file "
50 <<
" error, YAML exception:" << e.what();
54 std::vector<std::string> extrinsic_filelist;
55 extrinsic_filelist.push_back(params_dir +
56 "/velodyne128_novatel_extrinsics.yaml");
57 for (
const auto &camera_name : camera_names) {
58 extrinsic_filelist.push_back(params_dir +
"/" + camera_name +
62 for (
const auto &yaml_file : extrinsic_filelist) {
64 YAML::Node node = YAML::LoadFile(yaml_file);
66 AINFO <<
"Load " << yaml_file <<
" failed! please check!";
69 std::string child_frame_id = node[
"child_frame_id"].as<std::string>();
70 std::string frame_id = node[
"header"][
"frame_id"].as<std::string>();
71 double q[4] = {node[
"transform"][
"rotation"][
"w"].as<
double>(),
72 node[
"transform"][
"rotation"][
"x"].as<double>(),
73 node[
"transform"][
"rotation"][
"y"].as<
double>(),
74 node[
"transform"][
"rotation"][
"z"].as<double>()};
75 double t[3] = {node[
"transform"][
"translation"][
"x"].as<
double>(),
76 node[
"transform"][
"translation"][
"y"].as<double>(),
77 node[
"transform"][
"translation"][
"z"].as<
double>()};
78 Eigen::Quaterniond qq(q[0], q[1], q[2], q[3]);
79 Eigen::Affine3d trans;
80 trans.linear() = qq.matrix();
81 trans.translation() << t[0], t[1], t[2];
83 AINFO <<
"failed to add transform from " << child_frame_id <<
" to "
84 << frame_id << std::endl;
86 }
catch (YAML::InvalidNode &in) {
87 AERROR <<
"load camera extrisic file " << yaml_file
88 <<
" with error, YAML::InvalidNode exception";
90 }
catch (YAML::TypedBadConversion<double> &bc) {
91 AERROR <<
"load camera extrisic file " << yaml_file
92 <<
" with error, YAML::TypedBadConversion exception";
94 }
catch (YAML::Exception &e) {
95 AERROR <<
"load camera extrisic file " << yaml_file
96 <<
" with error, YAML exception:" << e.what();
131 for (
auto &&tf : tf_) {
132 if (
Equal(timestamp, tf.timestamp, error_limit_)) {
133 Eigen::Quaterniond rotation(tf.qw, tf.qx, tf.qy, tf.qz);
134 pose->linear() = rotation.matrix();
135 pose->translation() << tf.tx, tf.ty, tf.tz;
136 AINFO <<
"Get Pose:\n" << pose->matrix();
144 const std::string &frame_id,
145 const Eigen::Affine3d &transform) {
146 vertices_.insert(child_frame_id);
147 vertices_.insert(frame_id);
149 auto begin = edges_.lower_bound(child_frame_id);
150 auto end = edges_.upper_bound(child_frame_id);
152 for (
auto iter = begin; iter != end; ++iter) {
153 if (iter->second.frame_id == frame_id) {
159 e.child_frame_id = child_frame_id;
160 e.frame_id = frame_id;
161 e.transform = transform;
164 e_inv.child_frame_id = frame_id;
165 e_inv.frame_id = child_frame_id;
166 e_inv.transform = transform.inverse();
167 ADEBUG <<
"Add transform between " << frame_id <<
" and " << child_frame_id;
168 edges_.insert({child_frame_id, e});
169 edges_.insert({frame_id, e_inv});
175 const std::string &frame_id,
176 Eigen::Affine3d *transform) {
177 *transform = Eigen::Affine3d::Identity();
179 if (child_frame_id == frame_id) {
184 if (vertices_.find(child_frame_id) == vertices_.end() ||
185 vertices_.find(frame_id) == vertices_.end()) {
189 std::map<std::string, bool> visited;
190 for (
const auto &item : vertices_) {
191 visited[item] =
false;
194 return FindTransform(child_frame_id, frame_id, transform, &visited);
197bool TransformServer::FindTransform(
const std::string &child_frame_id,
224 if (FindTransform(edge.frame_id, frame_id, &tr, visited)) {
236 for (
auto item : edges_) {
237 AINFO <<
"----------------" << std::endl;
238 AINFO << item.first << std::endl;
239 AINFO <<
"edge: " << std::endl;
240 AINFO <<
"from " << item.second.child_frame_id <<
" to "
241 << item.second.frame_id << std::endl;
242 Eigen::Affine3d trans = item.second.transform;
243 Eigen::Quaterniond quat(trans.linear());
244 AINFO <<
"rot: " << quat.x() <<
" " << quat.y() <<
" " << quat.z() <<
" "
245 << quat.w() << std::endl;
246 AINFO <<
"trans: " << trans.translation()[0] <<
" "
247 << trans.translation()[1] <<
" " << trans.translation()[2]