Add y2024 intake constants

Signed-off-by: Niko Sohmers <nikolai@sohmers.com>
Change-Id: I41914cb76b7d3f79b7d9a0f0f2bab1632fa583be
diff --git a/y2024/constants/7971.json b/y2024/constants/7971.json
index 0062fa8..62d4b32 100644
--- a/y2024/constants/7971.json
+++ b/y2024/constants/7971.json
@@ -1,5 +1,12 @@
 {
   "robot": {
+    "intake_constants": {
+      "intake_pivot_zero": {
+        "measured_absolute_position": 0.0,
+        {% include 'y2024/constants/intake_pivot_common_zeroing.json' %}
+      },
+      "potentiometer_offset": 0.0
+    }
   },
   {% include 'y2024/constants/common.json' %}
 }
diff --git a/y2024/constants/971.json b/y2024/constants/971.json
index 0062fa8..62d4b32 100644
--- a/y2024/constants/971.json
+++ b/y2024/constants/971.json
@@ -1,5 +1,12 @@
 {
   "robot": {
+    "intake_constants": {
+      "intake_pivot_zero": {
+        "measured_absolute_position": 0.0,
+        {% include 'y2024/constants/intake_pivot_common_zeroing.json' %}
+      },
+      "potentiometer_offset": 0.0
+    }
   },
   {% include 'y2024/constants/common.json' %}
 }
diff --git a/y2024/constants/9971.json b/y2024/constants/9971.json
index 0062fa8..62d4b32 100644
--- a/y2024/constants/9971.json
+++ b/y2024/constants/9971.json
@@ -1,5 +1,12 @@
 {
   "robot": {
+    "intake_constants": {
+      "intake_pivot_zero": {
+        "measured_absolute_position": 0.0,
+        {% include 'y2024/constants/intake_pivot_common_zeroing.json' %}
+      },
+      "potentiometer_offset": 0.0
+    }
   },
   {% include 'y2024/constants/common.json' %}
 }
diff --git a/y2024/constants/BUILD b/y2024/constants/BUILD
index af01182..adebcf9 100644
--- a/y2024/constants/BUILD
+++ b/y2024/constants/BUILD
@@ -1,4 +1,5 @@
 load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
+load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary")
 load("//tools/build_rules:template.bzl", "jinja2_template")
 
 cc_library(
@@ -19,7 +20,14 @@
 jinja2_template(
     name = "test_constants.json",
     src = "test_constants.jinja2.json",
-    includes = glob(["test_data/*.json"]),
+    includes = glob([
+        "test_data/*.json",
+    ]) + [
+        ":intake_pivot_common_zeroing.json",
+        "//y2024/control_loops/superstructure/intake_pivot:intake_pivot_json",
+        "common.json",
+        "//y2024/vision/maps",
+    ],
     parameters = {},
     visibility = ["//visibility:public"],
 )
@@ -32,6 +40,8 @@
         "971.json",
         "9971.json",
         "common.json",
+        ":intake_pivot_common_zeroing.json",
+        "//y2024/control_loops/superstructure/intake_pivot:intake_pivot_json",
         "//y2024/vision/maps",
     ],
     parameters = {},
@@ -43,7 +53,9 @@
     srcs = ["constants.fbs"],
     visibility = ["//visibility:public"],
     deps = [
+        "//frc971/control_loops:profiled_subsystem_fbs",
         "//frc971/vision:target_map_fbs",
+        "//frc971/zeroing:constants_fbs",
     ],
 )
 
@@ -80,3 +92,19 @@
         "@com_github_google_glog//:glog",
     ],
 )
+
+cc_binary(
+    name = "intake_pivot_json_codegen",
+    srcs = ["intake_pivot_json_codegen.cc"],
+    deps = [
+        "//aos/util:file",
+        "//y2024:constants",
+    ],
+)
+
+run_binary(
+    name = "intake_pivot_codegen",
+    outs = ["intake_pivot_common_zeroing.json"],
+    args = ["$(location :intake_pivot_common_zeroing.json)"],
+    tool = ":intake_pivot_json_codegen",
+)
diff --git a/y2024/constants/common.json b/y2024/constants/common.json
index 279ec04..701ddd1 100644
--- a/y2024/constants/common.json
+++ b/y2024/constants/common.json
@@ -1,4 +1,6 @@
-"shooter_interpolation_table": [
+"common": {
+  "target_map": {% include 'y2024/vision/maps/target_map.json' %},
+  "shooter_interpolation_table": [
     {
         "distance_from_goal": 0.0,
         "shot_params": {
@@ -6,5 +8,34 @@
             "shot_angle": 0.0
         }
     }
-],
-"target_map": {% include 'y2024/vision/maps/target_map.json' %}
+  ],
+  "intake_roller_voltages": {
+    "spitting": -12.0,
+    "intaking": 12.0
+  },
+  "intake_pivot_set_points": {
+    "extended": 0.0,
+    "retracted": 0.0
+  },
+  "intake_pivot": {
+    "zeroing_voltage": 3.0,
+    "operating_voltage": 12.0,
+    "zeroing_profile_params": {
+      "max_velocity": 0.5,
+      "max_acceleration": 3.0
+    },
+    "default_profile_params":{
+      "max_velocity": 6.0,
+      "max_acceleration": 30.0
+    },
+    "range": {
+        "lower_hard": -0.85,
+        "upper_hard": 1.85,
+        "lower": -0.400,
+        "upper": 1.57
+    },
+    "loop": {% include 'y2024/control_loops/superstructure/intake_pivot/integral_intake_pivot_plant.json' %}
+  }
+}
+
+
diff --git a/y2024/constants/constants.fbs b/y2024/constants/constants.fbs
index 490bc99..52a54bb 100644
--- a/y2024/constants/constants.fbs
+++ b/y2024/constants/constants.fbs
@@ -1,4 +1,6 @@
 include "frc971/vision/target_map.fbs";
+include "frc971/control_loops/profiled_subsystem.fbs";
+include "frc971/zeroing/constants.fbs";
 
 namespace y2024;
 
@@ -12,14 +14,44 @@
     shot_params: ShotParams (id: 1);
 }
 
-table RobotConstants {
+// Amount of voltage to give to the intake rollers when:
+// spitting, which represents voltage when IntakeRollerGoal is SPITTING 
+// and intaking, which represents voltage when IntakeRollerGoal is INTAKING
+table IntakeRollerVoltages {
+  spitting:double (id: 0);
+  intaking:double (id: 1);
+}
 
+// Set points for the pivot in radians when:
+// extended, which represents radians for when IntakePivotGoal is EXTENDED
+// and retracted, which represents radians for when IntakePivotGoal is RETRACTED or NONE
+table IntakePivotSetPoints {
+  extended:double (id: 0);
+  retracted:double (id: 1);
+}
+
+// Intake Constants
+table IntakeConstants {
+  intake_pivot_zero:frc971.zeroing.PotAndAbsoluteEncoderZeroingConstants (id: 0);
+  potentiometer_offset:double (id: 1);
+}
+
+table RobotConstants {
+  intake_constants:IntakeConstants (id: 0);
+}
+
+// Common table for constants unrelated to the robot
+table Common {
+  target_map:frc971.vision.TargetMap (id: 0);
+  shooter_interpolation_table: [InterpolationTablePoint] (id: 1);
+  intake_roller_voltages:IntakeRollerVoltages (id : 2);
+  intake_pivot_set_points:IntakePivotSetPoints (id: 3);
+  intake_pivot:frc971.control_loops.StaticZeroingSingleDOFProfiledSubsystemCommonParams (id: 4);
 }
 
 table Constants {
-  target_map:frc971.vision.TargetMap (id: 0);
-  robot:RobotConstants (id: 1);
-  shooter_interpolation_table: [InterpolationTablePoint] (id: 2);
+  robot:RobotConstants (id: 0);
+  common:Common (id: 1);
 }
 
-root_type Constants;
+root_type Constants;
\ No newline at end of file
diff --git a/y2024/constants/intake_pivot_json_codegen.cc b/y2024/constants/intake_pivot_json_codegen.cc
new file mode 100644
index 0000000..9a0b6dd
--- /dev/null
+++ b/y2024/constants/intake_pivot_json_codegen.cc
@@ -0,0 +1,24 @@
+#include "aos/util/file.h"
+#include "y2024/constants.h"
+
+using namespace y2024::constants;
+
+// This file generates some JSON constants information for the intake that are
+// currently dependent on values that are located in C++ headers and would be
+// obnoxious/inappropriate to pull out. In the future the file may be used to
+// generate constants information for other subsystems as well
+int main(int argc, char *argv[]) {
+  CHECK_EQ(argc, 2) << "Must supply file name to output to.";
+  std::string output_file = argv[1];
+
+  std::stringstream output;
+
+  output << "\"average_filter_size\": " << Values::kZeroingSampleSize << ",\n";
+  output << "\"one_revolution_distance\": "
+         << M_PI * 2.0 * Values::kIntakePivotEncoderRatio() << ",\n";
+  output << "\"zeroing_threshold\": 0.0005,\n";
+  output << "\"moving_buffer_size\": 20,\n";
+  output << "\"allowable_encoder_error\": 0.9\n";
+  aos::util::WriteStringToFileOrDie(output_file, output.str());
+  return 0;
+}
\ No newline at end of file
diff --git a/y2024/constants/test_constants.jinja2.json b/y2024/constants/test_constants.jinja2.json
index c6b77dd..aa5c553 100644
--- a/y2024/constants/test_constants.jinja2.json
+++ b/y2024/constants/test_constants.jinja2.json
@@ -2,7 +2,7 @@
   "constants": [
     {
       "team": 7971,
-      "data": {}
+      "data": {% include 'y2024/constants/test_data/test_team.json' %}
     }
   ]
 }
diff --git a/y2024/constants/test_data/test_team.json b/y2024/constants/test_data/test_team.json
new file mode 100644
index 0000000..bb30395
--- /dev/null
+++ b/y2024/constants/test_data/test_team.json
@@ -0,0 +1,12 @@
+{
+	"robot": {
+		"intake_constants": {
+			"intake_pivot_zero": {
+				"measured_absolute_position": 0.0,
+				{% include 'y2024/constants/intake_pivot_common_zeroing.json' %}
+			},
+			"potentiometer_offset": 0.0
+		}
+	},
+	{% include 'y2024/constants/common.json' %}
+}
\ No newline at end of file