Hi, we recently transferred to swerve and are having problems setting cancoder offset values. our current code is advantage kits swerve drive example code tweaked to change analog sensors to cancoders. When to robot starts the wheels turn around to a random position even if if the wheels are started perfectly straight. i tried tuner x readings to set the offsets but by far it didnt work and the wheels never aligned even though our absolute encoder positions were what it was supposed to be. Does anyone have steps to configure cancoders offsets so we can get our drivetrain up and running?
When you used Tuner X to set the offsets, did you make sure to save the configuration?
yeah
What motors and modules are you using? If you’re using ctre devices, I’d suggest using the Phoenix Tuner X’s swerve generator. I tried it the other day and after about 15 minutes of work, I had a driving robot that drives better than any other swerve library my team has tried (sds and yagsl). Also what swerve library are you currently using? When using the sds library, I remember having to put the offsets into the constants file for them to stay.
we are using neos, cancoders and navx2 also we didnt use any libraries and just copied advantage kits example swerve code. i just looked into what you stated and is it only avalible with falcons and pigeon?
Tuner X swerve generator really shows off all the fantastic work CTRE has put into their firmware and library while allowing devices to work really well together. I will always recommend using them over YAGSL if you can. I even put a disclaimer on my docs saying so
I think both are great. The only reason YAGSL took longer for me to set up is user error
There’s alot of room for that especially with this upcoming release which is why my documentation is incredibly important. I can’t compete with applications that can communicate with the hardware directly like Tuner X or REV Hardware Client simply bc it’s not worth my time or effort, but i can document everything in excruciating detail.
That’s correct, the phoenix tuner x swerve generator only works if all of your devices are ctre. I’m sorry but I can’t remember for the life of me how I zeroed our cancoder offsets last year. I remember we used some documentation but I can’t seem to find it now. Sorry I couldn’t be of more help.
Yeah, the reason it didn’t work when I did it was because I didn’t read the documentation. I was putting in the wrong type for our encoders because we were using canandcoders with neos so I assumed the type should be canandcoder but it wasn’t. It still took wayyyy less time than the sds library.
I’m not sure if you got this working or not, but I know that we struggled a bit to make sure we were reading the appropriate swerve position value in Tuner X. I expect that you want to use the “Absolute Position No Offset” value. Depending on how the rest of your code handles that value, you may need to negate it.
Yes, just to add a +1 to this, we also had to negate it. Our team is not using all Rev parts. We’re using a NavX gyro. Here is our procedure we’ve had some success with:
With the CANCoder set to a magnetic offset of 0:
- Command the drive motor to have some positive velocity
1.1 This finds which directions is “forwards” to the module - Set the drive motor velocity to 0, carefully rotate the module by hand so that the module “forward” matches your robot’s “forward”
- Using TunerX read the absolute position of the CANCoder assigned to that module
3.1 This is the offset that needs to be negated.
3.2 To confirm, set the magnetic offset to -1.0 * the read absolute position.
The new absolute position should now be 0.
Another issue we had to fix was just getting the conversion units correct. We were using last years conversion(encoder units per deci-second) instead of the latest Rev6 library conversions (rotations per minute)
@kuzeyatay have you had any luck? There are others who likely will have the same issues in the future so it would be great to hear what worked for you!
actually we did! we used mechanical advantage’s base swerve code and aligned the wheels straight then copied the absoulte encoder valıes. this worked perfectly for us. However if we dont manually align the wheels before turning on the robot, wheels start unaligned and we are unable to move. still trying to figure that out. open to suggestions.
I like REV’s approach to this. They have a calibration jig that you use to calibrate each module. And each module points in a different direction for it’s zero. But the code has an offset in it for each module. Doing it this way also simplifies moving all the modules to the “locked” position.
Creating a similar calibration jig/tool for SDS modules shouldn’t bee too difficult.
My team is also using the AdvantageKit base swerve and we’ve had to re-align the wheels before turning the robot on and before deploying code in order for the robot to move.
Have you found a solution yet to having to manually align the wheels? We’ve tried calling .waitForUpdate(2) after cancoder.getAbsolutePosition() but the problem still persists.
Unfortunately we have not. this friday one of our seniors are coming in and we will console him. I will keep you updated.