summaryrefslogtreecommitdiff
path: root/n/accel/calcul.c
blob: aeff53403c4cccca0265089105ece189cdc44615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* 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 <inttypes.h>

/* +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;
}