Go to Post Someone should make FIRST fortune cookies, because I think I just thought of a good one. - artdutra04 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-01-2017, 14:40
mananb mananb is offline
Registered User
FRC #0224
 
Join Date: Oct 2016
Location: Piscataway High School
Posts: 3
mananb is an unknown quantity at this point
Swerve Programming joystick issues

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
Reply With Quote
  #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: 403
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
  #3   Spotlight this post!  
Unread 11-01-2017, 16:27
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Swerve Programming joystick issues

Quote:
Originally Posted by mananb View Post
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.
https://www.chiefdelphi.com/forums/s....php?p=1440383


Reply With Quote
  #4   Spotlight this post!  
Unread 17-01-2017, 13:07
david.e.boles david.e.boles is offline
Bringer of Whales and Petunias
AKA: david476
FRC #5940 (BREAD)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2011
Location: San Francisco, CA
Posts: 30
david.e.boles is on a distinguished road
Re: Swerve Programming joystick issues

It's difficult without your code to give an exact solution, but something like this should work for determining the best direction to rotate (as discussed above):

(W)heel pos: 350
(J)oystick pos: 10

(W-J)%360 = 340 -> bigger than 180, don't turn negative
(J-W)%360 = 20 -> smaller than or = to 180, turn positive!
Reply With Quote
  #5   Spotlight this post!  
Unread 17-01-2017, 15:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Swerve Programming joystick issues

Quote:
Originally Posted by david.e.boles View Post
(W)heel pos: 350
(J)oystick pos: 10

(W-J)%360 = 340 -> bigger than 180, don't turn negative
(J-W)%360 = 20 -> smaller than or = to 180, turn positive!
Could you please explain why you prefer that method rather than using IEEEremainder.



Reply With Quote
  #6   Spotlight this post!  
Unread 18-01-2017, 13:32
david.e.boles david.e.boles is offline
Bringer of Whales and Petunias
AKA: david476
FRC #5940 (BREAD)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2011
Location: San Francisco, CA
Posts: 30
david.e.boles is on a distinguished road
Re: Swerve Programming joystick issues

Mostly inexperience on my part, good point
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:33.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi