FRC 3767 TC Titans
This is a state machine-based robot code template for FRC (FIRST Robotics Competition) that combines WPILib's Command-Based framework with AdvantageKit logging and a custom annotation-driven state management system. The template features a swerve drive robot with an organized state machine architecture for controlling robot behaviors.
- Feature Name: Description about
this code
src/main/java/frc/robot/
├── commands/
│ ├── basicCommands/ # Robot state commands (@State annotated)
│ │ └── exampleSubsystemCommand.java # Example transit state
│ ├── states/ # Robot state commands (@State annotated)
│ │ └── Transit.java # Example transit state
│ ├── transitions/ # State transition commands (@Transition annotated)
│ │ └── TransitTransition.java # Example transition to transit state
│ └── driveStates/ # Drive mode commands
│ └── TeleopDrive.java # Teleop drive command
├── subsystems/
│ ├── exampleSubsystem/ # Example additional subsystem
│ │ ├── ExampleSubsystem.java # Example subsystem implementation
│ │ └── ExampleSubsystemIO.java# Example subsystem IO interface
│ └── robotControl/
│ ├── RobotControl.java # State machine controller
│ └── RobotControlIO.java # State logging interface
├── util/
│ ├── DrivetrainPublisher.java # Drivetrain input management
The robot uses a dual-layer command system:
- Robot State Commands: High-level robot behaviors (intake, shoot, climb, etc.)
- Drive Mode Commands: Independent drive control modes (teleop, auto-align, etc.)
Both can run simultaneously, allowing the robot to drive while performing other actions.
States represent discrete robot behaviors. Each state is a Command class marked with the @State annotation.
Example: Transit State
@State
public class Transit extends Command {
// State initialization and execution logic
}Transitions manage the logic for moving between states. They are SequentialCommandGroups that:
- Perform necessary actions before state change
- Update the current state in RobotControl
- Can select different transition paths based on robot conditions
Example: Transit Transition
@Transition
public class TransitTransition extends SequentialCommandGroup {
public TransitTransition() {
addCommands(
new SelectCommand<>(
Map.of(TransitionType.BASIC, new BasicTransition()),
this::chooseTransitionType
),
new InstantCommand(() -> {
RobotControl.setCurrentMode(RobotStates.transit);
})
);
}
}The RobotControl class extends RobotController (from the annotation processor library) and manages:
- Current and previous robot states
- Current and previous drive modes
- State transitions and command scheduling
- Logging of state machine data
Key Methods:
setCurrentMode(): Changes the robot's statesetDriveModeCommand(): Changes the drive modeupdateInputs(): Logs state machine status to AdvantageKit
Drive commands are separate from robot state commands and control drivetrain behavior:
Drive commands set the control inputs to be read on each cycle of the drivetrain subsystem.
TeleopDrive: Field-centric manual control
public class TeleopDrive extends Command {
public TeleopDrive() {
DrivetrainPublisher.setSuppliers(
Robot.driverController::getLeftX,
Robot.driverController::getLeftY,
Robot.driverController::getRightX,
() -> true // Field-centric enabled
);
}
}The robot supports three operating modes:
- REAL: Runs on physical robot, logs to USB drive
- SIM: Runs in simulation, logs to NetworkTables
- REPLAY: Replays logged data for analysis and debugging
All hardware interactions use IO interfaces for deterministic logging:
ModuleIO: Swerve module interface (drive motor, steer motor, encoder)GyroIO: Gyroscope interfaceRobotControlIO: State machine logging interface
Each has multiple implementations (real hardware, simulation, replay).
- WPILib 2025.3.2 or later
- Java 17
- Gradle (included via wrapper)
# Build the code
./gradlew build
# Deploy to robot
./gradlew deploy
# Run simulation
./gradlew simulateJava
# Run log replay (watch mode)
./gradlew replayWatch- WPILib: FRC robot framework (Command-Based)
- AdvantageKit: Deterministic logging and replay
- Phoenix 6: CTRE motor controller library (TalonFX)
- NavX/Pigeon2: Gyroscope support
- Custom Libraries:
robotControlAnnotations: State machine annotation definitions (org.frc3767)annotationHandlers: Annotation processing for state machine (org.frc3767)
- Configure Robot: Update
Constants.javawith your robot's parameters - Define States: Create state commands in
commands/states/with@Stateannotation - Create Transitions: Add transition logic in
commands/transitions/with@Transitionannotation - Initialize States: Set up initial state in
Robot.java - Bind Controls: Configure controller bindings in
RobotContainer.java
This project incorporates code from:
- AdvantageKit (GPL-3.0) - See
AdvantageKit-License.md - WPILib - See
WPILib-License.md
Original template code by FRC 3767 TC Titans.