/* calcul.c */ /* Accelerometre {{{ * * Copyright (C) 2004 Thomas Burg * * Robot APB Team/Efrei 2005. * Web: http://assos.efrei.fr/robot/ * Email: robot AT efrei DOT fr * * This program 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; either version 2 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 * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ #include "calcul.h" #include /* +AutoDec */ /* -AutoDec */ uint16_t T2_cal; uint16_t T1x_cal; uint16_t T1y_cal; uint32_t K; volatile enum T_etat etat; int16_t G0x; int16_t G0y; void calibration(void) { uint16_t i = 0; uint32_t T1x = 0; uint32_t T1y = 0; uint32_t T2c = 0; while (i < 1024 ) { if( etat == calcul) { T1x += Tb; T1y += Td - Tc; //T2 += (Td - (Td - Tc)/2) - Tb/2; T2c += (Td + Tc - Tb) /2; i++; etat = strt_at_Ta; } } T2_cal = T2c / 1024; T1x_cal = T1x / 1024; T1y_cal = T1y / 1024; K = (uint16_t)((uint32_t)( 4 * ( T2_cal * BIT_SCALE_FACTOR) / T2_cal)); Vx = 0; Vy = 0; } int16_t calculG ( uint16_t T1, uint16_t T2, int16_t Go) { /*uint32_t Zactual; Zactual = Zcal * T2 / T2_cal; return ( (int16_t) K * (int16_t)( T1 - Zactual) / (int16_t)T2); */ return (K * T1) / T2 - Go ; } int16_t calculGb(uint16_t T1, uint16_t T2, uint16_t T1cal) { int32_t Zactual = T1cal * T2 / T2_cal; int32_t Gtmp = K * (T1 - Zactual); int16_t G = Gtmp / T2; return G; }