Swerve Drive not Driving Straight

We are using MAXswerve for the first time this year and are getting issues with driving the robot. Basically, when we want to drive straight, the robot drives and turns significantly and doesn’t go in a straight line (both in autonomous and teleop). We verified that it wasn’t any weird gyroscope issue and verified that when pushing the joystick up we aren’t getting slight turn readings that cause it to turn. We noticed the wheels weren’t all straight when we want to drive straight, so we calibrated the modules with the rev hardware client. That didn’t fix anything as the wheels still weren’t all straight. We then slightly changed the angle offset of the modules in our constants, and it fixed it for the most part. The turning significantly decreased but there is still some slight turning. Are there any alternatives to fix this issue or do we need to keep messing around with the modules’ angle offset? Would it be more of a programming issue or a mechanical issue? Here’s a video of how it looks like now. Here’s our code, too.

1 Like

Have you tuned the gains for the moudles’ turning PID controllers?

Yes. But we did not properly tune it with other clients and such as we don’t really know the best way to do so. We just played around with the p value and saw if it would do anything. Our issue still persists.

I haven’t looked at your code yet, but this sounds like an issue my team had last year. Have you glued in the absolute encoder magnets into the housing in the swerve module? If the magnets rotate even a little bit, your rotation offset data will be completely useless.

Second mechanical-based question: is the angular motor drive shaft slipping at all? If it is not tightly fitted into the housing, then the friction of turning the wheels on carpet may cause the wheel alignment to change in a way the encoders would never know about.

Code question: are you using your encoders as Absolute Encoders? Different kinds call it different names, but if there is some sort of “absolute mode”, make sure that is set

For the code question: we are using absolute encoders, yes. As for the mechanical questions, I’ll have to check it with the build team at tomorrow’s meeting. I will let you know how it goes! Thank you for your response!

1 Like

Good news (hopefully that persists)! We thought we only needed p values for turning PID motors at first. We ran out of ideas and decided to mess around with the I value. It seems like it fixes it. Do you know a good way to tune these numbers? If it’s a client of some sort, how would you integrate that into the code?

1 Like

Glad to hear your robot is driving in a straight line!

In terms of PID tuning, my team keeps the PID values as hardcoded constants and tunes them by trial and error. I recommend setting up some sort of consistent test scenario, like making a command that just tries to drive in a straight line for 1 second, just to keep as many variables consistent as possible.

Are you sure all modules have the same pinion gear?

David

Yes, it seemed everything mechanical-wise was fine after checking the modules.

Ok will do! Does the speed of the robot matter much when tuning? Should it be going max speed when driving straight or does that not matter?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.