altos: Have MicroKite just start recording at startup
[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 /* 64 sample, or about six seconds worth */
24 #define GROUND_AVG_SHIFT        6
25 #define GROUND_AVG              (1 << GROUND_AVG_SHIFT)
26
27 /* Pressure change (in Pa) to detect boost */
28 #ifndef BOOST_DETECT
29 #define BOOST_DETECT            360     /* 30m at sea level, 36m at 2000m */
30 #endif
31
32 #ifndef LOG_INTERVAL
33 #define LOG_INTERVAL             2      /* 192 ms */
34 #endif
35
36 #define AO_LOG_ID_MICROPEAK     0
37 #define AO_LOG_ID_MICROKITE     1
38
39 #ifndef AO_LOG_ID
40 #define AO_LOG_ID               AO_LOG_ID_MICROPEAK
41 #endif
42
43 /* Wait after power on before doing anything to give the user time to assemble the rocket */
44 #ifndef BOOST_DELAY
45 #define BOOST_DELAY             AO_SEC_TO_TICKS(60)
46 #endif
47
48 /* Pressure change (in Pa) to detect landing */
49 #define LAND_DETECT             24      /* 2m at sea level, 2.4m at 2000m */
50
51 /* Current sensor pressure value */
52 extern uint32_t pa;
53
54 /* Average pressure value on ground */
55 extern uint32_t pa_ground;
56
57 /* Minimum recorded filtered pressure value */
58 extern uint32_t pa_min;
59
60 /* Pressure values converted to altitudes */
61 extern alt_t    ground_alt, max_alt;
62
63 /* max_alt - ground_alt */
64 extern alt_t    ao_max_height;
65
66 void
67 ao_pa_get(void);
68
69 void
70 ao_microflight(void);
71
72 #define ACCEL_LOCK_PA           -20
73 #define ACCEL_LOCK_TIME         10
74
75 extern uint32_t ao_k_pa;                /* 24.8 fixed point */
76 extern int32_t  ao_k_pa_speed;          /* 16.16 fixed point */
77 extern int32_t  ao_k_pa_accel;          /* 16.16 fixed point */
78
79 extern uint32_t ao_pa;                  /* integer portion */
80 extern int16_t  ao_pa_speed;            /* integer portion */
81 extern int16_t  ao_pa_accel;            /* integer portion */
82
83 void
84 ao_microkalman_init(void);
85
86 void
87 ao_microkalman_predict(void);
88
89 void
90 ao_microkalman_correct(void);
91         
92 #endif
93