Cartographer_ros: Extract pdstream file data

Created on 6 Sep 2018  路  5Comments  路  Source: cartographer-project/cartographer_ros

I got a pdstream file by running the offline_backpack_2d.launch. What is the content of this document? How do I extract the contents of the document and save it to .txt?

Most helpful comment

With the latest Cartographer you can at least run cartographer_pbstream info <pbstream_file> --all_debug_strings... have fun with all that text :P

All 5 comments

A pbstream file is Cartographer's own file format, which contains serialized, compressed protobuf messages of cartographer.mapping.proto.SerializationHeader and cartographer.mapping.proto.SerializedData, which in turn contain various submessages that contain essentially all data of a PoseGraph.

To extract data, see the implementation of MapBuilder::LoadState.

I can get a pose (x,y,z,quaternion) of EndOfTrajectory by using this code

  ::cartographer::io::ProtoStreamReader reader(FLAGS_pbstream_filename);
  cartographer_ros::NodeOptions node_options;
  cartographer_ros::TrajectoryOptions trajectory_options;
  std::tie(node_options, trajectory_options) =
      cartographer_ros::LoadOptions(FLAGS_configuration_directory, FLAGS_configuration_basename);
  auto map_builder =
      cartographer::common::make_unique<cartographer::mapping::MapBuilder>(
          node_options.map_builder_options);

  // ed: load pbstream
  map_builder->LoadState(&reader, true);

  // ed: get TrajectoryNodePose
  const auto node_poses = map_builder->pose_graph()->GetTrajectoryNodePoses();
  double pbstream_x = std::prev(node_poses.EndOfTrajectory(0))->data.global_pose.translation().x();
  double pbstream_y = std::prev(node_poses.EndOfTrajectory(0))->data.global_pose.translation().y();
  double pbstream_z = std::prev(node_poses.EndOfTrajectory(0))->data.global_pose.translation().z();
  double pbstream_quat_x = (std::prev(node_poses.EndOfTrajectory(0)))->data.global_pose.rotation().x();
  double pbstream_quat_y = (std::prev(node_poses.EndOfTrajectory(0)))->data.global_pose.rotation().y();
  double pbstream_quat_z = (std::prev(node_poses.EndOfTrajectory(0)))->data.global_pose.rotation().z();
  double pbstream_quat_w = (std::prev(node_poses.EndOfTrajectory(0)))->data.global_pose.rotation().w();

see more details from here
https://gist.github.com/tigerk0430/7f67a9ca10824ea56875ad4b7a449b49

@tigerk0430 First of all, thank you for your answer. I want to extract the trajectory and submaps in the pbstream file and save them as TXT files. Do you have any suggestions? I look forward to your reply.

@woshidaye
well, If I were you, I could save trajectory.txt file by using code I posted using while loop.

but I have no idea how to save submap.txt file because I don't know how to extract submap data from .pbstream file.
sorry for it and hope you post the way to extract submap data from .pbstream if you figure it out

With the latest Cartographer you can at least run cartographer_pbstream info <pbstream_file> --all_debug_strings... have fun with all that text :P

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ojura picture ojura  路  5Comments

zchao9456 picture zchao9456  路  4Comments

shreyasgokhale picture shreyasgokhale  路  5Comments

ashnarayan13 picture ashnarayan13  路  4Comments

monabf picture monabf  路  9Comments