|
Re: Efficient Swerve Drive
What we did in 5817's swerve code last year is this:
1) Added a method that lets us feed the wheel a degree value rather than an encoder position value.
2) Let's pretend the wheel is at 30 degrees east of North. If you want to get to 180 degrees South, the code will check and see whether it is faster to go clockwise or counterclockwise to 180.
3) The code then adds 180 to the angle (which in this case will equal 0/360 degrees) and with the two prior values in mind, checks whether it is even faster to go clockwise or counterclockwise to the new angle.
4) Now you have four angles: regular clock and counterclockwise, and reversed clock and counterclockwise.
5) Compare the four values and see which is the shortest and command the wheel to go to that position.
6) If the direction you chose goes to the reversed position, multiply the wheel power output by -1.
Hopefully this helps, I can share the code itself if you would like.
__________________
My FRC History:
2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
|