altos: Move micropeak sources around
[fw/altos] / src / product / ao_micropeak.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_MICROPEAK_H_
19 #define _AO_MICROPEAK_H_
20
21 #define SAMPLE_SLEEP            AO_MS_TO_TICKS(96)
22
23 /* 16 sample, or about two seconds worth */
24 #define GROUND_AVG_SHIFT        4
25 #define GROUND_AVG              (1 << GROUND_AVG_SHIFT)
26
27 /* Pressure change (in Pa) to detect boost */
28 #define BOOST_DETECT            120     /* 10m at sea level, 12m at 2000m */
29
30 /* Wait after power on before doing anything to give the user time to assemble the rocket */
31 #define BOOST_DELAY             AO_SEC_TO_TICKS(60)
32
33 /* Pressure change (in Pa) to detect landing */
34 #define LAND_DETECT             24      /* 2m at sea level, 2.4m at 2000m */
35
36 /* Current sensor pressure value */
37 extern uint32_t pa;
38
39 /* Average pressure value on ground */
40 extern uint32_t pa_ground;
41
42 /* Minimum recorded filtered pressure value */
43 extern uint32_t pa_min;
44
45 /* Pressure values converted to altitudes */
46 extern alt_t    ground_alt, max_alt;
47
48 /* max_alt - ground_alt */
49 extern alt_t    ao_max_height;
50
51 void
52 ao_pa_get(void);
53
54 void
55 ao_microflight(void);
56
57 #define ACCEL_LOCK_PA           -20
58 #define ACCEL_LOCK_TIME         10
59
60 extern uint32_t ao_k_pa;                /* 24.8 fixed point */
61 extern int32_t  ao_k_pa_speed;          /* 16.16 fixed point */
62 extern int32_t  ao_k_pa_accel;          /* 16.16 fixed point */
63
64 extern uint32_t ao_pa;                  /* integer portion */
65 extern int16_t  ao_pa_speed;            /* integer portion */
66 extern int16_t  ao_pa_accel;            /* integer portion */
67
68 void
69 ao_microkalman_init(void);
70
71 void
72 ao_microkalman_predict(void);
73
74 void
75 ao_microkalman_correct(void);
76         
77 #endif
78