Skip to content

Repository files navigation

FRC Subsystem Example

This project is a teaching example, not a full competition robot. It has been stripped down to one fully-documented subsystem (the intake) plus just enough surrounding code to make it run, in both simulation and on a real robot.

If you're new to FRC command-based programming, start by reading the files in the order below. Every file has comments explaining what the code does and why it's organized that way.

Where to start reading

  1. src/main/java/frc/robot/subsystems/intake/: the main teaching example. Read these four files in this order:
    • IntakeIO.java: the interface describing everything the intake can do (spin the roller, move the extension, etc), without saying how. This is the "IO layer" pattern used throughout FRC codebases to support simulation.
    • Intake.java: the subsystem itself. Holds all the tunable constants, the state machine (IntakeState), and the periodic() loop that decides what the motors should do each cycle. This is the file with the most explanation in it; read its class-level comment first for a roadmap of the rest of the file.
    • IntakeIOTalonFX.java: the real-hardware implementation of IntakeIO. Talks to actual TalonFX motor controllers over CAN.
    • IntakeIOSimTalonFX.java: the simulation implementation. Extends the real hardware class and layers a physics simulation underneath it, so the exact same control code runs in sim and on the real robot.
  2. src/main/java/frc/robot/subsystems/Superstructure.java: sits between RobotContainer and the intake. On a full competition robot this is where multiple mechanisms would be coordinated together; here it just forwards requests to the intake, but it's kept as its own layer so you can see where that coordination logic would live.
  3. src/main/java/frc/robot/RobotContainer.java: where joystick buttons get connected to commands. This file is intentionally free of any control logic; its only job is wiring.
  4. src/main/java/frc/robot/Robot.java and Main.java: the standard WPILib entry point and lifecycle methods. You shouldn't need to change these on a normal FRC project.

What else is in here

  • subsystems/CommandSwerveDrivetrain.java, generated/TunerConstants.java, subsystems/vision/apriltag/, util/LimelightHelpers.java: a complete swerve drivetrain (generated by CTRE's Tuner X tool) plus the AprilTag vision code it uses to correct its odometry.
  • util/CtreUtil.java, util/Telemetry.java: small shared helpers used by both the swerve drivetrain and the intake (simulation setup and dashboard telemetry, respectively).
  • RobotVisualizer.java: publishes a simple drawing of the intake to the dashboard so you can see it move in simulation. Every method is a no-op on a real robot.
  • Constants.java: the CAN buses shared by every subsystem. Constants that only matter to one subsystem (like every number the intake needs) live next to that subsystem instead, in its own *Constants class.

About

Example that teaches the structure of programming FRC subsystems

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages