Add field name to TargetMap flatbuffer

We'll use this to know which map we're using in code once we load it on
the robot.

Signed-off-by: Milind Upadhyay <milind.upadhyay@gmail.com>
Change-Id: Id54b82e7b7f07b767a84e266d47468973cbe319e
diff --git a/frc971/vision/target_mapper.cc b/frc971/vision/target_mapper.cc
index 3342670..ccaa805 100644
--- a/frc971/vision/target_mapper.cc
+++ b/frc971/vision/target_mapper.cc
@@ -314,7 +314,8 @@
   return summary.IsSolutionUsable();
 }
 
-void TargetMapper::Solve(std::optional<std::string_view> output_path) {
+void TargetMapper::Solve(std::string_view field_name,
+                         std::optional<std::string_view> output_dir) {
   ceres::Problem problem;
   BuildOptimizationProblem(&target_poses_, target_constraints_, &problem);
 
@@ -323,15 +324,18 @@
 
   // TODO(milind): add origin to first target offset to all poses
 
-  auto map_json = MapToJson();
+  auto map_json = MapToJson(field_name);
   VLOG(1) << "Solved target poses: " << map_json;
-  if (output_path.has_value()) {
-    LOG(INFO) << "Writing map to file: " << output_path.value();
-    aos::util::WriteStringToFileOrDie(output_path.value(), map_json);
+
+  if (output_dir.has_value()) {
+    std::string output_path =
+        absl::StrCat(output_dir.value(), "/", field_name, ".json");
+    LOG(INFO) << "Writing map to file: " << output_path;
+    aos::util::WriteStringToFileOrDie(output_path, map_json);
   }
 }
 
-std::string TargetMapper::MapToJson() const {
+std::string TargetMapper::MapToJson(std::string_view field_name) const {
   flatbuffers::FlatBufferBuilder fbb;
 
   // Convert poses to flatbuffers
@@ -346,8 +350,9 @@
     target_poses_fbs.emplace_back(target_pose_builder.Finish());
   }
 
-  flatbuffers::Offset<TargetMap> target_map_offset =
-      CreateTargetMap(fbb, fbb.CreateVector(target_poses_fbs));
+  const auto field_name_offset = fbb.CreateString(field_name);
+  flatbuffers::Offset<TargetMap> target_map_offset = CreateTargetMap(
+      fbb, fbb.CreateVector(target_poses_fbs), field_name_offset);
 
   return aos::FlatbufferToJson(
       flatbuffers::GetMutableTemporaryPointer(fbb, target_map_offset),