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; 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 package org.altusmetrum.micropeak;
21 import org.altusmetrum.altoslib_4.*;
22 import org.altusmetrum.altosuilib_2.*;
24 public class MicroStats {
42 for (MicroDataPoint point : data.points()) {
43 landed_height = point.height;
44 landed_time = point.time;
47 boolean above = false;
48 for (MicroDataPoint point : data.points()) {
49 if (point.height > landed_height + 10) {
52 if (above && point.height < landed_height + 2) {
54 landed_time = point.time;
61 apogee_height = data.apogee_height();
62 double searched_apogee = 0;
65 /* This just finds the apogee time -- we've recorded the
66 * peak altitude separately in eeprom, and that could
67 * have occurred after the eeprom was full.
69 for (MicroDataPoint point : data.points()) {
70 if (point.height > searched_apogee) {
71 searched_apogee = point.height;
72 apogee_time = point.time;
81 for (MicroDataPoint point : data.points()) {
82 if (point.accel < -9.8)
84 coast_time = point.time;
85 coast_height = point.height;
89 void find_max_speed() {
91 for (MicroDataPoint point : data.points()) {
92 if (point.time > apogee_time)
94 if (point.speed > max_speed)
95 max_speed = point.speed;
99 void find_max_accel() {
101 for (MicroDataPoint point : data.points()) {
102 if (point.time > apogee_time)
104 if (point.accel > max_accel)
105 max_accel = point.accel;
109 double boost_duration() {
113 double boost_height() {
117 double boost_speed() {
118 return coast_height / coast_time;
121 double boost_accel() {
122 return boost_speed() / boost_duration();
125 double coast_duration() {
126 return apogee_time - coast_time;
129 double coast_height() {
130 return apogee_height - coast_height;
133 double coast_speed() {
134 return coast_height() / coast_duration();
137 double coast_accel() {
138 return coast_speed() / coast_duration();
141 double descent_duration() {
142 return landed_time - apogee_time;
145 double descent_height() {
146 return apogee_height - landed_height;
149 double descent_speed() {
150 return descent_height() / descent_duration();
153 public static final int state_startup = -1;
154 public static final int state_pad = 0;
155 public static final int state_boost = 1;
156 public static final int state_coast = 2;
157 public static final int state_descent = 3;
158 public static final int state_landed = 4;
160 static final String state_names[] = {
168 public int state(double t) {
169 if (t >= landed_time)
171 if (t >= apogee_time)
172 return state_descent;
180 public static String state_name(int state) {
181 if (state < 0 || state > state_landed)
183 return state_names[state];
186 public String state_name(double t) {
187 return state_name(state(t));
190 public MicroStats(MicroData data) {
201 public MicroStats() {
202 this(new MicroData());