2 * Copyright © 2011 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; either version 2 of the License, or
7 * (at your option) any later version.
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.
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.
19 package org.altusmetrum.micropeak;
22 import org.altusmetrum.altoslib_11.*;
23 import org.altusmetrum.altosuilib_11.*;
25 public class MicroStats {
43 for (MicroDataPoint point : data.points()) {
44 landed_height = point.height;
45 landed_time = point.time;
48 boolean above = false;
49 for (MicroDataPoint point : data.points()) {
50 if (point.height > landed_height + 10) {
53 if (above && point.height < landed_height + 2) {
55 landed_time = point.time;
62 apogee_height = data.apogee_height();
63 double searched_apogee = 0;
66 /* This just finds the apogee time -- we've recorded the
67 * peak altitude separately in eeprom, and that could
68 * have occurred after the eeprom was full.
70 for (MicroDataPoint point : data.points()) {
71 if (point.height > searched_apogee) {
72 searched_apogee = point.height;
73 apogee_time = point.time;
82 for (MicroDataPoint point : data.points()) {
83 if (point.accel < -9.8)
85 coast_time = point.time;
86 coast_height = point.height;
90 void find_max_speed() {
92 for (MicroDataPoint point : data.points()) {
93 if (point.time > apogee_time)
95 if (point.speed > max_speed)
96 max_speed = point.speed;
100 void find_max_accel() {
102 for (MicroDataPoint point : data.points()) {
103 if (point.time > apogee_time)
105 if (point.accel > max_accel)
106 max_accel = point.accel;
110 double boost_duration() {
114 double boost_height() {
118 double boost_speed() {
119 return coast_height / coast_time;
122 double boost_accel() {
123 return boost_speed() / boost_duration();
126 double coast_duration() {
127 return apogee_time - coast_time;
130 double coast_height() {
131 return apogee_height - coast_height;
134 double coast_speed() {
135 return coast_height() / coast_duration();
138 double coast_accel() {
139 return coast_speed() / coast_duration();
142 double descent_duration() {
143 return landed_time - apogee_time;
146 double descent_height() {
147 return apogee_height - landed_height;
150 double descent_speed() {
151 return descent_height() / descent_duration();
154 public static final int state_startup = -1;
155 public static final int state_pad = 0;
156 public static final int state_boost = 1;
157 public static final int state_coast = 2;
158 public static final int state_descent = 3;
159 public static final int state_landed = 4;
161 static final String state_names[] = {
169 public int state(double t) {
170 if (t >= landed_time)
172 if (t >= apogee_time)
173 return state_descent;
181 public static String state_name(int state) {
182 if (state < 0 || state > state_landed)
184 return state_names[state];
187 public String state_name(double t) {
188 return state_name(state(t));
191 public MicroStats(MicroData data) {
202 public MicroStats() {
203 this(new MicroData());