We are having a problem with the offsets or the angles of the modules.We set up the code and changed the constants to suit our robot, and then we tried moving the robot at first everything runs smoothly, the angles are close to perfect and the directions are correct . After a bit of time the modules have a slight change in their angle which builds up slowly overtime , but the bigger problem happens when we reupload the code, the angles become WAY off.
The same thing happened with us last year, and the solution was to make a delay for one sec in the swerve subsystem and then reset the modules to absolute, and that didn’t work either.
We checked the constants; trackwidth,type of module,offsets …etc. But nothing works.
Btw we are using MK4i L2 falcon modules.
Does anyone experience the same thing?
And how can we solve this?
Code :GitHub - dirtbikerxz/BaseTalonFXSwerve
Typical troubleshooting question:
Magnets for encoders have loctite applied?
No, they don’t.
Would that solve the problem?
We had a problem similar to this problem about 3 months ago. Maybe this title will help, all our problems have been solved.
@gdefender @Hollisms they helped us a lot maybe they can help you too
Most likely yes, we had this same issue with one of our modules a few months ago and it was for this reason.
If after turning everything off and back on again, the modules are straight again, that means the issue is not with the magnets. Otherwise the actual numbers provided by absolute encoders would change.
Where are your absolutes recorded?
I see (in Constants Line 96)
public static final Rotation2d angleOffset = Rotation2d.fromDegrees(0.0)
Are all your absolute encoders zeroed?
I suggest checking them in Phoenix Tuner after you reupload the code.
Did you try using the solution from CTRE referenced in the post above, I don’t see it in your code
You would need to add waitForUpdate()
to getCANcoder()
:
public Rotation2d getCANcoder(){
return Rotation2d.fromRotations(angleEncoder.getAbsolutePosition().waitForUpdate(2).getValue());
}
You could even go farther to troubleshoot by checking if reading the signal was successful and logging when it fails. It won’t solve the problem, but at least it will help you know if this is the source:
public Rotation2d getCANcoder(){
var signal = angleEncoder.getAbsolutePosition().waitForUpdate(2);
if (signal.getStatus() != StatusCode.OK) {
DriverStation.reportError("FAILED TO READ CANCODER ON MODULE " + moduleNumber, false);
}
return Rotation2d.fromRotations(signal.getValue());
}
It’s not required, but I suggest you configure the CANCoders’ MagnetOffset
with your module offsets instead of dealing with it in your code. It just makes it easier and more automatic. But I see no problem with what you have.
We just found this problem last night. Loctite 609 or 638 (which is a retaining compound, not the normal loctite thread locker!) should be used.
Thank you all, we tried everything and nothing worked, and we decided to switch to a completely different code. And after that everything worked smoothly…
What code did you switch to?