Merge "Make the rootfs build script for rockpi work first try"
diff --git a/frc971/imu_reader/BUILD b/frc971/imu_reader/BUILD
new file mode 100644
index 0000000..7d424c4
--- /dev/null
+++ b/frc971/imu_reader/BUILD
@@ -0,0 +1,21 @@
+cc_library(
+    name = "imu",
+    srcs = [
+        "imu.cc",
+    ],
+    hdrs = [
+        "imu.h",
+    ],
+    target_compatible_with = ["@platforms//os:linux"],
+    visibility = ["//visibility:public"],
+    deps = [
+        "//aos/events:epoll",
+        "//aos/events:shm_event_loop",
+        "//aos/util:crc32",
+        "//frc971/wpilib:imu_batch_fbs",
+        "//frc971/wpilib:imu_fbs",
+        "//y2022:constants",
+        "@com_github_google_glog//:glog",
+        "@com_google_absl//absl/types:span",
+    ],
+)
diff --git a/y2022/localizer/imu.cc b/frc971/imu_reader/imu.cc
similarity index 90%
rename from y2022/localizer/imu.cc
rename to frc971/imu_reader/imu.cc
index 2310e99..b477e4c 100644
--- a/y2022/localizer/imu.cc
+++ b/frc971/imu_reader/imu.cc
@@ -1,10 +1,9 @@
-#include "y2022/localizer/imu.h"
+#include "frc971/imu_reader/imu.h"
 
 #include "aos/util/crc32.h"
 #include "glog/logging.h"
-#include "y2022/constants.h"
 
-namespace y2022::localizer {
+namespace frc971::imu {
 
 namespace {
 
@@ -15,13 +14,11 @@
 
 }  // namespace
 
-Imu::Imu(aos::ShmEventLoop *event_loop)
+Imu::Imu(aos::ShmEventLoop *event_loop, double encoder_scalar)
     : event_loop_(event_loop),
       imu_sender_(
-          event_loop_->MakeSender<frc971::IMUValuesBatch>("/localizer")) {
-  event_loop->SetRuntimeRealtimePriority(30);
-  PCHECK(system("sudo chmod 644 /dev/adis16505") == 0)
-      << ": Failed to set read permissions on IMU device.";
+          event_loop_->MakeSender<frc971::IMUValuesBatch>("/localizer")),
+      encoder_scalar_(encoder_scalar) {
   imu_fd_ = open("/dev/adis16505", O_RDONLY | O_NONBLOCK);
   PCHECK(imu_fd_ != -1) << ": Failed to open SPI device for IMU.";
   aos::internal::EPoll *epoll = event_loop_->epoll();
@@ -123,10 +120,8 @@
 
     // extra data from the pico
     imu_builder.add_pico_timestamp_us(pico_timestamp);
-    imu_builder.add_left_encoder(
-        -constants::Values::DrivetrainEncoderToMeters(encoder2_count));
-    imu_builder.add_right_encoder(
-        constants::Values::DrivetrainEncoderToMeters(encoder1_count));
+    imu_builder.add_left_encoder(-encoder_scalar_ * encoder2_count);
+    imu_builder.add_right_encoder(encoder_scalar_ * encoder1_count);
     imu_builder.add_previous_reading_diag_stat(diag_stat_offset);
   }
 
@@ -167,4 +162,5 @@
 }
 
 Imu::~Imu() { PCHECK(0 == close(imu_fd_)); }
-}  // namespace y2022::localizer
+
+}  // namespace frc971::imu
diff --git a/y2022/localizer/imu.h b/frc971/imu_reader/imu.h
similarity index 71%
rename from y2022/localizer/imu.h
rename to frc971/imu_reader/imu.h
index cd45710..e3285d0 100644
--- a/y2022/localizer/imu.h
+++ b/frc971/imu_reader/imu.h
@@ -1,16 +1,17 @@
-#ifndef Y2022_LOCALIZER_IMU_H_
-#define Y2022_LOCALIZER_IMU_H_
+#ifndef FRC971_IMU_READER_IMU_H_
+#define FRC971_IMU_READER_IMU_H_
+
 #include "aos/events/shm_event_loop.h"
 #include "frc971/wpilib/imu_batch_generated.h"
-#include "y2022/constants.h"
 
-namespace y2022::localizer {
+namespace frc971::imu {
 
 // Reads IMU packets from the kernel driver which reads them over spi
 // from the Raspberry Pi Pico on the IMU board.
 class Imu {
  public:
-  Imu(aos::ShmEventLoop *event_loop);
+  // Constructs an IMU reader object.  encoder_scalar is in meters/count.
+  Imu(aos::ShmEventLoop *event_loop, double encoder_scalar);
   ~Imu();
 
  private:
@@ -26,6 +27,10 @@
   int imu_fd_;
 
   uint failed_checksums_ = 0;
+
+  double encoder_scalar_;
 };
-}  // namespace y2022::localizer
-#endif  // Y2022_LOCALIZER_IMU_H_
+
+}  // namespace frc971::imu
+
+#endif  // FRC971_IMU_READER_IMU_H_
diff --git a/frc971/rockpi/build_rootfs.sh b/frc971/rockpi/build_rootfs.sh
index fcfe1d3..4bffe67 100755
--- a/frc971/rockpi/build_rootfs.sh
+++ b/frc971/rockpi/build_rootfs.sh
@@ -18,6 +18,7 @@
     gcc-aarch64-linux-gnu
     device-tree-compiler
     swig
+    debootstrap
 )
 for dep in "${REQUIRED_DEPS[@]}"; do
     if ! dpkg-query -W -f='${Status}' "${dep}" | grep -q "install ok installed"; then
diff --git a/y2022/localizer/BUILD b/y2022/localizer/BUILD
index ec717fc..2a0a9fe 100644
--- a/y2022/localizer/BUILD
+++ b/y2022/localizer/BUILD
@@ -168,35 +168,15 @@
     ],
 )
 
-cc_library(
-    name = "imu",
-    srcs = [
-        "imu.cc",
-    ],
-    hdrs = [
-        "imu.h",
-    ],
-    target_compatible_with = ["@platforms//os:linux"],
-    deps = [
-        "//aos/events:epoll",
-        "//aos/events:shm_event_loop",
-        "//aos/util:crc32",
-        "//frc971/wpilib:imu_batch_fbs",
-        "//frc971/wpilib:imu_fbs",
-        "//y2022:constants",
-        "@com_github_google_glog//:glog",
-        "@com_google_absl//absl/types:span",
-    ],
-)
-
 cc_binary(
     name = "imu_main",
     srcs = ["imu_main.cc"],
     target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
     deps = [
-        ":imu",
         "//aos:init",
         "//aos/events:shm_event_loop",
+        "//frc971/imu_reader:imu",
+        "//y2022:constants",
     ],
 )
diff --git a/y2022/localizer/imu_main.cc b/y2022/localizer/imu_main.cc
index 5bdab41..03dfc58 100644
--- a/y2022/localizer/imu_main.cc
+++ b/y2022/localizer/imu_main.cc
@@ -1,6 +1,8 @@
 #include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
-#include "y2022/localizer/imu.h"
+#include "aos/realtime.h"
+#include "frc971/imu_reader/imu.h"
+#include "y2022/constants.h"
 
 DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
 
@@ -10,8 +12,14 @@
   aos::FlatbufferDetachedBuffer<aos::Configuration> config =
       aos::configuration::ReadConfig(FLAGS_config);
 
+  PCHECK(system("sudo chmod 644 /dev/adis16505") == 0)
+      << ": Failed to set read permissions on IMU device.";
+
   aos::ShmEventLoop event_loop(&config.message());
-  y2022::localizer::Imu imu(&event_loop);
+  frc971::imu::Imu imu(&event_loop,
+                       y2022::constants::Values::DrivetrainEncoderToMeters(1));
+
+  event_loop.SetRuntimeRealtimePriority(30);
 
   event_loop.Run();