Intro - GrissomRobotics/InfiniteRecharge GitHub Wiki

Code Introduction

This repository uses Java to program an FRC robot. Most code that we care about is under src/main/java/frc/robot and generally uses the WPILib framework to interact with elements on the robot.

Useful links

High-level code description

  • Main.java
    • Boiler-plate code for building project. Can be ignored.
  • OI.java
    • Custom uses of the controller inputs
  • Robot.java
    • Instantiates each mode, e.g., teleop and autonomous.
    • Sets up cameras for teleop
  • RobotMap.java
    • Instantiates sensors/subsystems
    • Maps joystick controls
  • commandGroups
    • Each code file in this directory contains sequences of commands to use during autonomous mode
  • commands
    • Each code file in this directory specifies one "operation" of the robot, e.g., DriveWithJoystick.java, SpinCellIn.java
    • Commands use access to a subsystem (see below) to make the robot do things, as opposed to directly accessing a motor, which is part of a subsystem
  • custom
    • Code "classes" made by our group that do special things we needed our robot to do that weren't in the WPILib code
      • E.g., Ramper.java limits the acceleration of a command sent to a motor
  • subsystems
    • Each subsystem is a collection of hardware (e.g., motors) that does a thing as a unit, e.g., Belt.java or DriveSubsystem.java

FAQ

So how does the robot know what to do when I press a button on the remote control? Examples:

Belt

This one is a bit convoluted...

  • belt subsystem is instantiated here after being imported here so it can be used in this Java file
  • The "default command" for the belt subsystem is set here to be the ManualBelt command. Note that the oi object is passed in to ManualBelt
    • The oi object is instantiated here
    • The "default command" is what gets run if the subsystem is not otherwise being commanded
  • ManualBelt declares what its primary functionality is in the execute function
    • It grabs from oi here (getManualBeltRotation)
    • getManualBeltRotation pulls data from the second joystick, raw axis 5 here (zoom stick)
    • The output from getManualBeltRotation is piped into the belt's function turnBelt on the same line
  • The belt subsystem knows which motor to actuate in its turnBelt function because it is defined here

Color sensor

This one is much simpler...

  • The color sensor toggle button is defined here
  • We define what happens when we press that button here
    • ToggleSensor is a "command" that uses the spinner subsystem