We have been trying to line up our swerve modules for a few weeks now, but we can’t get them to sync up. We are using mk4 swerve modules with falcons for driving and neos for steering. Please let me know if there is anymore information I can provide as this is my first post to Chief Delphi. Thanks!
It looks like your CANCoder offsets are not set correctly in your Constants File.
The way to get the correct offset values is as follows:
-
Run robot code and press fwd on the forward joystick. The angle values (shown in Smartdashboard or Phoenix Tuner) should be ~0. (Factory zero)
-
Align all wheels forward. Use an extrusion, or something straight, to guarantee alignment between front and back wheels. Jot down the new angles.
-
Subtract first angle from new angle, and set that as your offset. If the direction of spin is wrong, add 180 to your offset.
I just finished trying that and it didn’t seem to work. It seems like every time the robot is power cycled or new code is deployed, the zeroed position changes. We tested to see if the absolute encoder is giving accurate values, and it seems to be.
It’s probably a good idea to verify everything is set up like you think it is. I have a feeling your motor and CANCoder might be out of phase.
- Use Phoenix’s Tuner X to verify your CANCoder value gets larger when you turn the wheels CCW (to the left).
- Use REV Hardware client to confirm your motor’s position also gets larger when you turn the wheels CCW.
- Finally, verify that when you apply positive power to the turning motor, the wheels turn to the left.
When things are set up right, after your code starts up and your resetEncoders()
methods have run, the CANCoder and the motor’s encoder should have (almost) the same values as you turn the wheels.
Ohhh ok. We ran into the same issue this year. Setting to absolute mode in code seemed difficult and different than last year. We gave up and went back to Phoenix 5, where you can easily set to absolute mode in the GUI.
Not a code solution, but just in case this might be your problem: make sure the magnets used by the angular motor encoders are glued to the swerve module itself. The absolute encoder values are dependent on those magnets being very very still, and if they move around your values will go nuts. My students had the same issue as you last year and they went away the moment the glue cured
We’ve triple checked to see if the magnets are glued in and I can confirm they are.
I think that we have come to the same conclusion. Thank you so much everyone for helping!