Team 254's 2022 FRC robot code for Sideways. Sideways' code is written in Java and is based off of WPILib's Java control system.
The code is divided into several packages, each responsible for a different aspect of the robot function. This README explains setup instructions, the function of each package, and some of the variable naming conventions used. Additional information about each specific class can be found in that class' Java file.
- Clone this repo
- Run
./gradlew
to download gradle and needed FRC/Vendor libraries - Run
./gradlew tasks
to see available options - Enjoy!
- Get the WPILib extension for easiest use from the VSCode Marketplace - Requires Java 11 or greater
- In
.vscode/settings.json
, set the User Setting,java.home
, to the correct directory pointing to your JDK 11 directory
- Run
./gradlew idea
- Open the
FRC-2022-Public.ipr
file with IntelliJ
- Run
./gradlew eclipse
- Open Eclipse and go to File > Open Projects from File System...
- Set the import source to the
FRC-2022-Public
folder then click finish
- Run
./gradlew deploy
to deploy to the robot in Terminal (*nix) or Powershell (Windows) - Run
./gradlew build
to build the code. Use the--info
flag for more details - Run
./gradlew test
to run all of the JUnit tests
-
Field-Centric Swerve Drive
Standard field-centric control of a swerve drivebase using odometry, encoders and gyro along with Swerve Setpoint Generation to impose Kinematic constraints on the drivebase for more controlled movements to reduce wheel-slip and improve Shoot-On-The-Move.
-
Superstructure with Two-Sided Intake, Automatic Wrong Ball Rejection, Super Eject, Automatic Turret Tracking
The robot uses a state machine to control the intakes and serializers on both sides of the robot. It uses banner sensors to determine the locations of the ball in the robot and REV Color Sensors wired to a Teensy to determine ball color. After detecting a wrong color ball, the robot determines the eject setpoints based on its position and orientation on the field. Throughout the match, the robot always follows the vision target with the turret using Motion Profiling.
-
Shooting on the Move
The robot uses a Sin Map (Utilizing Trigonometry for both Shooter RPM and Hood Angle). We break Shooter RPM into a horizontal and vertical component and use a linear regression to map the robot's distance from goal to a Shooter RPM. To compensate for motion, the robot calculates a feedforward based on its tangential and radial velocity about the goal.
-
Feedforward + Proportional Feedback Controller for Autonomous Path Following
The robot generates pre-computed trajectories using a Quintic Hermite Spline. To follow trajectories, the robot is first commanded the precomputed velocity at the current timestamp. It then computes the longitudinal error along the path and uses a proportional controller to reduce it. The robot time-parametrizes heading based on the total timing of the trajectory and uses a separate proportional controller to reach heading setpoints.
-
Fully Automated Climb
The robot uses a state machine for the endgame climb to move mechanisms in a controlled fashion. Transitions between states are determined using encoder positions, time in state, and gyro measurements.
-
Contains the robot's central functions and holds a class with all numerical constants used throughout the code (see
Constants.java
). For example, theRobot
class controls all routines depending on the robot mode. In addition, theRobotState
class keeps track of the current position of the robot's various frames of reference. -
Handles the execution of autonomous routines and contains the
actions
andmodes
packages. -
com.team254.frc2022.auto.actions
Contains all actions used during the autonomous period, which all share a common interface,
Action
(also in this package). Examples include driving paths, auto aiming the turret, and deploying and retracting intakes. Actions interact with the subsystems, which in turn interact with the hardware. -
com.team254.frc2022.auto.modes
Contains all autonomous modes. Autonomous modes consist of a list of autonomous actions executed in a specific order.
-
com.team254.frc2022.controlboard
Contains code for the driver to use either joysticks or gamepad and the operator to use a gamepad. Also contains a wrapper class specifically for Xbox controllers (see XboxController.java).
-
Contains codes for loops, which are routines that run periodically on the robot, such as for calculating robot pose, processing vision feedback, or updating subsystems. All loops implement the
Loop
interface and are handled (started, stopped, added) by theLooper
class, which runs at 100 Hz. TheRobot
class has one main looper,mEnabledLooper
, that runs all loops when the robot is enabled. -
Contains the
TrajectoryGenerator
class which contains the trajectories that the robot drives during autonomous mode. EachTrajectory
is composed of a list ofWaypoint
objects and headings. -
Contains the
DriveMotionPlanner
class which controls the drivebase as it follows a trajectory during the autonomous period. -
Contains the
ShootingUtil
helper class which takes in the current target range and robot state and returns parameters for an ideal shot for both stationary and shooting on the move. -
Contains multiple classes representing LED states used in the
Superstructure
class. -
com.team254.frc2022.subsystems
Contains code for subsystems, which are consolidated into one central class per subsystem, all of which extend the
Subsystem
abstract class. Each subsystem uses state machines for control and is a singleton, meaning that there is only one instance of each. Subsystems also contain an enabled loop, a read periodic inputs method, and a write periodic outputs method, which are controlled by theSubystemManager
class. -
Contains classes used for the robot's path following and alternative teleoperated driver modes.
-
Constains a set of custom classes for motor controllers, color sensors, and solenoids for simplifying motor configuration, reducing CAN Bus usage, and checking motors.
-
Contains a set of classes that represent various geometric entities.
-
Contains all motion profiling code used for autonomous driving. Trapezoidal motion profiles are used for smooth acceleration and minimal slip.
-
Contains classes to represent physical states of a swerve drive, a swerve's effective wheelbase, and a DC motor.
-
Contains classes to generate and time parameterize splines for smooth autonomous paths.
-
Contains various drive controllers and classes used for forward and inverse kinematics.
-
Contains multiple classes used for representing and following
Trajectory
objects. -
com.team254.lib.trajectory.timing
Contains multiple classes for generating time-parameterized trajectories that obey physical robot constraints.
-
Contains a collection of assorted utilities classes used in the robot code. Check each file for more information.
-
Contains various classes that help with tracking and storing information about vision targets.
-
Contains parent classes of the main
Robot
class that get rid of loop overrun and watchdog print messages that clutter the console.
- k*** (i.e.
kDriveWheelbaseMeters
): Final constants, especially those found in theConstants.java
file - m*** (i.e.
mPathFollower
): Private instance variables