We have been using Talon SRXs to control our swerve drive that’s in development. For clarity “turn” will refer to the angle of the wheel, and “spin” will refer to the velocity. While attempting to turn the wheel past the 1023 limit, instead of continuing past 1023, the Talon will return to a point in the 0-1023 interval. I am currently using an Analog Encoder with the Talon in the Position closed-loop mode.
To attempt to solve this problem, I converted the encoder signal into an equivalent degree value, processed it to get my new setpoint, and then converted it back to a 0-1023 value in the same interval that the encoder is in. I believe my problem lies in the red boxed area of my code, but I could very easily be wrong. Any help is appreciated, and I will provide any additional information if needed.
When “Analog Encoder” is selected the wraparound is tracked (1023 => 1024). It sounds like "Analog Potentiometer " is instead selected (so 1023 => back to 0).
Can you grab a self-test screenshot as you manually rotate (or just straight drive) the swerve module using the RIO web based config? That will tell us what the reported sensor position is before and after the wraparound and confirm the selected feedback device.
The POS value did as expected and went past 1023. Your code appears to be throwing away the overflow and trying to limit everything to a single rotation.
Don’t do that. Just add to or subtract from the current setpoint, without worrying about going “too far” in any direction.
Cool so the Talon SRX, and sensor are working as expected.
So if you want to do servo to the closest degree, what I’d recommend is taking a look at the google sheet below. Basically the strategy is to input the current sensor position (could be anything) and the target-desired angle (expressed in sensor units from 0 to 1023). The output is the final full position to send to the Talon to servo to. The middle columns will calc the distance to the target in both directions, and then chooses the smaller distance. Looks like this is what’s attempted in your VI, but it’s hard to follow because there is a lot going on.
hah, Levi you emailed me the same question so I guess this post is redundant, but figured posting this on CD helps everybody.
Zebracorn’s (FRC900) followed this strategy last year and it seemed to work well. For anyone interested in looking at an LV implementation I would check out their github (2015 FRC code base).
Google sheet. Make a copy into your google drive or download as excel so you can edit.