/* 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" /* +AutoDec */ /* -AutoDec */ uint16_t T2_cal; uint16_t T1x_cal; uint16_t T1y_cal; uint32_t K; void calibration(void) { mode =1; uint32_t i = 0; uint32_t T2c = 0; while (i < 32768) { if( etat == record_T2_x) { T2c += T2x; i++; } } T2x = T2c / 32768; i=0; T2c = 0; ACSR |= 0x04; //change d'entrée : analogue comparator mode=2; while (i < 32768) { if( etat == record_T2_y) { T2c += T2y; i++; } } ACSR &= ~0x04; //change d'entrée : IPC T2y = T2c / 32768; T2 = (T2x+T2y)/2; mode = 0; uint8_t j = 0; while (j==0) { if(calcul_rdy == 1) { T1x_cal = Tx; T1y_cal = Ty; j++; } } K = BIT_SCALE_FACTOR * 8 / T2; Vx = 0; Vy = 0; } int16_t calculG ( uint16_t T1, uint16_t T1_cal) { return (T1 - T1_cal) * K ; } 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; }