Quote:
Originally Posted by kinganu123
For example, i was trying to figure out how i would get the left motors to stay off and the right motors to stay full on when the joystick is at teh top left corner(X,Y) = (-1,1), and see if that code works for all quadrants. I used y+X for the left wheels and Math.max(X,Y) for the right wheels. However that algorithim doesnt work for all four quadrants so Ive made a big branching if-else so I have a different algorithim for each quadrant of the cartesian plane and another if else for if the joystick is on the x or y axis
|
Try this: Use L=Y+X and R=Y-X.
Then limit L and R to the range -1..+1. Spoiler hint at bottom.
If you do this, you should get these values:
Code:
X Y L R
0 1 1 1
1 1 1 0
1 0 1 -1
1 -1 0 -1
0 -1 -1 -1
-1 -1 -1 0
-1 0 -1 1
-1 1 0 1
The above table matches
this diagram.
If the above table is not the result you are seeking, post a table showing the result you want.
Warning: spoiler follows:
Hint:
for limiting (clipping), do this:
if(L>1) L=1; else if(L<-1) L=-1;
if(R>1) R=1; else if(R<-1) R=-1;
instead of clipping, you could normalize instead. you'll still get the same table as above, but intermediate joystick results will be slightly different:
max=fabs(L); if(fabs(R)>max) max=fabs(R);
if(max>1){ L/=max; R/=max;}
if you want to get the exact same results as the WPI library functions for all intermediate joystick settings, a slightly different algorithm will be necessary... but still no trig required.