-
Notifications
You must be signed in to change notification settings - Fork 1
Tuning the Swerve Drive
Open Phoenix Tuner X and import the config the robot code. Then, export the generated constants only, not the generated project. When importing, there will be a few changes in the file. Pretty much undo every single one except for the ones affecting what you are trying to modify. (In this case, module offsets.)
Go into the Constants
and go into the SwerveConstants
under DevelopmentBotConstants
. Then find the modules, usually labeled Mod0
, Mod1
, Mod2
, and Mod3
. These are the Front Left, Front Right, Back Left, and Back Right modules respectively. The angleOffset
field contains the modules' current offsets in degrees.
Put the robot on blocks or support it some way so that its wheels do not touch the ground. Align the wheels straight using a straight beam so that all of the bevel gears are facing left if you are looking at the front of the robot. (The front of the robot is the closest side to you.)
Look into NetworkTables and find the /SwerveDriveSubsystem/Raw CANCoder Angles
field. It should be a list of doubles. Copy these numbers into a text editor or something so they stop changing once your wheels are aligned. Then, replace the modules' current offsets with these new ones. They should be in order from Mod0
up to Mod3
.
Finally deploy and the modified code and make sure the wheels drive straight. Then, drive the robot around and make sure it is driving well. Commit the changes with git and then push to GitHub.
Change the PID values in the drive motor PID section in constants to all be 0, and change both PIDs in the PathPlanner AutoBuilder
to all 0. Additionally, change the angularVelocityCoefficient
to 0 and the accelerationCoefficient
to 0. Make a straight path for the robot to follow that has as reasonably low as you can get the acceleration to go. Run the auto with a small kV
, likely around 0.1, and see how it follows the path. Start increasing the kS
until the robot starts accelerating relatively instantly on auto enable as opposed to waiting a few seconds. Then start increasing kV
until the path is followed accurately.
Do the same sort of tuning with the accelerationCoefficient
in the SwerveDriveSubsystem
as was done with the kV
parameter. Change the PathPlanner path to have significantly more acceleration and make sure that it still follows the path properly.
This and the velocity was based on 2910 Jack in the Bot's feedforward tuning methods.
Make a drive command which drives the robot forward by default, or set the drive supplier for the forward joystick to always be something small but stable and forward. Tune the constant until spinning does not cause the robot to drift left or right significantly.
This was based on 2910 Jack in the Bot's twisting correction.