We are using SDS swerve modules (I believe they are MK4i but they could be MK4) with NEOs connected to Spark Max controllers as well as CANcoders for the absolute encoders. This is my first time trying to code for swerve, and I have almost no understanding of swerve drive as a concept and how the specifications of the robot fit in to the control code.
The code from last year is in the branch “myer”. We also tried to use YAGSL (see “desperation” branch), but I am unsure if I calculated my angle/drive conversion factors correctly. Using both last year’s code and YAGSL, we are getting an odd, inconsistent oscillating behavior on the angle motors. Sometimes, they seem to bounce back and forth with decreasing changes until they settle in on a fixed position, but any inputs will repeat this behavior. Other times, they simply wiggle around endlessly even without inputs.
Any help would be appreciated as I have been struggling with this for quite a while now.
Do you know how I should set these values? Right now, my CANcoders are set to signed minus one half to one half, and I am multiplying the absolute position value of each module by 360 to obtain my offset value. Is this correct?
I also think the wheels are not moving consistently between startups, and I wonder if there is some other code issue.
to set your cancoder offsets you can face your wheels forward, making sure the bevel gear is facing the same direction for all of the wheels, and then measure the cancoder position. when you have that position you can subtract it from your position readings to set forward as your zero
This is actively happening to our team just much more extreme. When we enable the robot the turn motors bounce around like in the video just much more violently.
In code, it seems like the position readings are multiplied by 360 for (I assume) a degrees value, but I’m not actually sure if this is the case and whether ±0.5 is the correct setting vs. the 0-1 setting. I’m setting my offsets as the absolute position value * 360 in my constants file and subtracting them in my getAbsoluteEncoderPosition().
As for the inconsistent behavior, I meant that after I enable teleop, inputting full forwards on my joystick does not always cause the wheels to make the same physical adjustments after making other inputs. For example, if I enable teleop and immediately input full forwards, there will be some reaction from the wheels. If I now make other directional inputs and then input full forwards again, the reaction from the wheels will not be the same as when I first enabled teleop. This is why I was convinced there was some other code issue, but I am using code that @Thor5090 linked above and should apparently work since they are using our exact setup.
Here’s our code if you’re still having the issue. It works great but a few things of note are that we are using PlayStation controllers so you’ll have to adjust for that and our robot is 29.5 inches x 29.5 inches.