]> git.taranathan.com Git - subsystem-generator.git/commitdiff
templates woops main
authormoo <moogoesmeow123@gmail.com>
Sun, 10 May 2026 21:35:54 +0000 (14:35 -0700)
committermoo <moogoesmeow123@gmail.com>
Sun, 10 May 2026 21:35:54 +0000 (14:35 -0700)
templates/constants.java.askama [new file with mode: 0644]
templates/io_impl.java.askama [new file with mode: 0644]
templates/io_interface.java.askama [new file with mode: 0644]
templates/subsystem.java.askama [new file with mode: 0644]

diff --git a/templates/constants.java.askama b/templates/constants.java.askama
new file mode 100644 (file)
index 0000000..9e7b882
--- /dev/null
@@ -0,0 +1,6 @@
+package {{ package }};
+
+public class {{ constants_class }} {
+
+{% for motor in motors %}  public static final int {{ motor.constant_base }}_MOTOR_ID = {{ motor.can_id }};
+{% endfor %}}
diff --git a/templates/io_impl.java.askama b/templates/io_impl.java.askama
new file mode 100644 (file)
index 0000000..e5344fc
--- /dev/null
@@ -0,0 +1,44 @@
+package {{ package }};
+
+import com.ctre.phoenix6.configs.MotorOutputConfigs;
+import com.ctre.phoenix6.configs.TalonFXConfiguration;
+import com.ctre.phoenix6.controls.ControlRequest;
+import com.ctre.phoenix6.hardware.TalonFX;
+import com.ctre.phoenix6.signals.InvertedValue;
+import com.ctre.phoenix6.signals.NeutralModeValue;
+import frc.robot.constants.Constants;
+
+public class {{ io_impl }} implements {{ io_interface }} {
+{% for motor in motors %}  private final TalonFX {{ motor.field_base }}Motor = new TalonFX({{ constants_class }}.{{ motor.constant_base }}_MOTOR_ID, Constants.CANIVORE_SUB);
+{% endfor %}
+  public {{ io_impl }}() {
+    TalonFXConfiguration config = new TalonFXConfiguration();
+    // TODO: tune PID, current limits, and motion magic limits
+{% for motor in motors %}    {{ motor.field_base }}Motor.getConfigurator().apply(config);
+    {{ motor.field_base }}Motor.getConfigurator().apply(new MotorOutputConfigs().withInverted({{ motor.inverted_value }}).withNeutralMode({{ neutral_mode_value }}));
+{% endfor %}  }
+
+  @Override
+  public void updateInputs({{ io_inputs }} inputs) {
+{% for motor in motors %}    inputs.{{ motor.field_base }}PositionRot = {{ motor.field_base }}Motor.getPosition().getValueAsDouble();
+    inputs.{{ motor.field_base }}VelocityRps = {{ motor.field_base }}Motor.getVelocity().getValueAsDouble();
+    inputs.{{ motor.field_base }}StatorCurrentAmps = {{ motor.field_base }}Motor.getStatorCurrent().getValueAsDouble();
+    inputs.{{ motor.field_base }}SupplyCurrentAmps = {{ motor.field_base }}Motor.getSupplyCurrent().getValueAsDouble();
+    inputs.{{ motor.field_base }}AppliedVolts = {{ motor.field_base }}Motor.getMotorVoltage().getValueAsDouble();
+{% endfor %}  }
+
+{% for motor in motors %}  @Override
+  public void set{{ motor.method_suffix }}SpeedRaw(double speed) {
+    {{ motor.field_base }}Motor.set(speed);
+  }
+
+  @Override
+  public void set{{ motor.method_suffix }}Control(ControlRequest request) {
+    {{ motor.field_base }}Motor.setControl(request);
+  }
+
+{% endfor %}  @Override
+  public void close() {
+{% for motor in motors %}    {{ motor.field_base }}Motor.close();
+{% endfor %}  }
+}
diff --git a/templates/io_interface.java.askama b/templates/io_interface.java.askama
new file mode 100644 (file)
index 0000000..05cbda9
--- /dev/null
@@ -0,0 +1,27 @@
+package {{ package }};
+
+import org.littletonrobotics.junction.AutoLog;
+import com.ctre.phoenix6.controls.ControlRequest;
+
+public interface {{ io_interface }} {
+  @AutoLog
+  public static class {{ io_inputs }} {
+{% for motor in motors %}    public double {{ motor.field_base }}PositionRot = 0.0;
+    public double {{ motor.field_base }}VelocityRps = 0.0;
+    public double {{ motor.field_base }}StatorCurrentAmps = 0.0;
+    public double {{ motor.field_base }}SupplyCurrentAmps = 0.0;
+    public double {{ motor.field_base }}AppliedVolts = 0.0;
+{% endfor %}  }
+
+  public void updateInputs({{ io_inputs }} inputs);
+
+{% for motor in motors %}  public void set{{ motor.method_suffix }}SpeedRaw(double speed);
+
+  public void set{{ motor.method_suffix }}Control(ControlRequest request);
+
+{% endfor %}  public default void stop() {
+{% for motor in motors %}    set{{ motor.method_suffix }}SpeedRaw(0.0);
+{% endfor %}  }
+
+  public default void close() {}
+}
diff --git a/templates/subsystem.java.askama b/templates/subsystem.java.askama
new file mode 100644 (file)
index 0000000..0666b4d
--- /dev/null
@@ -0,0 +1,36 @@
+package {{ package }};
+
+import org.littletonrobotics.junction.Logger;
+
+import edu.wpi.first.wpilibj2.command.SubsystemBase;
+
+public class {{ subsystem }} extends SubsystemBase {
+  private final {{ io_interface }} io;
+  private final {{ io_inputs_auto }} inputs = new {{ io_inputs_auto }}();
+
+  public {{ subsystem }}({{ io_interface }} io) {
+    this.io = io;
+  }
+
+  @Override
+  public void periodic() {
+    io.updateInputs(inputs);
+    Logger.processInputs("{{ subsystem }}", inputs);
+  }
+
+{% for motor in motors %}  public void set{{ motor.method_suffix }}SpeedRaw(double speed) {
+    io.set{{ motor.method_suffix }}SpeedRaw(speed);
+  }
+
+  public void set{{ motor.method_suffix }}Control(ControlRequest request) {
+    io.set{{ motor.method_suffix }}Control(request);
+  }
+
+{% endfor %}  public void stop() {
+    io.stop();
+  }
+
+  public void close() {
+    io.close();
+  }
+}