Zeroing CANCoders

Hi all,

I am working on programming a swerve drivetrain, and I seem to be having an issue with the orientation of the encoders. I am using 4 MK3 SDS Falcon swerve modules as well as 4 CANCoders. I have the CANCoders configured to report 0-360.

I am booting them to absolute position and am able to control the position of each module. My zeroing process is as follows:

  1. Turn each module so they are facing my desired zero.
  2. Take the angle of each CANCoder.
  3. Set the magnetOffset to the opposite of what each CANCoder reads.
  4. Reboot the robot.

This process is not working, and I am not sure why. Is there another way to zero the CANCoder? Print statements in my code make it appear as though the changing of the offset is working, but it does not appear to be.

Any advice is appreciated.

We manually grabbed the pulse width (not position) and zeroed in code last year. Pulse width was in increments of 250ns, where position is in increments of 1us. I believe the problem was that Talon SRXs don’t support zeroing remote sensors, and that may go for zeroing the sensor itself as well.

How did you grab the pulse width of a CANCoder? I’m also using Falcon 500s. Not to mention, I am using Python, but that should not be a limitation.

1 Like

There should be a getPulseWidthRiseToFall method. Our 2020 code might be public on the 1072 github.

I think I might have found my issue. Thanks for the help anyway @asid61!

Can you share what your issue was?

We found using the magnet offset setting in the CANcoders to be flaky (however this was over a year ago, when the CANcoders were still brand new, so this might be fixed by now). We just set the offset’s directly in our swerve code to the target position instead.


For clarification, this was with the Mag Encoder connected via ribbon cable to a Talon SRX. I don’t know what I was thinking in January. The CANcoder has no offsets, it just reports the angle of the magnet raw.

1 Like

@aabshagen My issue was with the magnet offset and some programmatical issues. What I did to zero the CANCoders was this:

  1. Turn all wheels to the desired angle.
  2. Turn the robot on and use the Phoenix Tuner to record the angle offset of each straight wheel.
  3. Call configMagnet offset every time the robot instantiates the modules. Set each module’s offset equal to the respective offset you recorded.
  4. Ensure you are calling getPosition(), after setting the mode to absolute. My issue was that I was calling configMagnetOffset and using this method. Magnet offset has no influence on this value.
  5. Test your code.

Again, my issue was in step four. A lack of closely reading the documentation was my issue it seems. This was a long time ago, so I think this was the issue, but am not 100% sure.

The CANCoder has a “boot to absolute position” option

I believe this means that it is absolute all the time. So if you turn off the robot, rotate the wheels, then turn it back on, you will still get the correct angle of the wheel

I’m not 100% sure though, so I would test this. I haven’t used this option yet

Maybe this will help

Hello! I know that this is an old thread, but our team has also been having some issues with encoder zeroing recently, and I thought I would share this in case other teams are also having problems:

Thanks to Cory from CTRE for this info!

1 Like

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