I just took a quick look at the code, but is there anyplace you’re handling the fact that the Falcon’s encoder does not wrap? One rotation is 2048, two rotations is 4096. Link to our code for this.
I’m also not able to find where the conversion from degrees to talon native units happens. This looks like the code is setting the falcon’s encoder with degrees, but I can’t find a coefficient being configured. I’m probably just missing it.
No, we haven’t found a solution, although we haven’t investigated this much further as we have been more focused on other priorities. I was actually just about to bump this thread.
I can’t check now because I don’t have access to a bot. I would recommend running with the debugger attached and putting a break point in the setAngle method and see where the odd value is coming from. What method is passing it down. There may be something odd with initialization order.
My students integrated Brad’s solution and got it working as intended. I’ll post code when I am at a desktop but here’s the gist of it written up by one of our lead programming kids, Arnav:
We passed in the overloaded and original makePositiveDegrees method, the optimizeTurn method, and using make positive degrees in the resetToAbsolute as the example code provided indicated.
We then used optimizeTurn in setAngle in SwerveModule.java and passed in the old angle parameter as getAngle() in SwerveModule.java and did angle = optimizeTurn(getAngle(), angle) before y’all angle in the setAngle function in SwerveModule.java
So far so good. If anything changes we’ll report back here.
Thanks a ton @Bmongar this was a massive headache we were dealing with!
As you can see, I just find the old angle using the getAngle() function and then pass it into optimizeTurn and use the resulting angle as the angle variable in setAngle(). I didn’t see an implementation for optimizeTurn anyways in the solution code provided so I just presumed this was how it was meant to be used. No other changes were made in any other file than SwerveModule.java
Again, every other change we made to SwerveModule.java was exactly as documented in the solution code. You can view it all in the repository and file linked above.
Thanks for the solution again, really appreciate it!
We didn’t add the optimizeTurn function since our understanding is that the CTREModuleState.optimize function from 364’s base code takes care of the angle optimization. We’ll try @Bmongar’s optimizeTurn and your setAngle modifications. Unfortunately our meeting for tonight has been canceled due to weather, so it’ll have to wait until Thursday.