2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
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.
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.
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.
18 #include "ao-fakeflight.h"
20 char *state_name[] = {
21 [state_ascent] = "ascent",
22 [state_drogue] = "drogue",
23 [state_main] = "main",
24 [state_landed] = "landed",
27 struct rocket o5778 = {
47 .average_thrust = 5778.0,
53 .average_thrust = 5778.0,
54 .burn_time = 0, /* 17.04 */
60 struct rocket n5778 = {
80 .average_thrust = 5778.0,
88 * Move the flight one tick forward
91 step(struct flight *f, struct rocket *r)
93 double drag = rocket_drag(f, r);
94 double thrust = rocket_thrust(f, r);
95 double gravity = rocket_gravity(f, r);
96 double mass = rocket_mass(f, r);
99 /* This is our acceleration relative to the earth */
100 accel = (drag + thrust - gravity) / mass;
102 /* Because the accelerometer is also affected by gravity, it
103 * only measures *other* forces applied to the rocket
105 f->accel = (drag + thrust) / mass;
107 f->altitude += f->speed * STEP + 0.5 * (accel * STEP) * (accel * STEP);
108 f->speed += accel * STEP;
113 init(struct flight *f, struct rocket *r)
115 double gravity = rocket_gravity(f, r);
117 /* The pad is pushing up on the rocket to counter
118 * gravity, so the accelerometer, which only measures
119 * forces other than gravity, sees only this
121 f->accel = gravity / rocket_mass(f, r);
128 fly(FILE *file, struct rocket *r)
135 .state = state_ascent,
138 double max_speed = 0;
140 double max_accel = 0;
143 ao_show_header(file, r);
148 while (f.altitude >= 0) {
154 f.state = state_drogue;
157 if (f.altitude > o5778.main_deploy)
159 f.state = state_main;
165 max_speed = fmax(max_speed, f.speed);
166 max_accel = fmax(max_accel, f.accel);
167 max_alt = fmax(max_alt, f.altitude);
169 fprintf(stderr, "max alt %9.1f speed %9.1f accel %9.1f\n",
170 max_alt, max_speed, max_accel);
174 main(int argc, char **argv)
177 // fly(stdout, &n5778);