Hello everyone, I have been encountering an issue that I have not been able to resolve. I have been trying to set the offsets on my swerve drive on our practice bot. We are using Falcon 500’s with canCoders and a Pigeon.
Every time code restarts on the robot, the wheels will find a new home position even if the offset value was not changed. They seem to be changing based on the position they were on when they booted. If I align the wheels they will work until the robot is booted and the wheels are not in sync. It seems like they are not using canCoder Values at all.
For example, my back left module will change its position by about 30 degrees counterclockwise every time I redeploy code. This happens for every module even if nothing is touched both in software and physically.
I have been building upon this code(Based on 364 code): GitHub - dirtbikerxz/BaseTalonFXSwerve and this issue exists with this project even if I only change the Pigeon, Talon, and CanCoder Can ID’s.
We have done this multiple times in the last few seasons but I have never seen this issue before.
Have you tried using Tuner X swerve generator instead? It sounds like you’re using all CTRE products so this would be wayy better and more optimzied the 364’s code?
I have tried that and it worked correctly. However, our competition bot is using Neos this season and I would like to keep our test bot and competition bot as close as possible.
I think the issue is related to Pheonix 6 but I have not figured it out yet.
Don’t seem to find any good reason for this
Is the CANcoder showing the same positon as the motor?
Btw, why not have the cancoder be a remote sensor for the motor, and configure its offset with the MagnetOffset config? Or is this a part of the moving to NEOs thing?
We had a similar problem when migrating our swerve from last year. Every startup, the angle motor’s zero wouldn’t be its starting position. We haven’t found the root cause, but we got around it by setting the Talon FX’s position to be 0 in the constructor using the setPosition() method.
Edit: We are using the integrated encoder for the Falcon’s, not a CANCoder.
With Phoenix 6, I would recommend setting the MagnetOffset property for the CANcoder and then never having to worry about offsets again. In Phoenix 6, the CANcoders always boot absolute. When you read the position it will incorporate the magnet offset; so, you don’t have to make any adjustments.
Hello, We did not experience this issue using V5 and we decided to use v5 for the 2024 season. Is your issue the exact same as mine, does it work until you power cycle?
Yeah! We will manually zero the robot, it works great. We power cycle when the wheels are all in different places, and boom! Offsets are off. Only difference is we were using the v5 code. I’m moving things over to v6 to test if the problem persists there.
Are you using MK4i modules? We encountered this issue recently with MK4i modules and 364’s drive code and found that the module offsets weren’t being set properly because resetModulesToAbsolute() wasn’t being called.
Calling resetModulesToAbsolute() after a 1-second delay worked perfectly for us.
Are you using the Base Talon Swerve code? If you are, you need to set offset using MagnetOffset, this is new for Phoenix 6. In SwerveModule.java, I got rid of angleEncoder.getConfigurator().apply(Robot.ctreConfigs.swerveCANcoderConfig);
and created a new method
then I called this method right after angleEncoder = new CANcoder(moduleConstants.cancoderID, "static");
You will also need to go to the Constants file and change angleOffset from Rotation2d to a double, the value phoenix tuner gives is a double. Since you made this change you will have to go to SwerveModuleConstants.java and change the type there as well.