2 * Copyright © 2010 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.
19 * Track flight state from telemetry or eeprom data stream
22 package org.altusmetrum.altoslib_5;
24 public class AltosState implements Cloneable {
26 public static final int set_position = 1;
27 public static final int set_gps = 2;
28 public static final int set_data = 4;
32 static final double ascent_filter_len = 0.5;
33 static final double descent_filter_len = 0.5;
37 public long received_time;
40 public double prev_time;
41 public double time_change;
43 private int prev_tick;
44 public int boost_tick;
48 private double prev_value;
49 private double max_value;
50 private double set_time;
51 private double prev_set_time;
53 boolean can_max() { return true; }
55 void set(double new_value, double time) {
56 if (new_value != AltosLib.MISSING) {
58 if (can_max() && (max_value == AltosLib.MISSING || value > max_value))
64 void set_filtered(double new_value, double time) {
65 if (prev_value != AltosLib.MISSING)
66 new_value = (prev_value * 15.0 + new_value) / 16.0;
83 if (value != AltosLib.MISSING && prev_value != AltosLib.MISSING)
84 return value - prev_value;
85 return AltosLib.MISSING;
90 double t = set_time - prev_set_time;
92 if (c != AltosLib.MISSING && t != 0)
94 return AltosLib.MISSING;
98 if (value == AltosLib.MISSING)
99 return AltosLib.MISSING;
100 if (prev_value == AltosLib.MISSING)
101 return AltosLib.MISSING;
103 return (value + prev_value) / 2 * (set_time - prev_set_time);
110 void set_derivative(AltosValue in) {
111 double n = in.rate();
113 if (n == AltosLib.MISSING)
116 double p = prev_value;
117 double pt = prev_set_time;
119 if (p == AltosLib.MISSING) {
121 pt = in.time() - 0.01;
124 /* Clip changes to reduce noise */
125 double ddt = in.time() - pt;
126 double ddv = (n - p) / ddt;
128 final double max = 100000;
131 if (Math.abs(ddv) > max) {
141 filter_len = ascent_filter_len;
143 filter_len = descent_filter_len;
145 double f = 1/Math.exp(ddt/ filter_len);
146 n = p * f + n * (1-f);
151 void set_integral(AltosValue in) {
152 double change = in.integrate();
154 if (change != AltosLib.MISSING) {
155 double prev = prev_value;
156 if (prev == AltosLib.MISSING)
158 set(prev + change, in.time());
162 void copy(AltosValue old) {
164 set_time = old.set_time;
165 prev_value = old.value;
166 prev_set_time = old.set_time;
167 max_value = old.max_value;
170 void finish_update() {
172 prev_set_time = set_time;
176 value = AltosLib.MISSING;
177 prev_value = AltosLib.MISSING;
178 max_value = AltosLib.MISSING;
187 double v = measured.value();
188 if (v != AltosLib.MISSING)
190 return computed.value();
193 boolean is_measured() {
194 return measured.value() != AltosLib.MISSING;
198 double m = measured.max();
200 if (m != AltosLib.MISSING)
202 return computed.max();
205 double prev_value() {
206 if (measured.value != AltosLib.MISSING && measured.prev_value != AltosLib.MISSING)
207 return measured.prev_value;
208 return computed.prev_value;
211 AltosValue altos_value() {
212 if (measured.value() != AltosLib.MISSING)
218 double c = measured.change();
219 if (c == AltosLib.MISSING)
220 c = computed.change();
225 double r = measured.rate();
226 if (r == AltosLib.MISSING)
231 void set_measured(double new_value, double time) {
232 measured.set(new_value, time);
235 void set_computed(double new_value, double time) {
236 computed.set(new_value, time);
239 void set_derivative(AltosValue in) {
240 computed.set_derivative(in);
243 void set_derivative(AltosCValue in) {
244 set_derivative(in.altos_value());
247 void set_integral(AltosValue in) {
248 computed.set_integral(in);
251 void set_integral(AltosCValue in) {
252 set_integral(in.altos_value());
255 void copy(AltosCValue old) {
256 measured.copy(old.measured);
257 computed.copy(old.computed);
260 void finish_update() {
261 measured.finish_update();
262 computed.finish_update();
266 measured = new AltosValue();
267 computed = new AltosValue();
274 public int altitude_32;
275 public int receiver_serial;
276 public boolean landed;
277 public boolean ascent; /* going up? */
278 public boolean boost; /* under power */
281 public int device_type;
282 public int config_major;
283 public int config_minor;
284 public int apogee_delay;
285 public int main_deploy;
286 public int flight_log_max;
288 private double pressure_to_altitude(double p) {
289 if (p == AltosLib.MISSING)
290 return AltosLib.MISSING;
291 return AltosConvert.pressure_to_altitude(p);
294 private AltosCValue ground_altitude;
296 public double ground_altitude() {
297 return ground_altitude.value();
300 public void set_ground_altitude(double a) {
301 ground_altitude.set_measured(a, time);
304 class AltosGpsGroundAltitude extends AltosValue {
305 void set(double a, double t) {
308 gps_altitude.set_gps_height();
311 void set_filtered(double a, double t) {
312 super.set_filtered(a, t);
314 gps_altitude.set_gps_height();
318 private AltosGpsGroundAltitude gps_ground_altitude;
320 public double gps_ground_altitude() {
321 return gps_ground_altitude.value();
324 public void set_gps_ground_altitude(double a) {
325 gps_ground_altitude.set(a, time);
328 class AltosGroundPressure extends AltosCValue {
329 void set_filtered(double p, double time) {
330 computed.set_filtered(p, time);
332 ground_altitude.set_computed(pressure_to_altitude(computed.value()), time);
335 void set_measured(double p, double time) {
336 super.set_measured(p, time);
337 ground_altitude.set_computed(pressure_to_altitude(p), time);
341 private AltosGroundPressure ground_pressure;
343 public double ground_pressure() {
344 return ground_pressure.value();
347 public void set_ground_pressure (double pressure) {
348 ground_pressure.set_measured(pressure, time);
351 class AltosAltitude extends AltosCValue {
353 private void set_speed(AltosValue v) {
354 if (!acceleration.is_measured() || !ascent)
355 speed.set_derivative(this);
358 void set_computed(double a, double time) {
359 super.set_computed(a,time);
364 void set_measured(double a, double time) {
365 super.set_measured(a,time);
371 private AltosAltitude altitude;
373 class AltosGpsAltitude extends AltosValue {
375 private void set_gps_height() {
377 double g = gps_ground_altitude.value();
379 if (a != AltosLib.MISSING && g != AltosLib.MISSING)
382 gps_height = AltosLib.MISSING;
385 void set(double a, double t) {
391 private AltosGpsAltitude gps_altitude;
393 private AltosValue gps_ground_speed;
394 private AltosValue gps_ascent_rate;
395 private AltosValue gps_course;
396 private AltosValue gps_speed;
398 public double altitude() {
399 double a = altitude.value();
400 if (a != AltosLib.MISSING)
402 return gps_altitude.value();
405 public double max_altitude() {
406 double a = altitude.max();
407 if (a != AltosLib.MISSING)
409 return gps_altitude.max();
412 public void set_altitude(double new_altitude) {
413 altitude.set_measured(new_altitude, time);
416 public double gps_altitude() {
417 return gps_altitude.value();
420 public double max_gps_altitude() {
421 return gps_altitude.max();
424 public void set_gps_altitude(double new_gps_altitude) {
425 gps_altitude.set(new_gps_altitude, time);
428 public double gps_ground_speed() {
429 return gps_ground_speed.value();
432 public double max_gps_ground_speed() {
433 return gps_ground_speed.max();
436 public double gps_ascent_rate() {
437 return gps_ascent_rate.value();
440 public double max_gps_ascent_rate() {
441 return gps_ascent_rate.max();
444 public double gps_course() {
445 return gps_course.value();
448 public double gps_speed() {
449 return gps_speed.value();
452 public double max_gps_speed() {
453 return gps_speed.max();
456 class AltosPressure extends AltosValue {
457 void set(double p, double time) {
459 if (state == AltosLib.ao_flight_pad)
460 ground_pressure.set_filtered(p, time);
461 double a = pressure_to_altitude(p);
462 altitude.set_computed(a, time);
466 private AltosPressure pressure;
468 public double pressure() {
469 return pressure.value();
472 public void set_pressure(double p) {
473 pressure.set(p, time);
476 public double baro_height() {
477 double a = altitude();
478 double g = ground_altitude();
479 if (a != AltosLib.MISSING && g != AltosLib.MISSING)
481 return AltosLib.MISSING;
484 public double height() {
485 double k = kalman_height.value();
486 if (k != AltosLib.MISSING)
489 double b = baro_height();
490 if (b != AltosLib.MISSING)
496 public double max_height() {
497 double k = kalman_height.max();
498 if (k != AltosLib.MISSING)
501 double a = altitude.max();
502 double g = ground_altitude();
503 if (a != AltosLib.MISSING && g != AltosLib.MISSING)
505 return max_gps_height();
508 public double gps_height() {
509 double a = gps_altitude();
510 double g = gps_ground_altitude();
512 if (a != AltosLib.MISSING && g != AltosLib.MISSING)
514 return AltosLib.MISSING;
517 public double max_gps_height() {
518 double a = gps_altitude.max();
519 double g = gps_ground_altitude();
521 if (a != AltosLib.MISSING && g != AltosLib.MISSING)
523 return AltosLib.MISSING;
526 class AltosSpeed extends AltosCValue {
529 return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
533 acceleration.set_derivative(this);
536 void set_derivative(AltosCValue in) {
537 super.set_derivative(in);
541 void set_computed(double new_value, double time) {
542 super.set_computed(new_value, time);
546 void set_measured(double new_value, double time) {
547 super.set_measured(new_value, time);
552 private AltosSpeed speed;
554 public double speed() {
555 double v = kalman_speed.value();
556 if (v != AltosLib.MISSING)
559 if (v != AltosLib.MISSING)
562 if (v != AltosLib.MISSING)
564 return AltosLib.MISSING;
567 public double max_speed() {
568 double v = kalman_speed.max();
569 if (v != AltosLib.MISSING)
572 if (v != AltosLib.MISSING)
575 if (v != AltosLib.MISSING)
577 return AltosLib.MISSING;
580 class AltosAccel extends AltosCValue {
583 return state < AltosLib.ao_flight_fast || state == AltosLib.ao_flight_stateless;
586 void set_measured(double a, double time) {
587 super.set_measured(a, time);
589 speed.set_integral(this.measured);
593 AltosAccel acceleration;
595 public double acceleration() {
596 return acceleration.value();
599 public double max_acceleration() {
600 return acceleration.max();
603 public AltosValue orient;
605 public void set_orient(double new_orient) {
606 orient.set(new_orient, time);
609 public double orient() {
610 return orient.value();
613 public double max_orient() {
617 public AltosValue kalman_height, kalman_speed, kalman_acceleration;
619 public void set_kalman(double height, double speed, double acceleration) {
620 kalman_height.set(height, time);
621 kalman_speed.set(speed, time);
622 kalman_acceleration.set(acceleration, time);
625 public double battery_voltage;
626 public double pyro_voltage;
627 public double temperature;
628 public double apogee_voltage;
629 public double main_voltage;
631 public double ignitor_voltage[];
634 public AltosGPS temp_gps;
635 public int temp_gps_sat_tick;
636 public boolean gps_pending;
637 public int gps_sequence;
642 public static final int MIN_PAD_SAMPLES = 10;
645 public int gps_waiting;
646 public boolean gps_ready;
650 public AltosGreatCircle from_pad;
651 public double elevation; /* from pad */
652 public double range; /* total distance */
654 public double gps_height;
656 public double pad_lat, pad_lon, pad_alt;
658 public int speak_tick;
659 public double speak_altitude;
661 public String callsign;
662 public String firmware_version;
664 public double accel_plus_g;
665 public double accel_minus_g;
667 public double ground_accel;
668 public double ground_accel_avg;
670 public int log_format;
671 public String product;
673 public AltosMs5607 baro;
675 public AltosCompanion companion;
677 public int pyro_fired;
679 public void set_npad(int npad) {
681 gps_waiting = MIN_PAD_SAMPLES - npad;
682 if (this.gps_waiting < 0)
684 gps_ready = gps_waiting == 0;
690 received_time = System.currentTimeMillis();
691 time = AltosLib.MISSING;
692 time_change = AltosLib.MISSING;
693 prev_time = AltosLib.MISSING;
694 tick = AltosLib.MISSING;
695 prev_tick = AltosLib.MISSING;
696 boost_tick = AltosLib.MISSING;
697 state = AltosLib.ao_flight_invalid;
698 flight = AltosLib.MISSING;
701 rssi = AltosLib.MISSING;
703 device_type = AltosLib.MISSING;
704 config_major = AltosLib.MISSING;
705 config_minor = AltosLib.MISSING;
706 apogee_delay = AltosLib.MISSING;
707 main_deploy = AltosLib.MISSING;
708 flight_log_max = AltosLib.MISSING;
710 ground_altitude = new AltosCValue();
711 ground_pressure = new AltosGroundPressure();
712 altitude = new AltosAltitude();
713 pressure = new AltosPressure();
714 speed = new AltosSpeed();
715 acceleration = new AltosAccel();
716 orient = new AltosValue();
718 temperature = AltosLib.MISSING;
719 battery_voltage = AltosLib.MISSING;
720 pyro_voltage = AltosLib.MISSING;
721 apogee_voltage = AltosLib.MISSING;
722 main_voltage = AltosLib.MISSING;
723 ignitor_voltage = null;
725 kalman_height = new AltosValue();
726 kalman_speed = new AltosValue();
727 kalman_acceleration = new AltosValue();
731 temp_gps_sat_tick = 0;
742 elevation = AltosLib.MISSING;
743 range = AltosLib.MISSING;
744 gps_height = AltosLib.MISSING;
746 pad_lat = AltosLib.MISSING;
747 pad_lon = AltosLib.MISSING;
748 pad_alt = AltosLib.MISSING;
750 gps_altitude = new AltosGpsAltitude();
751 gps_ground_altitude = new AltosGpsGroundAltitude();
752 gps_ground_speed = new AltosValue();
753 gps_speed = new AltosValue();
754 gps_ascent_rate = new AltosValue();
755 gps_course = new AltosValue();
757 speak_tick = AltosLib.MISSING;
758 speak_altitude = AltosLib.MISSING;
761 firmware_version = null;
763 accel_plus_g = AltosLib.MISSING;
764 accel_minus_g = AltosLib.MISSING;
765 accel = AltosLib.MISSING;
767 ground_accel = AltosLib.MISSING;
768 ground_accel_avg = AltosLib.MISSING;
770 log_format = AltosLib.MISSING;
772 serial = AltosLib.MISSING;
773 receiver_serial = AltosLib.MISSING;
774 altitude_32 = AltosLib.MISSING;
782 void finish_update() {
785 ground_altitude.finish_update();
786 altitude.finish_update();
787 pressure.finish_update();
788 speed.finish_update();
789 acceleration.finish_update();
790 orient.finish_update();
792 kalman_height.finish_update();
793 kalman_speed.finish_update();
794 kalman_acceleration.finish_update();
797 void copy(AltosState old) {
804 received_time = old.received_time;
806 time_change = old.time_change;
807 prev_time = old.time;
810 prev_tick = old.tick;
811 boost_tick = old.boost_tick;
820 device_type = old.device_type;
821 config_major = old.config_major;
822 config_minor = old.config_minor;
823 apogee_delay = old.apogee_delay;
824 main_deploy = old.main_deploy;
825 flight_log_max = old.flight_log_max;
829 ground_pressure.copy(old.ground_pressure);
830 ground_altitude.copy(old.ground_altitude);
831 altitude.copy(old.altitude);
832 pressure.copy(old.pressure);
833 speed.copy(old.speed);
834 acceleration.copy(old.acceleration);
835 orient.copy(old.orient);
837 battery_voltage = old.battery_voltage;
838 pyro_voltage = old.pyro_voltage;
839 temperature = old.temperature;
840 apogee_voltage = old.apogee_voltage;
841 main_voltage = old.main_voltage;
842 ignitor_voltage = old.ignitor_voltage;
844 kalman_height.copy(old.kalman_height);
845 kalman_speed.copy(old.kalman_speed);
846 kalman_acceleration.copy(old.kalman_acceleration);
849 gps = old.gps.clone();
852 if (old.temp_gps != null)
853 temp_gps = old.temp_gps.clone();
856 temp_gps_sat_tick = old.temp_gps_sat_tick;
857 gps_sequence = old.gps_sequence;
858 gps_pending = old.gps_pending;
861 imu = old.imu.clone();
866 mag = old.mag.clone();
871 gps_waiting = old.gps_waiting;
872 gps_ready = old.gps_ready;
875 if (old.from_pad != null)
876 from_pad = old.from_pad.clone();
880 elevation = old.elevation;
883 gps_height = old.gps_height;
885 gps_altitude.copy(old.gps_altitude);
886 gps_ground_altitude.copy(old.gps_ground_altitude);
887 gps_ground_speed.copy(old.gps_ground_speed);
888 gps_ascent_rate.copy(old.gps_ascent_rate);
889 gps_course.copy(old.gps_course);
890 gps_speed.copy(old.gps_speed);
892 pad_lat = old.pad_lat;
893 pad_lon = old.pad_lon;
894 pad_alt = old.pad_alt;
896 speak_tick = old.speak_tick;
897 speak_altitude = old.speak_altitude;
899 callsign = old.callsign;
900 firmware_version = old.firmware_version;
902 accel_plus_g = old.accel_plus_g;
903 accel_minus_g = old.accel_minus_g;
905 ground_accel = old.ground_accel;
906 ground_accel_avg = old.ground_accel_avg;
908 log_format = old.log_format;
909 product = old.product;
911 receiver_serial = old.receiver_serial;
912 altitude_32 = old.altitude_32;
915 companion = old.companion;
917 pyro_fired = old.pyro_fired;
924 elevation = AltosLib.MISSING;
925 range = AltosLib.MISSING;
930 if (gps.locked && gps.nsat >= 4) {
931 /* Track consecutive 'good' gps reports, waiting for 10 of them */
932 if (state == AltosLib.ao_flight_pad || state == AltosLib.ao_flight_stateless) {
934 if (pad_lat != AltosLib.MISSING && (npad < 10 || state == AltosLib.ao_flight_pad)) {
935 pad_lat = (pad_lat * 31 + gps.lat) / 32;
936 pad_lon = (pad_lon * 31 + gps.lon) / 32;
937 gps_ground_altitude.set_filtered(gps.alt, time);
940 if (pad_lat == AltosLib.MISSING) {
943 gps_ground_altitude.set(gps.alt, time);
945 gps_altitude.set(gps.alt, time);
946 if (gps.climb_rate != AltosLib.MISSING)
947 gps_ascent_rate.set(gps.climb_rate, time);
948 if (gps.ground_speed != AltosLib.MISSING)
949 gps_ground_speed.set(gps.ground_speed, time);
950 if (gps.climb_rate != AltosLib.MISSING && gps.ground_speed != AltosLib.MISSING)
951 gps_speed.set(Math.sqrt(gps.ground_speed * gps.ground_speed +
952 gps.climb_rate * gps.climb_rate), time);
953 if (gps.course != AltosLib.MISSING)
954 gps_course.set(gps.course, time);
956 if (gps.lat != 0 && gps.lon != 0 &&
957 pad_lat != AltosLib.MISSING &&
958 pad_lon != AltosLib.MISSING)
962 if (h == AltosLib.MISSING)
964 from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h);
965 elevation = from_pad.elevation;
966 range = from_pad.range;
970 public void set_tick(int new_tick) {
971 if (new_tick != AltosLib.MISSING) {
972 if (prev_tick != AltosLib.MISSING) {
973 while (new_tick < prev_tick - 1000) {
979 time_change = time - prev_time;
983 public void set_boost_tick(int boost_tick) {
984 if (boost_tick != AltosLib.MISSING)
985 this.boost_tick = boost_tick;
988 public String state_name() {
989 return AltosLib.state_name(state);
992 public void set_state(int state) {
993 if (state != AltosLib.ao_flight_invalid) {
995 ascent = (AltosLib.ao_flight_boost <= state &&
996 state <= AltosLib.ao_flight_coast);
997 boost = (AltosLib.ao_flight_boost == state);
1001 public void set_device_type(int device_type) {
1002 this.device_type = device_type;
1003 switch (device_type) {
1004 case AltosLib.product_telegps:
1005 this.state = AltosLib.ao_flight_stateless;
1010 public void set_log_format(int log_format) {
1011 this.log_format = log_format;
1012 switch (log_format) {
1013 case AltosLib.AO_LOG_FORMAT_TELEGPS:
1014 this.state = AltosLib.ao_flight_stateless;
1019 public void set_flight_params(int apogee_delay, int main_deploy) {
1020 this.apogee_delay = apogee_delay;
1021 this.main_deploy = main_deploy;
1024 public void set_config(int major, int minor, int flight_log_max) {
1025 config_major = major;
1026 config_minor = minor;
1027 this.flight_log_max = flight_log_max;
1030 public void set_callsign(String callsign) {
1031 this.callsign = callsign;
1034 public void set_firmware_version(String version) {
1035 firmware_version = version;
1038 public int compare_version(String other_version) {
1039 if (firmware_version == null)
1040 return AltosLib.MISSING;
1041 return AltosLib.compare_version(firmware_version, other_version);
1044 private void re_init() {
1045 int bt = boost_tick;
1046 int rs = receiver_serial;
1049 receiver_serial = rs;
1052 public void set_flight(int flight) {
1054 /* When the flight changes, reset the state */
1055 if (flight != AltosLib.MISSING) {
1056 if (this.flight != AltosLib.MISSING &&
1057 this.flight != flight) {
1060 this.flight = flight;
1064 public void set_serial(int serial) {
1065 /* When the serial changes, reset the state */
1066 if (serial != AltosLib.MISSING) {
1067 if (this.serial != AltosLib.MISSING &&
1068 this.serial != serial) {
1071 this.serial = serial;
1075 public void set_receiver_serial(int serial) {
1076 if (serial != AltosLib.MISSING)
1077 receiver_serial = serial;
1080 public boolean altitude_32() {
1081 return altitude_32 == 1;
1084 public void set_altitude_32(int altitude_32) {
1085 if (altitude_32 != AltosLib.MISSING)
1086 this.altitude_32 = altitude_32;
1090 if (rssi == AltosLib.MISSING)
1095 public void set_rssi(int rssi, int status) {
1096 if (rssi != AltosLib.MISSING) {
1098 this.status = status;
1102 public void set_received_time(long ms) {
1106 public void set_gps(AltosGPS gps, int sequence) {
1108 this.gps = gps.clone();
1109 gps_sequence = sequence;
1115 public void set_imu(AltosIMU imu) {
1121 public void set_mag(AltosMag mag) {
1122 this.mag = mag.clone();
1125 public AltosMs5607 make_baro() {
1127 baro = new AltosMs5607();
1131 public void set_ms5607(AltosMs5607 ms5607) {
1135 set_pressure(baro.pa);
1136 set_temperature(baro.cc / 100.0);
1140 public void set_ms5607(int pres, int temp) {
1142 baro.set(pres, temp);
1144 set_pressure(baro.pa);
1145 set_temperature(baro.cc / 100.0);
1149 public void make_companion (int nchannels) {
1150 if (companion == null)
1151 companion = new AltosCompanion(nchannels);
1154 public void set_companion(AltosCompanion companion) {
1155 this.companion = companion;
1158 void update_accel() {
1159 if (accel == AltosLib.MISSING)
1161 if (accel_plus_g == AltosLib.MISSING)
1163 if (accel_minus_g == AltosLib.MISSING)
1166 double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0;
1167 double counts_per_mss = counts_per_g / 9.80665;
1168 acceleration.set_measured((accel_plus_g - accel) / counts_per_mss, time);
1171 public void set_accel_g(double accel_plus_g, double accel_minus_g) {
1172 if (accel_plus_g != AltosLib.MISSING) {
1173 this.accel_plus_g = accel_plus_g;
1174 this.accel_minus_g = accel_minus_g;
1179 public void set_ground_accel(double ground_accel) {
1180 if (ground_accel != AltosLib.MISSING)
1181 this.ground_accel = ground_accel;
1184 public void set_accel(double accel) {
1185 if (accel != AltosLib.MISSING) {
1187 if (state == AltosLib.ao_flight_pad) {
1188 if (ground_accel_avg == AltosLib.MISSING)
1189 ground_accel_avg = accel;
1191 ground_accel_avg = (ground_accel_avg * 7 + accel) / 8;
1197 public void set_temperature(double temperature) {
1198 if (temperature != AltosLib.MISSING) {
1199 this.temperature = temperature;
1204 public void set_battery_voltage(double battery_voltage) {
1205 if (battery_voltage != AltosLib.MISSING) {
1206 this.battery_voltage = battery_voltage;
1211 public void set_pyro_voltage(double pyro_voltage) {
1212 if (pyro_voltage != AltosLib.MISSING) {
1213 this.pyro_voltage = pyro_voltage;
1218 public void set_apogee_voltage(double apogee_voltage) {
1219 if (apogee_voltage != AltosLib.MISSING) {
1220 this.apogee_voltage = apogee_voltage;
1225 public void set_main_voltage(double main_voltage) {
1226 if (main_voltage != AltosLib.MISSING) {
1227 this.main_voltage = main_voltage;
1232 public void set_ignitor_voltage(double[] voltage) {
1233 this.ignitor_voltage = voltage;
1236 public void set_pyro_fired(int fired) {
1237 this.pyro_fired = fired;
1240 public double time_since_boost() {
1241 if (tick == AltosLib.MISSING)
1244 if (boost_tick == AltosLib.MISSING)
1245 return tick / 100.0;
1246 return (tick - boost_tick) / 100.0;
1249 public boolean valid() {
1250 return tick != AltosLib.MISSING && serial != AltosLib.MISSING;
1253 public AltosGPS make_temp_gps(boolean sats) {
1254 if (temp_gps == null) {
1255 temp_gps = new AltosGPS(gps);
1259 if (tick != temp_gps_sat_tick)
1260 temp_gps.cc_gps_sat = null;
1261 temp_gps_sat_tick = tick;
1266 public void set_temp_gps() {
1267 set_gps(temp_gps, gps_sequence + 1);
1268 gps_pending = false;
1272 public AltosState clone() {
1273 AltosState s = new AltosState();
1278 public AltosState () {