//#include /************************************************************************* Autor: David Sánchez Datum: 06.10.06 Funktion: calculate the atan and convert to our specifications Variablen: double U1 and U2: value from the ADC (sine and cosine) *************************************************************************/ /* float calc_atan(double U1, double U2) { float fAlfa; fAlfa=57.2957795*atan(U1/U2); // calculate the angle with the atan function (math.h) if (U2<0) // if the cosine is <0 then we add 180 degrees { fAlfa = fAlfa + 180; // then we add 180 degrees } if (U1<0) // if the sine is <0 { if (U2>0) // and the cosine is >0 { fAlfa = fAlfa + 360; // then we add 360 degrees } } return fAlfa; } */ /************************************************************************* Autor: David Sánchez Datum: 27.10.06 Funktion: calculate the atan and convert to our specifications Variablen: signed int U1 and U2: value from the ADC (sine and cosine) *************************************************************************/ #define Fall0 0 // We are always working in the first 22.5 degrees #define Fall1 1 // later we will transform the angles #define Fall2 3 #define Fall3 2 #define Fall4 6 #define Fall5 7 #define Fall6 5 #define Fall7 4 #define invU1 4 #define invU2 2 #define changeU1U2 1 float atanGreen (signed long U1, signed long U2) { char cFall=0; float fZaehler; float fNenner; float fArg; float fAlfa; cFall=0; if (U1<0) // if Sine<0 { U1=-U1; // positive Sine cFall+=invU1; } if (U2<0) // if Cosine<0 { U2=-U2; // positive Cosine cFall+=invU2; } if (U1>U2) // if Sine > Cosine { fZaehler = U2; // Numerator = U2 fNenner = U1; // Denominator = U1 cFall+= changeU1U2; } else { fZaehler = U1; // Numerator = U1 fNenner = U2; // Denominator = U2 } fArg = (fZaehler / fNenner); // function argument if (fArg <= 0.125) // look-up table { fAlfa = (0.9974133042 * fArg) * 57.2957795; } else if (fArg <= 0.250) { fAlfa = (0.004072621 + (0.964989344 * fArg)) * 57.2957795; } else if (fArg <= 0.375) { fAlfa = (0.017899968 + (0.910336056 * fArg)) * 57.2957795; } else if (fArg <= 0.5) { fAlfa = (0.044740546 + (0.839015512 * fArg)) * 57.2957795; } else if (fArg <= 0.625) { fAlfa = (0.084473784 + (0.759613648 * fArg)) * 57.2957795; } else if (fArg <= 0.75) { fAlfa = (0.134708924 + (0.679214352 * fArg)) * 57.2957795; } else if (fArg <= 0.875) { fAlfa = (0.192103293 + (0.602631128 * fArg)) * 57.2957795; } else if (fArg <= 1) { fAlfa = (0.253371504 + (0.532545304 * fArg)) * 57.2957795; } switch(cFall) { case Fall1: // to transform the angles into the real ones return 90-fAlfa; case Fall2: return 90+fAlfa; case Fall3: return 180-fAlfa; case Fall4: return 180+fAlfa; case Fall5: return 270-fAlfa; case Fall6: return 270+fAlfa; case Fall7: return 360-fAlfa; } return fAlfa; } e-REdING. Biblioteca de la Escuela Superior de Ingenieros de Sevilla.


DESEÑO Y DESARROLLO DE SISTEMA PARA MEDIDA DE LA INCLINACIÓN Y ROTACIÓN

: Sánchez Padilla, David
: Ingeniería Telecomunicación
Contenido del proyecto:
Directorio raíz  >  Anexos  >  KMS  >  atan.c