hmmm it may be awhile before I get my robot working enough that I can verify my code, but Im fairly sure I didnt make any mistakes. I listed it below if you are willing to beta test it.
To use it, just call cos_SoR(20) or sin_SoR(172) and it will return the answer multiplied by 100 (to avoid floating point math).
For example, if you wanted cos_SoR(20), it will return 94 (its really .94)
You can also do tan_SoR(degrees) which will give an answer multiplied by 10.
Let me know how it goes.
//***********TRIG LOOKUP TABLES**********
//returns a trig sin or cos calculation value multiplied by 100 (to avoid floating point math)
//returns a trig tan calculation value multiplied by 10 (to avoid floating point math)
//only allows for angles between 0 and 360 degrees
//multiplied by 100 so no floating point math
signed int angtable[73]={100,100,98,97,94,91,87,82,77,71,64,57,50,42,34,26,17,9,0,-9,-17,-26,-34,-42,-50,-57,-64,-71,-77,-82,-87,-91,-94,-97,-98,-100,
-100,-100,-98,-97,-94,-91,-87,-82,-77,-71,-64,-57,-50,-42,-34,-26,-17,-9,0,9,17,26,34,42,50,57,64,71,77,82,87,91,94,97,98,100,100};
signed int cos_SoR(long signed int degrees)//returns cos*100
{
if (degrees >= 0)//positive angles
return angtable[degrees/5];
else
return -angtable[72-(-degrees)/5];
}
signed int sin_SoR(long signed int degrees)//returns sin*100
{
degrees=degrees - 90;//phase shift 90 degrees
if (degrees >= 0)//positive angles
return angtable[degrees/5];
else
return -angtable[72-(-degrees)/5];
}
signed int tan_SoR(long signed int degrees)//returns tan * 10
{
//tan(x) = sin(x)/cos(x)
if (degrees == 90 || degrees == -90 || degrees == 270 || degrees == -270)//blows up
return 0;//what else should I return?!?!?
return sin_SoR(degrees)/cos_SoR(degrees)*10;
}
//***************************************