Swerve is the most effective drivebase available in FRC, but it is also the most complex. In a swerve drivebase, all for wheels can turn and drive separately.
Open Phoenix Tuner X and click on the icon with the red arrow in the sidebar
Make sure you are doing a SWERVE project
Connect the computer to the robot with canivore, motors, encoders, and pigeon (all the circles should be green)
Take all the measurements and input them into their respective boxes
Hit New Project
Input all the necessary data for the swerve project
EACH MODULE:
Turn motor
Drive motor
Encoder
For each module, you must select Validate Configuration at the bottom of the screen, and run both tests
Select the Gyro for the whole robot (pigeon 2.0)
Once all the modules have been configured, you will need to calibrate encoders:
Click the highlighted button and disable the robot
Position all the wheels so that the bevel gear is pointed inwards
Use a long bar to align the wheels
Continue with the on screen directions
The final step before generating the swerve project is to verify steer and drive
Make sure to read all the directions carefully!
Click the green start button
An on-screen prompt will appear asking if all the modules rotated counterclockwise
If a module rotated clockwise, click Not Inverted and then rerun the test
Repeat until all modules rotate counterclockwise
Click Yes
The drive test is much simpler
Click the green start button
Verify that the modules aligned
Pay attention to the modules during the test
An on-screen prompt will ask you if the robot moved forwards
If it did, hit yes
Once this is complete, you can hit generate swerve project. The video tutorial goes through the code, I would reccomend looking at that.
INSIDE OF YOUR Robot() constructor in Robot.java ADD THESE TWO LINES OF CODE. IF YOU DON'T SIGNAL LOGGER WILL RUN EVEN IF YOU TRY AND STOP IT OTHERWISE.
Changes to Generated Files
The only major change to these files are in the very last method of CommandSwerveDrivetrain.java, which runs addVisionMeasurement() as shown below. TunerConstants.java can be let alone
The image below is what the code will look like after project generation
NOTE: The files below are well documented and you need to look through them yourself. I am covering important/confusing methods, because there are too many getter and setter methods which may be important, but are not worth covering
Drive.java: Manages telemetry output, pose tracking, and updating drivetrain states
Drive.java has lots of important getter, setter, and reset methods. It also has commands to stop the drivetrain, update the drivetrain state, and follow choreo/pathplanner
Instance variables and constructor
driveWarmupCmd()
The goal of this method is to force SwerveRequest classes to load before the robot is enabled to optimize initial loop times
DriveConstants.java
Aside from containing drive constants, DriveConstants.java contains methods for PIDToPose and auto align PID constants
Telemetry.java: Sets up network tables and drivetrain telemetry
Network Tables
If you want to know what each table holds, look at the first parameter in each. (Orange colored String)
Swerve Modules
Creates an array of all the swerve drive modules as Mechanism2d objects. Creates arrays with their speeds and directions.
The telemeterize() method is pretty self-explanatory except for the set(), setAngle(), and setLength() methods. These do not actually change anything on the robot. The set() method publishes the values onto the network tables. The setAngle() and setLength() methods set the angle/length of the Mechanism2dLigaments. A Mechanism2d is a widget 'illustrating' a mechanism, and the ligaments represent a stage of that mechanism.
DISABLING SIGNAL LOGGER: COMMENT OUT EVERY LINE IN Telemetry.java WITH SignalLogger in it