Unit 7: Advanced FRC Coding
A swerve drive is a complex system. When things go wrong, it can be intimidating to find the cause. This lesson provides a systematic checklist for debugging, allowing you to quickly isolate whether a problem is in hardware, low-level control, or high-level logic.
The core principle of debugging is isolation. Instead of looking at the entire complex system at once, we test the smallest possible components first and work our way up. Our most powerful tool for this process is the SmartDashboard, which gives us a real-time window into the robot's state.
The first step is always to visualize the state of each module. We use custom widgets to display the angle and speed of each of the four swerve modules.
Common Problems to Look For:
If the dashboard reveals an issue with a specific module, we need to isolate it. We put the robot on blocks and run a special test routine that commands the suspicious module to spin its drive motor slowly while its steering motor rotates through a full 360 degrees.
What to Watch For:
If all four modules pass the wheel test but the robot still "drifts" or doesn't drive straight in field-oriented mode, the problem is almost always the gyroscope.
To test it, we place the robot on the ground, reset the gyro to 0, physically rotate the robot exactly 90 degrees, and check the SmartDashboard. The reading should be very close to 90.0. If not, the gyro may be improperly calibrated, mounted loosely, or failing.
If all hardware checks out, the final place to look is in the high-level code.
Question: Your swerve drive drifts to the left when you command it to drive straight forward in field-oriented mode. The individual wheel tests all pass. What is the most likely culprit?