Swerve Drive PID Tuning and Encoder Values (aka HELP)

Hello people of delphi,

Once again returning for assistance with our swerve robot. Since last time, we have changed up our code (shoutout to FRC Team 3161 for our base code) and made some signifigant progress. The robot currently “drives” but not the way we want to. Currently, after a ton of trials, the robot can drive, but not in the right directions according to the joysticks and after a couple of seconds, the modules go crazy and all in the wrong directions. I beleive this to be a problem with our encoders and PID tuning. I have worked through this with multiple methods and can’t seem to get anywhere. Any help? Tips and tricks are much appreciated!

Our github: GitHub - FRCTeam3543/FRC3543_SwerveBaseCode !

1 Like

Double check magnets are not loose as well.

Although if you are maintaining offsets on code start then the magnets for the encoders are likely ok.

Ensure that the CAN IDs in code physically correspond to the correct modules on the correct corners of the robot as well.

Finally if you are still having trouble, a video of the problem (especially if you can show a logger screen at the same time) and a list of hardware goes a LONG way in helping us diagnose :slight_smile:

i looked at the code, but couldn’t find where you keep the steering offsets. like it seemed like they’re all zero?

have you verified that when you execute test code like “set all module steering to zero” that the modules all line up in the right direction? you need to work this sort of thing up from the bottom, you’ll never make any progress by trying to jump to the full solution.

My team picked the “standard” of the gears are on the inside of the robot. That is the basis of the encoder zero (what the offset is based on), which motors need invert or not, and the direction the wheels must point when the code is started.

We use a straight edge on the outside (smooth side) of the wheels to align then. A CD post pointed out that some swerve modules have holes or marks that can be used for alignment.

Yes we have. Actually, in the beginning we had the modules following the joystick perfectly and “reseting to zero” upon startup and whenever the joystick was touched it aligned the wheels perfectly. Since then, the code was changed (I do not recall what it was, even looked back at the timeline/history of the files) the modules haven’t been working the same. I’m still pretty new with delphi, so I’m not to sure about to do videos yet! But i can link the social platform where the video is linked!

Im getting our lead mechanical to have a look at the module and the magnets throughout the next couple of days

hm, ok. usually there is someplace in the code where the arbitrary “zero” offset numbers live, but I couldn’t find it. could you point it out?

I see that you have set all four CANCoder offsets to zero in your robot code. Since you set them programmatically I think that overrides the offsets that are set within the CANCoder memory. Best practice, I think, is to set the correct offsets in both places (and obviously to the same values).

(I’m sure zeros are incorrect values - it’s impossible (and unnecessary) to achieve those values.)
public static final double angleOffset = 0 ;

So the only reason that we have set them to zero was for testing purposes. We have tried offseting each module according to what the smartdashboard has been telling us, but we’ve had no luck. Our absolute encoders are Thrifty Absolute Magnetic Encoders, not cancoders.

These are 2 links of where we had the most progress: https://fb.watch/wA3StUvO22/ and https://fb.watch/wA3VAOqpj0/ ! These are from our socials. I also have another video uploading soon about what it’s doing now. IMG_3415.MOV - Google Drive : For what its doing now