当前位置:   article > 正文

【cartographer without ros】六、路标landmark数据转换_aruco如何作为cartographer的landmark

aruco如何作为cartographer的landmark

上一节介绍了IMU数据相关转换。

本节就开始介绍cartographer中的LandmarkData数据和Ros中的cartographer_ros_msgs::LandmarkList数据相互转换,方便引入Rosbag进行储存和读取。

目录

1:LandmarkData数据类型

2:cartographer数据转换Ros数据

3:Ros数据转换cartographer数据


1:LandmarkData数据类型

【landmark_data.h】中查看数据结构:

  1. struct LandmarkObservation {
  2.   std::string id;
  3.   transform::Rigid3d landmark_to_tracking_transform;
  4.   double translation_weight;
  5.   double rotation_weight;
  6. };
  7. struct LandmarkData {
  8.   common::Time time;
  9.   std::vector<LandmarkObservation> landmark_observations;
  10. };


2:cartographer数据转换Ros数据

  1. cartographer_ros_msgs::LandmarkList ToRosMsg(cartographer::sensor::LandmarkData landmark_data)
  2.     {
  3.         cartographer_ros_msgs::LandmarkList landmarkList;
  4.         cartographer_ros_msgs::LandmarkEntry landmarkEntry;
  5.         landmarkList.header.frame_id = "base_link";
  6.         landmarkList.header.stamp = common::RosFromCarto(landmark_data.time);
  7.         landmarkList.landmarks.clear();
  8.         for (auto var : landmark_data.landmark_observations)
  9.         {
  10.             landmarkEntry.id = var.id;
  11.             landmarkEntry.tracking_from_landmark_transform.position.x = var.landmark_to_tracking_transform.translation().x();
  12.             landmarkEntry.tracking_from_landmark_transform.position.y = var.landmark_to_tracking_transform.translation().y();
  13.             landmarkEntry.tracking_from_landmark_transform.position.z = 0;
  14.             landmarkEntry.tracking_from_landmark_transform.orientation.x = var.landmark_to_tracking_transform.rotation().x();
  15.             landmarkEntry.tracking_from_landmark_transform.orientation.y = var.landmark_to_tracking_transform.rotation().y();
  16.             landmarkEntry.tracking_from_landmark_transform.orientation.z = var.landmark_to_tracking_transform.rotation().z();
  17.             landmarkEntry.tracking_from_landmark_transform.orientation.w = var.landmark_to_tracking_transform.rotation().w();
  18.             landmarkEntry.translation_weight = var.translation_weight;
  19.             landmarkEntry.rotation_weight = var.rotation_weight;
  20.             landmarkList.landmarks.push_back(landmarkEntry);
  21.         }
  22.         return landmarkList;
  23.     }


3:Ros数据转换cartographer数据

  1. cartographer::sensor::LandmarkData ToCartoSensor(cartographer_ros_msgs::LandmarkList landmark_list)
  2. {
  3.   cartographer::sensor::LandmarkData landmark_data;
  4.   landmark_data.time = FromRos(landmark_list.header.stamp);
  5.   for (const LandmarkEntry& entry : landmark_list.landmarks) {
  6.     landmark_data.landmark_observations.push_back(
  7.         {entry.id, ToRigid3d(entry.tracking_from_landmark_transform),
  8.          entry.translation_weight, entry.rotation_weight});
  9.   }
  10.   return landmark_data;
  11. }

【完】


下一节会介绍Rosbag的引入和使用,即使脱离了ros环境依然能够进行存包读包等操作,方便支持离线建图定位等功能,以及对原始数据进行分析

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/876885
推荐阅读
相关标签
  

闽ICP备14008679号