@@ -594,13 +594,15 @@ void tryWriteMapToFile(
594594 std::string image_name = mapdatafile.substr (file_name_index + 1 );
595595
596596 YAML::Emitter e;
597- e << YAML::Precision (3 );
597+ e << YAML::Precision (7 );
598598 e << YAML::BeginMap;
599599 e << YAML::Key << " image" << YAML::Value << image_name;
600600 e << YAML::Key << " mode" << YAML::Value << map_mode_to_string (save_parameters.mode );
601- e << YAML::Key << " resolution" << YAML::Value << map.info .resolution ;
602- e << YAML::Key << " origin" << YAML::Flow << YAML::BeginSeq << map.info .origin .position .x <<
603- map.info .origin .position .y << yaw << YAML::EndSeq;
601+ e << YAML::Key << " resolution" << YAML::Value << to_string_with_precision (map.info .resolution ,
602+ 3 );
603+ e << YAML::Key << " origin" << YAML::Flow << YAML::BeginSeq <<
604+ to_string_with_precision (map.info .origin .position .x , 3 ) <<
605+ to_string_with_precision (map.info .origin .position .y , 3 ) << yaw << YAML::EndSeq;
604606 e << YAML::Key << " negate" << YAML::Value << 0 ;
605607
606608 if (save_parameters.mode == MapMode::Trinary) {
@@ -611,8 +613,10 @@ void tryWriteMapToFile(
611613 e << YAML::Key << " occupied_thresh" << YAML::Value << 0.65 ;
612614 e << YAML::Key << " free_thresh" << YAML::Value << 0.196 ;
613615 } else {
614- e << YAML::Key << " occupied_thresh" << YAML::Value << save_parameters.occupied_thresh ;
615- e << YAML::Key << " free_thresh" << YAML::Value << save_parameters.free_thresh ;
616+ e << YAML::Key << " occupied_thresh" << YAML::Value <<
617+ to_string_with_precision (save_parameters.occupied_thresh , 3 );
618+ e << YAML::Key << " free_thresh" << YAML::Value <<
619+ to_string_with_precision (save_parameters.free_thresh , 3 );
616620 }
617621
618622 if (!e.good ()) {
@@ -648,4 +652,12 @@ bool saveMapToFile(
648652 return true ;
649653}
650654
655+ std::string to_string_with_precision (double value, int precision)
656+ {
657+ std::ostringstream out;
658+ out << std::fixed << std::setprecision (precision) << value;
659+
660+ return out.str ();
661+ }
662+
651663} // namespace nav2_map_server
0 commit comments