Swerve drive azimuth not working correctly while on carpet

So after 2 days of comp we have realized that our issue with swerve drive is that :

we use the integrated encoders from neos for our azimuth pid, and our in-built encoders for neos are inconsistent with our actual module angles (which we can see correctly from the absolue encoder (cancoders)) which causes the drivetrain to MASSIVELY drift, to the point that it’s barely driveable;
so we developed a 5-minute fix by assigning a button that basically resets in-built encoder positions to absolute position and it worked half-well.

so as a permanent fix does this look feasible

for(SwerveModule mod : mSwerveMods){ if (Math.abs(mod.integratedAngleEncoder.getPosition() - mod.getCanCoder().getDegrees()) > 4.0) mod.resetToAbsolute(); }
(called in swerve subsystem periodic)

and resetToAbsolute() does this

public void resetToAbsolute() { double absolutePosition = getCanCoder().getDegrees() - angleOffset.getDegrees(); integratedAngleEncoder.setPosition(absolutePosition); }

our full code can be found here GitHub - FMWill-7576/SwerveBot7576: FRC Team 7576 Swerve code using NEO motors and SDS MK4

2 Likes

Just to let you know both YAGSL and democat’s maintained swerve-lib both periodically update the integrated angle on rest.

why do you do it on rest? and how do you determine “on rest” ?

1 Like

We determine on rest by if desired angle is the sane as the last and the velocity is less than 10% of the max velocity.

okay, but is there a specific reason you update the position only when its on rest?

and is this the right implementation of what you just said periodically update neo encoders to cancoder pos. · FMWill-7576/SwerveBot7576@39da9f1 · GitHub

1 Like

Reduces the chance of setting it to an incorrect or out of date absolute encoder value.

No, you should also ensure velocity is low/near zero

i do that in the if statement 1 line above

1 Like

My bad! Was only looking at the changes, seems close enough.

1 Like

would i still need to update the neo encoders every time it notices an error greater than 4 degrees or is it safer to just do it when on rest? because I feel like the angle drifts while we’re on the move also, so do you think updating it only while resting will be enough?

1 Like

It normally will be, updating when 4deg off is dangerous bc you could be setting it to a slightly out of date angle.

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