summaryrefslogtreecommitdiff
path: root/n/accel/calcul.c
blob: 1623c858423e8931e57c7648587d7d0090363c7e (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
86
87
88
89
90
91
92
93
94
/* 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;
}