View Single Post
  #2   Spotlight this post!  
Unread 11-01-2017, 14:59
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 409
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
Re: Swerve Programming joystick issues

Quote:
Originally Posted by mananb View Post
Hi,
Our team is planning on using a swerve drive train this year. We currently have 1 module (steer motor and drive motor) set up as a prototype. We are using CANTalons and CTRE absolute magnetic encoders.

The problem I am encountering while programming is that the joystick position wraps from 360 to 0, causing the wheel to pivot the long way around. For example, if the joystick and the wheel are at 350 degrees and the joystick is moved to 10 degrees, the wheel would take the long way all around. Is there any way to fix this issue?

Thanks
For our swerve code, for every degree position we give the module, it calculates whether it is faster to go clockwise or counterclockwise, and goes the shorter way. However, we are using relative CTRE encoders. Here's an example:

Let's pretend that we are using a relative encoder where 100 ticks = 1 degree. If the wheel is at 10 degrees and wants to go to 350, it finds it faster to go counter-clockwise and chooses that path. The difference here would be -20 degrees. Then it takes the starting position in ticks, and subtracts the tick equivalent of 20 degrees, or 2000 ticks in this case. So, 1000 (starting position) - 2000 (calculated shorter distance) = -1000 (new position).

TL;DR do the math on which direction to turn is faster, and do that. This would probably be easier if you used relative encoder mode. Swerve gets more complex if you allow the drive to go to the angle of reverse and flip its output.

That may not have been the best explanation ever, so if you need me to explain this differently, just ask.
__________________
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
2017 - Team 5817: Return of the bench grinder


Reply With Quote