Move over to ABSL logging and flags.

Removes gperftools too since that wants gflags.

Here come the fireworks.

Change-Id: I79cb7bcf60f1047fbfa28bfffc21a0fd692e4b1c
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/y2024/localizer/localizer.cc b/y2024/localizer/localizer.cc
index 90423ca..cb11c44 100644
--- a/y2024/localizer/localizer.cc
+++ b/y2024/localizer/localizer.cc
@@ -1,6 +1,6 @@
 #include "y2024/localizer/localizer.h"
 
-#include "gflags/gflags.h"
+#include "absl/flags/flag.h"
 
 #include "aos/containers/sized_array.h"
 #include "frc971/control_loops/drivetrain/localizer_generated.h"
@@ -9,38 +9,36 @@
 #include "frc971/vision/target_map_utils.h"
 #include "y2024/constants.h"
 
-DEFINE_double(max_pose_error, 1e-5,
-              "Throw out target poses with a higher pose error than this");
-DEFINE_double(max_distortion, 1000.0, "");
-DEFINE_double(
-    max_pose_error_ratio, 0.4,
-    "Throw out target poses with a higher pose error ratio than this");
-DEFINE_double(distortion_noise_scalar, 4.0,
-              "Scale the target pose distortion factor by this when computing "
-              "the noise.");
-DEFINE_double(
-    max_implied_yaw_error, 5.0,
+ABSL_FLAG(double, max_pose_error, 1e-5,
+          "Throw out target poses with a higher pose error than this");
+ABSL_FLAG(double, max_distortion, 1000.0, "");
+ABSL_FLAG(double, max_pose_error_ratio, 0.4,
+          "Throw out target poses with a higher pose error ratio than this");
+ABSL_FLAG(double, distortion_noise_scalar, 4.0,
+          "Scale the target pose distortion factor by this when computing "
+          "the noise.");
+ABSL_FLAG(
+    double, max_implied_yaw_error, 5.0,
     "Reject target poses that imply a robot yaw of more than this many degrees "
     "off from our estimate.");
-DEFINE_double(
-    max_implied_teleop_yaw_error, 30.0,
+ABSL_FLAG(
+    double, max_implied_teleop_yaw_error, 30.0,
     "Reject target poses that imply a robot yaw of more than this many degrees "
     "off from our estimate.");
-DEFINE_double(max_distance_to_target, 5.0,
-              "Reject target poses that have a 3d distance of more than this "
-              "many meters.");
-DEFINE_double(max_auto_image_robot_speed, 5.0,
-              "Reject target poses when the robot is travelling faster than "
-              "this speed in auto.");
-DEFINE_bool(
-    do_xytheta_corrections, false,
+ABSL_FLAG(double, max_distance_to_target, 5.0,
+          "Reject target poses that have a 3d distance of more than this "
+          "many meters.");
+ABSL_FLAG(double, max_auto_image_robot_speed, 5.0,
+          "Reject target poses when the robot is travelling faster than "
+          "this speed in auto.");
+ABSL_FLAG(
+    bool, do_xytheta_corrections, false,
     "If set, uses the x/y/theta corrector rather than a heading/distance/skew "
     "one. This is better conditioned currently, but is theoretically worse due "
     "to not capturing noise effectively.");
-DEFINE_bool(
-    always_use_extra_tags, true,
-    "If set, we will use the \"deweighted\" tags even in auto mode (this "
-    "affects april tags whose field positions we do not trust as much).");
+ABSL_FLAG(bool, always_use_extra_tags, true,
+          "If set, we will use the \"deweighted\" tags even in auto mode (this "
+          "affects april tags whose field positions we do not trust as much).");
 
 namespace y2024::localizer {
 namespace {
@@ -380,8 +378,8 @@
 }
 
 namespace {
-// Converts a camera transformation matrix from treating the +Z axis from
-// pointing straight out the lens to having the +X pointing straight out the
+// converts a camera transformation matrix from treating the +z axis from
+// pointing straight out the lens to having the +x pointing straight out the
 // lens, with +Z going "up" (i.e., -Y in the normal convention) and +Y going
 // leftwards (i.e., -X in the normal convention).
 Localizer::Transform ZToXCamera(const Localizer::Transform &transform) {
@@ -419,7 +417,8 @@
   }
   double april_tag_noise_scalar = 1.0;
   if (DeweightAprilTag(target_id)) {
-    if (!FLAGS_always_use_extra_tags && utils_.MaybeInAutonomous()) {
+    if (!absl::GetFlag(FLAGS_always_use_extra_tags) &&
+        utils_.MaybeInAutonomous()) {
       VLOG(1) << "Rejecting target due to auto invalid ID " << target_id;
       RejectImage(camera_index, RejectionReason::NO_SUCH_TARGET, debug_builder);
       return;
@@ -454,12 +453,13 @@
     VLOG(1) << "Rejecting image due to being too old.";
     return RejectImage(camera_index, RejectionReason::IMAGE_TOO_OLD,
                        debug_builder);
-  } else if (target.pose_error() > FLAGS_max_pose_error) {
+  } else if (target.pose_error() > absl::GetFlag(FLAGS_max_pose_error)) {
     VLOG(1) << "Rejecting target due to high pose error "
             << target.pose_error();
     return RejectImage(camera_index, RejectionReason::HIGH_POSE_ERROR,
                        debug_builder);
-  } else if (target.pose_error_ratio() > FLAGS_max_pose_error_ratio) {
+  } else if (target.pose_error_ratio() >
+             absl::GetFlag(FLAGS_max_pose_error_ratio)) {
     VLOG(1) << "Rejecting target due to high pose error ratio "
             << target.pose_error_ratio();
     return RejectImage(camera_index, RejectionReason::HIGH_POSE_ERROR_RATIO,
@@ -484,7 +484,8 @@
   noises(Corrector::kSkew) *= distance_noise_scalar;
   // TODO(james): This is leftover from last year; figure out if we want it.
   // Scale noise by the distortion factor for this detection
-  noises *= (1.0 + FLAGS_distortion_noise_scalar * target.distortion_factor());
+  noises *= (1.0 + absl::GetFlag(FLAGS_distortion_noise_scalar) *
+                       target.distortion_factor());
   noises *= april_tag_noise_scalar;
   noises *= (1.0 + std::abs(robot_speed));
 
@@ -522,22 +523,24 @@
                                 corrector.observed_camera_pose().abs_theta());
   constexpr double kDegToRad = M_PI / 180.0;
   const double yaw_threshold =
-      (utils_.MaybeInAutonomous() ? FLAGS_max_implied_yaw_error
-                                  : FLAGS_max_implied_teleop_yaw_error) *
+      (utils_.MaybeInAutonomous()
+           ? absl::GetFlag(FLAGS_max_implied_yaw_error)
+           : absl::GetFlag(FLAGS_max_implied_teleop_yaw_error)) *
       kDegToRad;
 
-  if (target.distortion_factor() > FLAGS_max_distortion) {
+  if (target.distortion_factor() > absl::GetFlag(FLAGS_max_distortion)) {
     VLOG(1) << "Rejecting target due to high distortion.";
     return RejectImage(camera_index, RejectionReason::HIGH_DISTORTION,
                        debug_builder);
   } else if (utils_.MaybeInAutonomous() &&
-             (std::abs(robot_speed) > FLAGS_max_auto_image_robot_speed)) {
+             (std::abs(robot_speed) >
+              absl::GetFlag(FLAGS_max_auto_image_robot_speed))) {
     return RejectImage(camera_index, RejectionReason::ROBOT_TOO_FAST,
                        debug_builder);
   } else if (std::abs(camera_yaw_error) > yaw_threshold) {
     return RejectImage(camera_index, RejectionReason::HIGH_IMPLIED_YAW_ERROR,
                        debug_builder);
-  } else if (distance_to_target > FLAGS_max_distance_to_target) {
+  } else if (distance_to_target > absl::GetFlag(FLAGS_max_distance_to_target)) {
     return RejectImage(camera_index, RejectionReason::HIGH_DISTANCE_TO_TARGET,
                        debug_builder);
   }
@@ -551,15 +554,15 @@
   // the camera measurement and the current estimate of the
   // pose. This doesn't affect any of the math, it just makes the code a bit
   // more convenient to write given the Correct() interface we already have.
-  if (FLAGS_do_xytheta_corrections) {
+  if (absl::GetFlag(FLAGS_do_xytheta_corrections)) {
     Eigen::Vector3d Z(measured_pose.rel_pos().x(), measured_pose.rel_pos().y(),
                       measured_pose.rel_theta());
     Eigen::Matrix<double, 3, 1> xyz_noises(0.2, 0.2, 0.5);
     xyz_noises *= distance_noise_scalar;
     xyz_noises *= april_tag_noise_scalar;
     // Scale noise by the distortion factor for this detection
-    xyz_noises *=
-        (1.0 + FLAGS_distortion_noise_scalar * target.distortion_factor());
+    xyz_noises *= (1.0 + absl::GetFlag(FLAGS_distortion_noise_scalar) *
+                             target.distortion_factor());
 
     Eigen::Matrix3d R_xyz = Eigen::Matrix3d::Zero();
     R_xyz.diagonal() = xyz_noises.cwiseAbs2();
diff --git a/y2024/localizer/localizer_main.cc b/y2024/localizer/localizer_main.cc
index 25466d2..1da4ac9 100644
--- a/y2024/localizer/localizer_main.cc
+++ b/y2024/localizer/localizer_main.cc
@@ -1,16 +1,19 @@
+#include "absl/flags/flag.h"
+
 #include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
 #include "frc971/constants/constants_sender_lib.h"
 #include "y2024/control_loops/drivetrain/drivetrain_base.h"
 #include "y2024/localizer/localizer.h"
 
-DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
+ABSL_FLAG(std::string, config, "aos_config.json",
+          "Path to the config file to use.");
 
 int main(int argc, char *argv[]) {
   aos::InitGoogle(&argc, &argv);
 
   aos::FlatbufferDetachedBuffer<aos::Configuration> config =
-      aos::configuration::ReadConfig(FLAGS_config);
+      aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config));
 
   frc971::constants::WaitForConstants<y2024::Constants>(&config.message());
 
diff --git a/y2024/localizer/localizer_replay.cc b/y2024/localizer/localizer_replay.cc
index ad0caae..52fd917 100644
--- a/y2024/localizer/localizer_replay.cc
+++ b/y2024/localizer/localizer_replay.cc
@@ -1,4 +1,4 @@
-#include "gflags/gflags.h"
+#include "absl/flags/flag.h"
 
 #include "aos/configuration.h"
 #include "aos/events/logging/log_reader.h"
@@ -14,31 +14,32 @@
 #include "y2024/control_loops/drivetrain/drivetrain_base.h"
 #include "y2024/localizer/localizer.h"
 
-DEFINE_string(config, "y2024/aos_config.json",
-              "Name of the config file to replay using.");
-DEFINE_bool(override_config, false,
-            "If set, override the logged config with --config.");
-DEFINE_int32(team, 971, "Team number to use for logfile replay.");
-DEFINE_string(output_folder, "/tmp/replayed",
-              "Name of the folder to write replayed logs to.");
-DEFINE_string(constants_path, "y2024/constants/constants.json",
-              "Path to the constant file");
+ABSL_FLAG(std::string, config, "y2024/aos_config.json",
+          "Name of the config file to replay using.");
+ABSL_FLAG(bool, override_config, false,
+          "If set, override the logged config with --config.");
+ABSL_FLAG(int32_t, team, 971, "Team number to use for logfile replay.");
+ABSL_FLAG(std::string, output_folder, "/tmp/replayed",
+          "Name of the folder to write replayed logs to.");
+ABSL_FLAG(std::string, constants_path, "y2024/constants/constants.json",
+          "Path to the constant file");
 
 int main(int argc, char **argv) {
   aos::InitGoogle(&argc, &argv);
 
-  aos::network::OverrideTeamNumber(FLAGS_team);
+  aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team));
 
   const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
-      aos::configuration::ReadConfig(FLAGS_config);
+      aos::configuration::ReadConfig(absl::GetFlag(FLAGS_config));
 
   // sort logfiles
   const std::vector<aos::logger::LogFile> logfiles =
       aos::logger::SortParts(aos::logger::FindLogs(argc, argv));
 
   // open logfiles
-  aos::logger::LogReader reader(
-      logfiles, FLAGS_override_config ? &config.message() : nullptr);
+  aos::logger::LogReader reader(logfiles, absl::GetFlag(FLAGS_override_config)
+                                              ? &config.message()
+                                              : nullptr);
 
   reader.RemapLoggedChannel("/localizer", "y2024.localizer.Status");
   for (const auto orin : {"orin1", "imu"}) {
@@ -59,8 +60,9 @@
 
   reader.RegisterWithoutStarting(factory.get());
 
-  y2024::SendSimulationConstants(reader.event_loop_factory(), FLAGS_team,
-                                 FLAGS_constants_path);
+  y2024::SendSimulationConstants(reader.event_loop_factory(),
+                                 absl::GetFlag(FLAGS_team),
+                                 absl::GetFlag(FLAGS_constants_path));
 
   const aos::Node *node = nullptr;
   if (aos::configuration::MultiNode(reader.configuration())) {
@@ -75,7 +77,7 @@
     node_factory->AlwaysStart<frc971::imu_fdcan::DualImuBlender>(
         "dual_imu_blender");
     loggers.push_back(std::make_unique<aos::util::LoggerState>(
-        factory.get(), node, FLAGS_output_folder));
+        factory.get(), node, absl::GetFlag(FLAGS_output_folder)));
   });
 
   reader.event_loop_factory()->Run();
diff --git a/y2024/localizer/localizer_test.cc b/y2024/localizer/localizer_test.cc
index e5815e0..d02807f 100644
--- a/y2024/localizer/localizer_test.cc
+++ b/y2024/localizer/localizer_test.cc
@@ -1,5 +1,8 @@
 #include "y2024/localizer/localizer.h"
 
+#include "absl/flags/declare.h"
+#include "absl/flags/flag.h"
+#include "absl/flags/reflection.h"
 #include "gtest/gtest.h"
 
 #include "aos/events/logging/log_writer.h"
@@ -14,9 +17,9 @@
 #include "y2024/control_loops/drivetrain/drivetrain_base.h"
 #include "y2024/localizer/status_generated.h"
 
-DEFINE_string(output_folder, "",
-              "If set, logs all channels to the provided logfile.");
-DECLARE_double(max_distance_to_target);
+ABSL_FLAG(std::string, output_folder, "",
+          "If set, logs all channels to the provided logfile.");
+ABSL_DECLARE_FLAG(double, max_distance_to_target);
 
 namespace y2024::localizer::testing {
 
@@ -76,7 +79,7 @@
                 ->MakeFetcher<frc971::controls::LocalizerOutput>("/localizer")),
         status_fetcher_(
             imu_test_event_loop_->MakeFetcher<Status>("/localizer")) {
-    FLAGS_max_distance_to_target = 100.0;
+    absl::SetFlag(&FLAGS_max_distance_to_target, 100.0);
     {
       aos::TimerHandler *timer = roborio_test_event_loop_->AddTimer([this]() {
         {
@@ -222,11 +225,11 @@
     CHECK(status_fetcher_.Fetch());
     CHECK(status_fetcher_->imu()->zeroed());
 
-    if (!FLAGS_output_folder.empty()) {
+    if (!absl::GetFlag(FLAGS_output_folder).empty()) {
       logger_event_loop_ =
           event_loop_factory_.MakeEventLoop("logger", imu_node_);
       logger_ = std::make_unique<aos::logger::Logger>(logger_event_loop_.get());
-      logger_->StartLoggingOnRun(FLAGS_output_folder);
+      logger_->StartLoggingOnRun(absl::GetFlag(FLAGS_output_folder));
     }
   }
 
@@ -313,7 +316,7 @@
   double pose_error_ratio_ = 0.1;
   double implied_yaw_error_ = 0.0;
 
-  gflags::FlagSaver flag_saver_;
+  absl::FlagSaver flag_saver_;
 };
 
 // Test a simple scenario with no errors where the robot should just drive