Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 255 → Rev 256

/branches/v0.60_MicroMag3_Nick666/math.c
1,10 → 1,13
/*
 
Copyright 2007, Niklas Nold
 
This program (files math.c and math.h) is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software Foundation;
it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. You should have received a copy of the GNU General Public License
GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
Please note: All the other files for the project "Mikrokopter" by H.Buss are under the license (license_buss.txt) published by www.mikrokopter.de
12,40 → 15,6
 
#include "main.h"
 
/*
//-----------------------------------------------
// Fast arctan2 with max error of .07 rads
// http://www.dspguru.com/comp.dsp/tricks/alg/fxdatan2.htm
//-----------------------------------------------
signed int arctan_f(signed int x, signed int y)
{
float rad,r;
short int m;
#define coeff_1 0.7854
#define coeff_2 2.3562
#define rad2grad 57.2958
if (!x && !y) return 0;
if (y < 0) {y = abs(y); m = -1;}
else m = 1;
if (x>=0)
{
r = (float)(x - y) / (float)(x + y);
rad = coeff_1 - coeff_1*r;
}
else
{
r = (float)(x + y) / (float)(y - x);
rad = coeff_2 - coeff_1*r;
}
rad *= rad2grad;
return(rad*m);
}
*/
 
const uint8_t pgm_atan[270] PROGMEM = {0,1,2,3,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,27,28,29,30,31,32,33,33,34,35,36,37,37,38,39,39,40,41,41,42,43,43,44,44,45,46,46,47,47,48,48,49,49,50,50,51,51,52,52,52,53,53,54,54,54,55,55,56,56,56,57,57,57,58,58,58,59,59,59,60,60,60,60,61,61,61,61,62,62,62,62,63,63,63,63,64,64,64,64,65,65,65,65,65,66,66,66,66,66,67,67,67,67,67,67,68,68,68,68,68,68,69,69,69,69,69,69,69,70,70,70,70,70,70,70,70,71,71,71,71,71,71,71,71,72,72,72,72,72,72,72,72,72,73,73,73,73,73,73,73,73,73,73,74,74,74,74,74,74,74,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,75,76,76,76,76,76,76,76,76,76,76,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79,79};
 
132,40 → 101,3
 
return (sinus*m*n);
}
 
 
/*
 
const unsigned int pgm_sinus[91] PROGMEM = {0,17,35,52,70,87,105,122,139,156,174,191,208,225,242,259,276,292,309,326,342,358,375,391,407,423,438,454,469,485,500,515,530,545,559,574,588,602,616,629,643,656,669,682,695,707,719,731,743,755,766,777,788,799,809,819,829,839,848,857,866,875,883,891,899,906,914,921,927,934,940,946,951,956,961,966,970,974,978,982,985,988,990,993,995,996,998,999,999,1000,1000};
 
// cosinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =cos(winkel)*1000
signed int cos_i(signed int winkel)
{
return (sin_i(90-winkel));
}
 
// sinus Funktion: Eingabewert Winkel in Grad, Rueckgabe =sin(winkel)*1000
signed int sin_i(signed int winkel)
{
short int m,n;
//winkel = winkel % 360;
if (winkel < 0)
{
m = -1;
winkel = abs(winkel);
}
else m = +1;
// Quadranten auswerten
if ((winkel > 90 ) && (winkel <= 180)) {winkel = 180 - winkel; n = 1;}
else if ((winkel > 180 ) && (winkel <= 270)) {winkel = winkel - 180; n = -1;}
else if ((winkel > 270) && (winkel <= 360)) {winkel = 360 - winkel; n = -1;}
else n = 1; //0 - 90 Grad
 
winkel = pgm_read_word(&pgm_sinus[winkel]);
 
return (winkel*m*n);
}
*/