18
18
19
19
#include " Eigen/Core"
20
20
#include " absl/memory/memory.h"
21
+ #include " absl/strings/str_format.h"
21
22
#include " cartographer/common/lua_parameter_dictionary.h"
22
23
#include " cartographer/common/math.h"
23
24
#include " cartographer/io/draw_trajectories.h"
@@ -84,12 +85,14 @@ ProbabilityGridPointsProcessor::ProbabilityGridPointsProcessor(
84
85
probability_grid_range_data_inserter_options,
85
86
const DrawTrajectories& draw_trajectories, const OutputType& output_type,
86
87
std::unique_ptr<FileWriter> file_writer,
88
+ std::unique_ptr<FileWriter> yaml_file_writer,
87
89
const std::vector<mapping::proto::Trajectory>& trajectories,
88
90
PointsProcessor* const next)
89
91
: draw_trajectories_(draw_trajectories),
90
92
output_type_ (output_type),
91
93
trajectories_(trajectories),
92
94
file_writer_(std::move(file_writer)),
95
+ yaml_file_writer_(std::move(yaml_file_writer)),
93
96
next_(next),
94
97
range_data_inserter_(probability_grid_range_data_inserter_options),
95
98
probability_grid_(
@@ -114,14 +117,16 @@ ProbabilityGridPointsProcessor::FromDictionary(
114
117
dictionary->HasKey (" output_type" )
115
118
? OutputTypeFromString (dictionary->GetString (" output_type" ))
116
119
: OutputType::kPng ;
120
+
121
+ std::string filename = dictionary->GetString (" filename" ) +
122
+ FileExtensionFromOutputType (output_type);
123
+
117
124
return absl::make_unique<ProbabilityGridPointsProcessor>(
118
125
dictionary->GetDouble (" resolution" ),
119
126
mapping::CreateProbabilityGridRangeDataInserterOptions2D (
120
127
dictionary->GetDictionary (" range_data_inserter" ).get ()),
121
- draw_trajectories, output_type,
122
- file_writer_factory (dictionary->GetString (" filename" ) +
123
- FileExtensionFromOutputType (output_type)),
124
- trajectories, next);
128
+ draw_trajectories, output_type, file_writer_factory (filename),
129
+ file_writer_factory (filename + " .yaml" ), trajectories, next);
125
130
}
126
131
127
132
void ProbabilityGridPointsProcessor::Process (
@@ -145,6 +150,30 @@ PointsProcessor::FlushResult ProbabilityGridPointsProcessor::Flush() {
145
150
}
146
151
image->WritePng (file_writer_.get ());
147
152
CHECK (file_writer_->Close ());
153
+
154
+ // write YAML which confirms to http://wiki.ros.org/map_server
155
+ const char * format =
156
+ " image: %s\n "
157
+ " resolution: %f\n "
158
+ " origin: [%f, %f, 0]\n "
159
+ " occupied_thresh: 0.65\n "
160
+ " free_thresh: 0.196\n "
161
+ " negate: 0\n " ;
162
+
163
+ const cartographer::mapping::MapLimits& limits =
164
+ probability_grid_.limits ();
165
+ const cartographer::mapping::CellLimits& cell_limits =
166
+ limits.cell_limits ();
167
+
168
+ double resolution = limits.resolution ();
169
+ std::string yaml_str = absl::StrFormat (
170
+ format, file_writer_->GetFilename ().c_str (), resolution,
171
+ limits.max ().x () -
172
+ resolution * (cell_limits.num_x_cells - offset.x ()),
173
+ limits.max ().y () -
174
+ resolution * (cell_limits.num_y_cells - offset.y ()));
175
+ yaml_file_writer_->Write (yaml_str.c_str (), yaml_str.length ());
176
+ CHECK (yaml_file_writer_->Close ());
148
177
}
149
178
} else if (output_type_ == OutputType::kPb ) {
150
179
const auto probability_grid_proto = probability_grid_.ToProto ();
0 commit comments