ao-tools: Add ao-fakeflight
[fw/altos] / ao-tools / ao-fakeflight / ao-fakeflight.h
1 /*
2  * Copyright © 2014 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_FAKEFLIGHT_H_
19 #define _AO_FAKEFLIGHT_H_
20
21 #define __xdata
22 #include <stdint.h>
23 #include <ao_ms5607.h>
24 #include <math.h>
25 #include <stdio.h>
26 #include "cc.h"
27
28 #define GAS_CONSTANT            287.05
29 #define STEP                    0.01
30 #define GRAVITATIONAL_CONSTANT  6.67384e-11
31 #define GRAVITY                 9.807
32 #define EARTH_MASS              5.9726e24
33 #define EARTH_RADIUS            6375313
34
35 enum flight_state {
36         state_ascent,
37         state_drogue,
38         state_main,
39         state_landed,
40         state_num
41 };
42
43 extern char *state_name[];
44
45 struct model {
46         double  cd;
47         double  diameter;
48 };
49
50 struct motor {
51         double  fuel_mass;
52         double  average_thrust;
53         double  burn_time;
54         double  delay;
55 };
56
57 #define MAX_MOTORS      12
58
59 struct rocket {
60         struct model    models[state_num];
61         double          empty_mass;
62         double          main_deploy;
63         struct motor    motors[MAX_MOTORS];
64 };
65
66 /* Flight state */
67
68 struct flight {
69         double  time;
70         double  altitude;
71         double  speed;
72         double  accel;
73         enum flight_state       state;
74 };
75
76 /* ao-physics.c */
77
78 /* Density of dry air in kg/m³ for a given pressure and temperature. */
79 /* Density of dry air in kg/m³ for a given pressure and temperature. */
80 double
81 density_air(double pressure,            /* Pa */
82             double temperature);        /* °C */
83
84 /* Area of a circle */
85 double
86 area_circle(double diameter);
87
88 /* Force due to drag (N) */
89 double
90 force_drag(double       speed,          /* m/s */
91            double       rho,            /* kg/m³ */
92            double       cd,             /* unitless */
93            double       area);          /* m² */
94
95 /* Force due to gravity (N) */
96 double
97 force_gravity(double    mass,           /* kg */
98               double    altitude);      /* m */
99
100 /* ao-rocket.c */
101
102 /* Mass (kg) of the airframe */
103 double
104 rocket_mass(struct flight *f, struct rocket *r);
105
106 /* Force (N) due to thrust */
107 double
108 rocket_thrust(struct flight *f, struct rocket *r);
109
110 /* Drag (N) due to air resistance */
111 double
112 rocket_drag(struct flight *f, struct rocket *r);
113
114 /* Force (N) due to gravity */
115 double
116 rocket_gravity(struct flight *f, struct rocket *r);
117
118 /* ao-fake-convert.c */
119 void
120 ao_ms5607_unconvert(double altitude,
121                     struct ao_ms5607_sample *ret);
122
123 int16_t
124 ao_accel_unconvert(double accel);
125
126 void
127 ao_show_header(FILE *f, struct rocket *r);
128
129 /* ao-fake-log.c */
130
131 void
132 ao_log_flight(FILE *file, struct flight *f, struct rocket *r);
133
134 void
135 ao_log_sensor(FILE *file, struct flight *f, struct rocket *r);
136
137 void
138 ao_log_state(FILE *file, struct flight *f, struct rocket *r);
139
140 #endif