I’ve been writing code for our team’s swerve drive using the 0-to-autonomous video, and I’ve just about got it but I’m still facing some problems. Our swerve modules use a thriftybot magnetic encoder. (I’ve been uncertain on when to use that encoder versus a relative encoder in code, which leads me to my main issue)
The swerve modules have been having issues where while they rotate when prompted by the joystick, but all of their angles are off. Some more than others. I’ve tried remedying this by finding encoder offsets, but it hasn’t seemed to work well.
This is my code. I’d appreciate being led in the right direction to get this done.
generally you do not need to use the relative encoder in the turning motor, you can simply use the absolute encoder in its place, and then use the relative encoder for driving (at least that’s what my team did)
I mean, if your motors have an integrated relative encoder (such as NEOs) and you don’t actually need an absolute encoder, you might as well use the relative one.
The downside of a relative encoder is you will get drift between each of the modules. With an absolute encoder the same index is always in the same physical location.
With a relative encoder as the name implies it is relative to where the shaft of the motor is at power on or after a programming reset. So if one module is 2 degrees off at the start of auton it will be fighting the other three modules with no way of knowing it was offset.
With absolute encoders the wheels can all go to their true home at power on and you don’t need to worry that they will be offset. Is it worth losing a match because someone didn’t reset all 4 wheels properly?
You “need” an absolute encoder or you need a super duper accurate method for resetting the modules home locations
That’s fair, but does it make a significant difference for driving (not turning)?
Of course, this is especially if you’re mainly making use of odometry in autonomous, which is only the first 15 seconds, but as vision becomes more and more popular and accessible I could see precise odometry for the whole 2:30 being more important.
Ah, in that case not at all! There absolute is useless. In that case you’re trying to control the RPM or position with PID. Either way you are resetting the position and speed when auton or teleop starts to be based on the motors current position and speed. It’s relative to where it started that movement from, not from where it powered on initially.
The error between one cycle and the next is used to adjust your speed or position and that is always relative to the last cycle. Where it started from on the very first cycle doesn’t matter anymore.