doc: Add 1.9.18 release notes
[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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_MICROPEAK_H_
20 #define _AO_MICROPEAK_H_
21
22 #ifndef SAMPLE_SLEEP
23 #define SAMPLE_SLEEP            AO_MS_TO_TICKS(96)
24 #endif
25
26 /* 64 sample, or about six seconds worth */
27 #define GROUND_AVG_SHIFT        6
28 #define GROUND_AVG              (1 << GROUND_AVG_SHIFT)
29
30 /* Pressure change (in Pa) to detect boost */
31 #ifndef BOOST_DETECT
32 #define BOOST_DETECT            360     /* 30m at sea level, 36m at 2000m */
33 #endif
34
35 #ifndef LOG_INTERVAL
36 #define LOG_INTERVAL             2      /* 192 ms */
37 #endif
38
39 #define AO_LOG_ID_MICROPEAK     0
40 #define AO_LOG_ID_MICROKITE     1
41 #define AO_LOG_ID_MICROPEAK2    2
42
43 #ifndef AO_LOG_ID
44 #define AO_LOG_ID               AO_LOG_ID_MICROPEAK
45 #endif
46
47 /* Wait after power on before doing anything to give the user time to assemble the rocket */
48 #ifndef BOOST_DELAY
49 #define BOOST_DELAY             AO_SEC_TO_TICKS(60)
50 #endif
51
52 /* Pressure change (in Pa) to detect landing */
53 #define LAND_DETECT             24      /* 2m at sea level, 2.4m at 2000m */
54
55 /* Current sensor pressure value */
56 extern uint32_t pa;
57
58 /* Average pressure value on ground */
59 extern uint32_t pa_ground;
60
61 /* Minimum recorded filtered pressure value */
62 extern uint32_t pa_min;
63
64 /* Pressure values converted to altitudes */
65 extern alt_t    ground_alt, max_alt;
66
67 /* max_alt - ground_alt */
68 extern alt_t    ao_max_height;
69
70 void
71 ao_pa_get(void);
72
73 void
74 ao_microflight(void);
75
76 #define ACCEL_LOCK_PA           -20
77 #define ACCEL_LOCK_TIME         10
78
79 extern uint32_t ao_k_pa;                /* 24.8 fixed point */
80 extern int32_t  ao_k_pa_speed;          /* 16.16 fixed point */
81 extern int32_t  ao_k_pa_accel;          /* 16.16 fixed point */
82
83 extern uint32_t ao_pa;                  /* integer portion */
84 extern int16_t  ao_pa_speed;            /* integer portion */
85 extern int16_t  ao_pa_accel;            /* integer portion */
86
87 void
88 ao_microkalman_init(void);
89
90 void
91 ao_microkalman_predict(void);
92
93 void
94 ao_microkalman_correct(void);
95         
96 #endif
97