My team has this code that we are using for swerve drive. we have worked out all the bugs and everything works except actually turning to the correct position. The wheels go to the position that the math told them too(we got the swerve math online). Although the wheel are going to the position we told them too, they don’t swerve. They all point in different directions. I think it may have something to do with the math, and or converting units. I have seem to have hit a wall and would appreciate any help. Thanks in advance. I decided to link my Github as this is where we store our code form meeting to meeting. The names of the files are pretty self explanatory. The math portion is held within https://github.com/Mattbenfield9755/Robot-Code-2021/tree/main/src/main/cpp/SwerveMath.cpp.
If you tell all of the modules to go to 0 do they hold position?
The first diagnostic I’d do would be sync all the wheels and tell them to hold 0 normally and on button press go to 45 degrees. If that works it’s something in your kinematics math. If not, it’s further upstream. (Mostly posting this as general diagnostic, it sounds like you’ve gotten past this)
You’re not setting up encoders very much, it’s been a while so idk what the default values are but that might be causing issues as well.
Another thought would be that you probably need to convert back from your internal angle to encoder ticks. Right now it looks like you’re setting the PID to to a value between -0.5 and 0.5 but the encoder isn’t in those terms.
Ok thank you for the problem diagnostic. I will try setting them all the go to the same position. When we initially start the program they all point in different directions. I may have to zero them all like you said.
Oh, most certainly. If I’m reading your code correctly you’re using quadrature encoders, this means that they don’t have a known zero and all moves are relative to where they were initialized. This is why most swerves use an absolute encoder, though a few have used some sort of limit switch as a zeroing sensor.
We were discussing during initialization we would have the motors turn till they hit a limit switch and that would zero them out.
Yes, that is an approach that has been used. Be aware that you’ll have to monitor for brownouts on the controller which could reset that zero mid match.
Very true, thanks for the help.
Note that as far as detecting brownout conditions, it looks like you’re using TalonSRXs. In which case I believe they have a sticky bit fault that will get set if the controller loses power, and comes back online, during a match. You could poll for that.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.