View Single Post
  #12   Spotlight this post!  
Unread 22-03-2011, 11:05
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,070
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 drive with automatic rotation?

Quote:
Originally Posted by Chexposito View Post
we also had to create a function that converted the counts from 0 to 360 no matter what the count. then a pass that into another function that decided the closest way to get to the heading determined by the joystick. then had to do vector addition from the joystick to create ... a degree for the heading.
Since you are a programmer you may be interested in this. The following 2 lines of C code will do everything mentioned above. Try it with any gyro angle (positive, negative, greater than 360, etc) and any Joystick coordinates:

Code:
error = atan2(Xj,-Yj)*180/pi - gyroAngle;

error = error-360*floor(0.5+error/360);
"Xj,Yj" are the "uncorrected" joystick coordinates (Yj = -1 is full forward)

"gyroAngle" is in degrees clockwise

"error" is the clockwise angle error in degrees. It is the shortest path to the target.




Last edited by Ether : 22-03-2011 at 11:08.