Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ dependencies {

def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
annotationProcessor "org.littletonrobotics.akit:akit-autolog:$akitJson.version"

annotationProcessor project('robotControlAnnotations')
}

test {
Expand Down
27 changes: 27 additions & 0 deletions robotControlAnnotations/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id 'java'
id "edu.wpi.first.GradleRIO" version "2025.3.2"
}

group = 'org.frc3767'
version = 'unspecified'

repositories {
mavenCentral()
}

dependencies {
implementation 'edu.wpi.first.wpiutil:wpiutil-java:2025.3.2'
implementation 'edu.wpi.first.wpilibj:wpilibj-java:2025.3.2'
implementation 'edu.wpi.first.wpilibNewCommands:wpilibNewCommands-java:2025.3.2'
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'com.squareup:javapoet:1.13.0'
implementation('com.google.auto.service:auto-service:1.1.1')
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
StateAnnotationHandler
TransitionAnnotationHandler
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions robotControlAnnotations/build/tmp/jar/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

82 changes: 82 additions & 0 deletions robotControlAnnotations/src/main/java/StateAnnotationHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import edu.wpi.first.wpilibj2.command.Command;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.tools.Diagnostic;
import java.io.IOException;
import java.util.Optional;
import java.util.Set;

public class StateAnnotationHandler extends AbstractProcessor {
private static String getPackageName(Element e) {
while (e != null) {
if (e.getKind().equals(ElementKind.PACKAGE)) {
return ((PackageElement) e).getQualifiedName().toString();
}
e = e.getEnclosingElement();
}

return null;
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Optional<? extends TypeElement> annotationOptional =
annotations.stream()
.filter((te) -> te.getSimpleName().toString().equals("State"))
.findFirst();

if (!annotationOptional.isPresent()) {
return false;
}

TypeSpec.Builder stateClass = TypeSpec.classBuilder("RobotStates").addModifiers(Modifier.PUBLIC);
MethodSpec.Builder stateInitializer = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);

TypeElement annotation = annotationOptional.get();
roundEnv.getElementsAnnotatedWith(annotation)
.forEach(
(element) -> {
String robotModeName = element.getSimpleName().toString();
String robotModePackage = getPackageName(element);

processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Found state: " + robotModeName + " in package " + robotModePackage);

FieldSpec stateCommand = FieldSpec.builder(Command.class, Character.toLowerCase(robotModeName.charAt(0)) + robotModeName.substring(1), Modifier.PUBLIC, Modifier.STATIC).build();
stateInitializer.addStatement("RobotStates.$N = new $T()", stateCommand, element.asType());

stateClass.addField(stateCommand);
}
);

stateClass.addMethod(stateInitializer.build());

JavaFile fileBuilder = JavaFile.builder("frc.robot.utils", stateClass.build()).build();

try {
fileBuilder.writeTo(processingEnv.getFiler());
} catch (IOException e) {
throw new RuntimeException(e);
}

return true;
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}

@Override
public Set<String> getSupportedAnnotationTypes() {
return Set.of("frc.robot.utils.State");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import edu.wpi.first.wpilibj2.command.Command;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.tools.Diagnostic;
import java.io.IOException;
import java.util.Optional;
import java.util.Set;

public class TransitionAnnotationHandler extends AbstractProcessor {
private static String getPackageName(Element e) {
while (e != null) {
if (e.getKind().equals(ElementKind.PACKAGE)) {
return ((PackageElement) e).getQualifiedName().toString();
}
e = e.getEnclosingElement();
}

return null;
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Optional<? extends TypeElement> annotationOptional =
annotations.stream()
.filter((te) -> te.getSimpleName().toString().equals("Transition"))
.findFirst();

if (!annotationOptional.isPresent()) {
return false;
}

TypeSpec.Builder stateClass = TypeSpec.classBuilder("RobotTransitions").addModifiers(Modifier.PUBLIC);
MethodSpec.Builder stateInitializer = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);

TypeElement annotation = annotationOptional.get();
roundEnv.getElementsAnnotatedWith(annotation)
.forEach(
(element) -> {
String robotModeName = element.getSimpleName().toString();
String robotModePackage = getPackageName(element);

processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Found transition: " + robotModeName + " in package " + robotModePackage);

FieldSpec stateCommand = FieldSpec.builder(Command.class, Character.toLowerCase(robotModeName.charAt(0)) + robotModeName.substring(1), Modifier.PUBLIC, Modifier.STATIC).build();
stateInitializer.addStatement("RobotTransitions.$N = new $T()", stateCommand, element.asType());

stateClass.addField(stateCommand);
}
);

stateClass.addMethod(stateInitializer.build());

JavaFile fileBuilder = JavaFile.builder("frc.robot.utils", stateClass.build()).build();

try {
fileBuilder.writeTo(processingEnv.getFiler());
} catch (IOException e) {
throw new RuntimeException(e);
}

return true;
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}

@Override
public Set<String> getSupportedAnnotationTypes() {
return Set.of("frc.robot.utils.Transition");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
StateAnnotationHandler
TransitionAnnotationHandler
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ pluginManagement {

Properties props = System.getProperties();
props.setProperty("org.gradle.internal.native.headers.unresolved.dependencies.ignore", "true");
include 'robotControlAnnotations'
45 changes: 24 additions & 21 deletions src/main/java/frc/robot/Autos.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import frc.robot.commands.AutonCommands.CoralReefAlignPoseAuton;
import frc.robot.commands.AutonCommands.CoralReefPoseAuton;
import frc.robot.subsystems.robotControl.RobotControl;
import frc.robot.subsystems.robotControl.RobotControlIOInputsAutoLogged;
import frc.robot.utils.RobotStates;
import frc.robot.utils.RobotTransitions;
import frc.robot.utils.Utils.ReefPosition;

public class Autos {
Expand Down Expand Up @@ -60,16 +63,16 @@ public static Command J4_L4_A4_B4_Lolipops() {
CoralReefAlignPoseAuton alignWithB2 = new CoralReefAlignPoseAuton(ReefPosition.B, "2", false);

return new SequentialCommandGroup(
new InstantCommand(() -> {Robot.drivetrain.setPose(Robot.getAlliance() == Alliance.Blue ? leftWall_A.getStartingHolonomicPose().get() : flipped_LeftWall_AB.getStartingHolonomicPose().get()); RobotControl.setCurrentMode(RobotControl.transitPose);}),
new InstantCommand(() -> {Robot.drivetrain.setPose(Robot.getAlliance() == Alliance.Blue ? leftWall_A.getStartingHolonomicPose().get() : flipped_LeftWall_AB.getStartingHolonomicPose().get()); RobotControl.setCurrentMode(RobotTransitions.transitPose);}),
new InstantCommand(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(leftWall_A));}),
new WaitUntilCommand(RobotControl::isDriveCommandFinished).finallyDo(() -> RobotControl.setCurrentMode(alignWithA4)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(A_LeftLolipop))),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(leftLolipop_B));}),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(A_LeftLolipop))),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(leftLolipop_B));}),
new WaitUntilCommand(RobotControl::isDriveCommandFinished).finallyDo(() -> RobotControl.setCurrentMode(alignWithB4)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(B_MiddleLolipop))),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> RobotControl.setCurrentMode(alignWithA2)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(A_RightLolipop))),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(RightLolipop_B))),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(B_MiddleLolipop))),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> RobotControl.setCurrentMode(alignWithA2)),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(A_RightLolipop))),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> RobotControl.setDriveModeCommand(AutoBuilder.followPath(RightLolipop_B))),
new WaitUntilCommand(RobotControl::isDriveCommandFinished).finallyDo(() -> RobotControl.setCurrentMode(alignWithB2))
);

Expand Down Expand Up @@ -97,14 +100,14 @@ public static Command J4_K4_L4_CoralStation() {
CoralReefPoseAuton L4Pose = new CoralReefPoseAuton("4");

return new SequentialCommandGroup(
new InstantCommand(() -> {Robot.drivetrain.setPose(Robot.getAlliance() == Alliance.Blue ? rightReefStart_J.getStartingHolonomicPose().get() : flippedRightReefStart_J.getStartingHolonomicPose().get()); RobotControl.setCurrentMode(RobotControl.transitPose);}),
new InstantCommand(() -> {Robot.drivetrain.setPose(Robot.getAlliance() == Alliance.Blue ? rightReefStart_J.getStartingHolonomicPose().get() : flippedRightReefStart_J.getStartingHolonomicPose().get()); RobotControl.setCurrentMode(RobotTransitions.transitPose);}),
new InstantCommand(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(rightReefStart_J));}),
new WaitUntilCommand(RobotControl::isDriveCommandFinished).finallyDo(() -> RobotControl.setCurrentMode(alignWithJ4)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotControl.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(J_CoralStation));}),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_K));}),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotTransitions.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(J_CoralStation));}),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_K));}),
new WaitUntilCommand(() -> RobotControl.isDriveCommandFinished()).finallyDo(() -> RobotControl.setCurrentMode(alignWithK4)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotControl.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(K_CoralStation));}),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_L));}),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotTransitions.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(K_CoralStation));}),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_L));}),
new WaitUntilCommand(() -> RobotControl.isDriveCommandFinished()).finallyDo(() -> RobotControl.setCurrentMode(alignWithL4))
);
} catch (Exception e) {
Expand All @@ -131,14 +134,14 @@ public static Command E4_C4_D4_CoralStation() {
CoralReefPoseAuton L4Pose = new CoralReefPoseAuton("4");

return new SequentialCommandGroup(
new InstantCommand(() -> {Robot.drivetrain.setPose(Robot.getAlliance() == Alliance.Blue ? rightReefStart_E.getStartingHolonomicPose().get() : flippedRightReefStart_E.getStartingHolonomicPose().get()); RobotControl.setCurrentMode(RobotControl.transitPose);}),
new InstantCommand(() -> {Robot.drivetrain.setPose(Robot.getAlliance() == Alliance.Blue ? rightReefStart_E.getStartingHolonomicPose().get() : flippedRightReefStart_E.getStartingHolonomicPose().get()); RobotControl.setCurrentMode(RobotTransitions.transitPose);}),
new InstantCommand(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(rightReefStart_E));}),
new WaitUntilCommand(() -> RobotControl.isDriveCommandFinished()).finallyDo(() -> RobotControl.setCurrentMode(alignWithE4)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotControl.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(E_CoralStation));}),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_C));}),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotTransitions.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(E_CoralStation));}),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_C));}),
new WaitUntilCommand(() -> RobotControl.isDriveCommandFinished()).finallyDo(() -> RobotControl.setCurrentMode(alignWithC4)),
new WaitUntilCommand(() -> RobotControl.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotControl.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(C_CoralStation));}),
new WaitUntilCommand(() -> RobotControl.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_D));}),
new WaitUntilCommand(() -> RobotTransitions.coralFloorPose.isScheduled()).finallyDo(() -> {RobotControl.setCurrentMode(RobotTransitions.coralStationPose); RobotControl.setDriveModeCommand(AutoBuilder.followPath(C_CoralStation));}),
new WaitUntilCommand(() -> RobotTransitions.transitPose.isScheduled()).finallyDo(() -> {RobotControl.setDriveModeCommand(AutoBuilder.followPath(CoralStation_D));}),
new WaitUntilCommand(() -> RobotControl.isDriveCommandFinished()).finallyDo(() -> RobotControl.setCurrentMode(alignWithD4))
);
} catch (Exception e) {
Expand All @@ -151,8 +154,8 @@ public static Command centerAutoH() {
CoralReefAlignPoseAuton alignWithH4 = new CoralReefAlignPoseAuton(ReefPosition.H, "4", false);

return new SequentialCommandGroup(
new InstantCommand(() -> RobotControl.setCurrentMode(RobotControl.transitPose)),
new WaitUntilCommand(() -> RobotControl.transit.isScheduled()),
new InstantCommand(() -> RobotControl.setCurrentMode(RobotTransitions.transitPose)),
new WaitUntilCommand(() -> RobotStates.transit.isScheduled()),
new InstantCommand(() -> RobotControl.setCurrentMode(alignWithH4))
);
}
Expand All @@ -162,8 +165,8 @@ public static Command centerAutoG() {
CoralReefAlignPoseAuton alignWithG4 = new CoralReefAlignPoseAuton(ReefPosition.G, "4", true);

return new SequentialCommandGroup(
new InstantCommand(() -> RobotControl.setCurrentMode(RobotControl.transitPose)),
new WaitUntilCommand(() -> RobotControl.transit.isScheduled()),
new InstantCommand(() -> RobotControl.setCurrentMode(RobotTransitions.transitPose)),
new WaitUntilCommand(() -> RobotStates.transit.isScheduled()),
new InstantCommand(() -> RobotControl.setCurrentMode(alignWithG4))
);
}
Expand Down
Loading