28 #include "cartographer/mapping/proto/trajectory.pb.h" 32 #include "gflags/gflags.h" 33 #include "glog/logging.h" 36 trajectory_filename,
"",
37 "Proto containing the trajectory of which to assess the quality.");
39 "Relations file containing the ground truth.");
42 namespace ground_truth {
46 transform_interpolation_buffer,
48 constexpr
int64 kUtsTicksPerSecond = 10000000;
53 return transform_interpolation_buffer.Lookup(common_time);
65 (pose1.inverse() * pose2) * expected.
inverse();
70 string MeanAndStdDevString(
const std::vector<double>& values) {
71 CHECK_GE(values.size(), 2);
73 std::accumulate(values.begin(), values.end(), 0.) / values.size();
74 double sum_of_squared_differences = 0.;
75 for (
const double value : values) {
78 const double standard_deviation =
79 std::sqrt(sum_of_squared_differences / (values.size() - 1));
80 std::ostringstream out;
81 out << std::fixed << std::setprecision(5) << mean <<
" +/- " 82 << standard_deviation;
83 return string(out.str());
86 string StatisticsString(
const std::vector<Error>& errors) {
87 std::vector<double> translational_errors;
88 std::vector<double> squared_translational_errors;
89 std::vector<double> rotational_errors_degrees;
90 std::vector<double> squared_rotational_errors_degrees;
91 for (
const Error& error : errors) {
92 translational_errors.push_back(std::sqrt(error.translational_squared));
93 squared_translational_errors.push_back(error.translational_squared);
94 rotational_errors_degrees.push_back(
96 squared_rotational_errors_degrees.push_back(
99 return "Abs translational error " +
100 MeanAndStdDevString(translational_errors) +
102 "Sqr translational error " +
103 MeanAndStdDevString(squared_translational_errors) +
105 "Abs rotational error " +
106 MeanAndStdDevString(rotational_errors_degrees) +
108 "Sqr rotational error " +
109 MeanAndStdDevString(squared_rotational_errors_degrees) +
" deg^2\n";
112 void Run(
const string& trajectory_filename,
const string& relations_filename) {
113 LOG(INFO) <<
"Reading trajectory from '" << trajectory_filename <<
"'...";
114 mapping::proto::Trajectory trajectory_proto;
116 std::ifstream trajectory_stream(trajectory_filename.c_str(),
118 CHECK(trajectory_proto.ParseFromIstream(&trajectory_stream));
121 const auto transform_interpolation_buffer =
124 LOG(INFO) <<
"Reading relations from '" << relations_filename <<
"'...";
125 std::vector<Error> errors;
127 std::ifstream relations_stream(relations_filename.c_str());
128 double time1, time2, x, y, z, roll, pitch, yaw;
129 while (relations_stream >> time1 >> time2 >> x >> y >> z >> roll >> pitch >>
131 const auto pose1 = LookupPose(*transform_interpolation_buffer, time1);
132 const auto pose2 = LookupPose(*transform_interpolation_buffer, time2);
136 errors.push_back(ComputeError(pose1, pose2, expected));
138 CHECK(relations_stream.eof());
141 LOG(INFO) <<
"Result:\n" << StatisticsString(errors);
148 int main(
int argc,
char** argv) {
149 google::InitGoogleLogging(argv[0]);
150 FLAGS_logtostderr =
true;
151 google::SetUsageMessage(
153 "This program computes the relation based metric described in:\n" 154 "R. Kuemmerle, B. Steder, C. Dornhege, M. Ruhnke, G. Grisetti,\n" 155 "C. Stachniss, and A. Kleiner, \"On measuring the accuracy of SLAM\n" 156 "algorithms,\" Autonomous Robots, vol. 27, no. 4, pp. 387–407, 2009.\n" 158 "Note: Timestamps in the relations_file are interpreted relative to\n" 160 google::ParseCommandLineFlags(&argc, &argv,
true);
162 if (FLAGS_trajectory_filename.empty() || FLAGS_relations_filename.empty()) {
163 google::ShowUsageWithFlagsRestrict(argv[0],
"compute_relations_metrics");
166 ::cartographer::ground_truth::Run(FLAGS_trajectory_filename,
167 FLAGS_relations_filename);
double translational_squared
constexpr int64 kUtsEpochOffsetFromUnixEpochInSeconds
constexpr double RadToDeg(double rad)
UniversalTimeScaleClock::time_point Time
Time FromUniversal(const int64 ticks)
Duration FromSeconds(const double seconds)
double rotational_squared
int main(int argc, char **argv)
DEFINE_string(trajectory_filename,"","Proto containing the trajectory of which to assess the quality.")