altoslib: Add user-selectable filter width for data smoothing
[fw/altos] / altoslib / AltosFlightSeries.java
1 /*
2  * Copyright © 2017 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, either version 2 of the License, or
7  * (at your option) any later version.
8  *
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.
13  */
14
15 package org.altusmetrum.altoslib_12;
16
17 import java.util.*;
18
19 public class AltosFlightSeries extends AltosDataListener {
20
21         public ArrayList<AltosTimeSeries> series = new ArrayList<AltosTimeSeries>();
22
23         public double   speed_filter_width = 4.0;
24         public double   accel_filter_width = 1.0;
25
26         public int[] indices() {
27                 int[] indices = new int[series.size()];
28                 for (int i = 0; i < indices.length; i++)
29                         indices[i] = -1;
30                 step_indices(indices);
31                 return indices;
32         }
33
34         private double time(int id, int index) {
35                 AltosTimeSeries         s = series.get(id);
36
37                 if (index < 0)
38                         return Double.NEGATIVE_INFINITY;
39
40                 if (index < s.values.size())
41                         return s.values.get(index).time;
42                 return Double.POSITIVE_INFINITY;
43         }
44
45         public boolean step_indices(int[] indices) {
46                 double  min_next = time(0, indices[0]+1);
47
48                 for (int i = 1; i < indices.length; i++) {
49                         double next = time(i, indices[i]+1);
50                         if (next < min_next)
51                                 min_next = next;
52                 }
53
54                 if (min_next == Double.POSITIVE_INFINITY)
55                         return false;
56
57                 for (int i = 0; i < indices.length; i++) {
58                         double  t = time(i, indices[i] + 1);
59
60                         if (t <= min_next)
61                                 indices[i]++;
62                 }
63                 return true;
64         }
65
66         public double time(int[] indices) {
67                 double max = time(0, indices[0]);
68
69                 for (int i = 1; i < indices.length; i++) {
70                         double t = time(i, indices[i]);
71                         if (t >= max)
72                                 max = t;
73                 }
74                 return max;
75         }
76
77         public double value(String name, int[] indices) {
78                 for (int i = 0; i < indices.length; i++) {
79                         AltosTimeSeries s = series.get(i);
80                         if (s.label.equals(name)) {
81                                 int index = indices[i];
82                                 if (index < 0)
83                                         index = 0;
84                                 if (index >= s.values.size())
85                                         index = s.values.size() - 1;
86                                 return s.values.get(index).value;
87                         }
88                 }
89                 return AltosLib.MISSING;
90         }
91
92         public double value(String name, double time) {
93                 for (AltosTimeSeries s : series) {
94                         if (s.label.equals(name))
95                                 return s.value(time);
96                 }
97                 return AltosLib.MISSING;
98         }
99
100         public double value_before(String name, double time) {
101                 for (AltosTimeSeries s : series) {
102                         if (s.label.equals(name))
103                                 return s.value_before(time);
104                 }
105                 return AltosLib.MISSING;
106         }
107
108         public double value_after(String name, double time) {
109                 for (AltosTimeSeries s : series) {
110                         if (s.label.equals(name))
111                                 return s.value_after(time);
112                 }
113                 return AltosLib.MISSING;
114         }
115
116         public AltosTimeSeries make_series(String label, AltosUnits units) {
117                 return new AltosTimeSeries(label, units);
118         }
119
120         public void add_series(AltosTimeSeries s) {
121                 for (int e = 0; e < series.size(); e++) {
122                         if (s.compareTo(series.get(e)) < 0){
123                                 series.add(e, s);
124                                 return;
125                         }
126                 }
127                 series.add(s);
128         }
129
130         public AltosTimeSeries add_series(String label, AltosUnits units) {
131                 AltosTimeSeries s = make_series(label, units);
132                 add_series(s);
133                 return s;
134         }
135
136         public void remove_series(AltosTimeSeries s) {
137                 series.remove(s);
138         }
139
140         public boolean has_series(String label) {
141                 for (AltosTimeSeries s : series)
142                         if (s.label.equals(label))
143                                 return true;
144                 return false;
145         }
146
147         public AltosTimeSeries state_series;
148
149         public static final String state_name = "State";
150
151         public void set_state(int state) {
152
153                 if (state != AltosLib.ao_flight_pad && state != AltosLib.MISSING && state != AltosLib.ao_flight_stateless) {
154                         if (state_series == null)
155                                 state_series = add_series(state_name, AltosConvert.state_name);
156                         if (this.state() != state)
157                                 state_series.add(time(), state);
158                 }
159                 super.set_state(state);
160         }
161
162         public AltosTimeSeries  accel_series;
163         public boolean          accel_computed;
164
165         public static final String accel_name = "Accel";
166
167         public AltosTimeSeries  vert_accel_series;
168
169         public static final String vert_accel_name = "Vertical Accel";
170
171         public void set_acceleration(double acceleration) {
172                 if (acceleration == AltosLib.MISSING)
173                         return;
174                 if (accel_series == null)
175                         accel_series = add_series(accel_name, AltosConvert.accel);
176
177                 accel_series.add(time(), acceleration);
178                 accel_computed = false;
179         }
180
181         private AltosTimeSeries compute_accel() {
182                 AltosTimeSeries new_accel_series = null;
183
184                 if (speed_series != null) {
185                         AltosTimeSeries temp_series;
186                         if (accel_filter_width > 0) {
187                                 temp_series = make_series(speed_name, AltosConvert.speed);
188                                 speed_series.filter(temp_series, accel_filter_width);
189                         } else
190                                 temp_series = speed_series;
191
192                         new_accel_series = make_series(accel_name, AltosConvert.accel);
193                         temp_series.differentiate(new_accel_series);
194                 }
195                 return new_accel_series;
196         }
197
198         public void set_filter(double speed_filter, double accel_filter) {
199                 this.speed_filter_width = speed_filter;
200                 this.accel_filter_width = accel_filter;
201
202                 AltosTimeSeries new_speed_series = compute_speed();
203
204                 if (new_speed_series != null) {
205                         speed_series.erase_values();
206                         for (AltosTimeValue tv : new_speed_series)
207                                 speed_series.add(tv);
208                 }
209                 if (accel_computed) {
210                         AltosTimeSeries new_accel_series = compute_accel();
211                         if (new_accel_series != null) {
212                                 accel_series.erase_values();
213                                 for (AltosTimeValue tv : new_accel_series)
214                                         accel_series.add(tv);
215                         }
216                 }
217         }
218
219         public void set_received_time(long received_time) {
220         }
221
222         public AltosTimeSeries tick_series;
223
224         public static final String tick_name = "Tick";
225
226         public void set_tick(int tick) {
227                 super.set_tick(tick);
228                 if (tick_series == null)
229                         tick_series = add_series(tick_name, null);
230                 tick_series.add(time(), tick);
231         }
232
233         public AltosTimeSeries rssi_series;
234
235         public static final String rssi_name = "RSSI";
236
237         public AltosTimeSeries status_series;
238
239         public static final String status_name = "Radio Status";
240
241         public void set_rssi(int rssi, int status) {
242                 if (rssi_series == null) {
243                         rssi_series = add_series(rssi_name, null);
244                         status_series = add_series(status_name, null);
245                 }
246                 rssi_series.add(time(), rssi);
247                 status_series.add(time(), status);
248         }
249
250         public AltosTimeSeries pressure_series;
251
252         public static final String pressure_name = "Pressure";
253
254         public AltosTimeSeries altitude_series;
255
256         public static final String altitude_name = "Altitude";
257
258         public AltosTimeSeries height_series;
259
260         public static final String height_name = "Height";
261
262         public  void set_pressure(double pa) {
263                 if (pa == AltosLib.MISSING)
264                         return;
265
266                 if (pressure_series == null)
267                         pressure_series = add_series(pressure_name, AltosConvert.pressure);
268                 pressure_series.add(time(), pa);
269                 if (altitude_series == null)
270                         altitude_series = add_series(altitude_name, AltosConvert.height);
271
272                 if (cal_data().ground_pressure == AltosLib.MISSING)
273                         cal_data().set_ground_pressure(pa);
274
275                 double altitude = AltosConvert.pressure_to_altitude(pa);
276                 altitude_series.add(time(), altitude);
277         }
278
279         private void compute_height() {
280                 double ground_altitude = cal_data().ground_altitude;
281                 if (height_series == null && ground_altitude != AltosLib.MISSING && altitude_series != null) {
282                         height_series = add_series(height_name, AltosConvert.height);
283                         for (AltosTimeValue alt : altitude_series)
284                                 height_series.add(alt.time, alt.value - ground_altitude);
285                 }
286
287                 if (gps_height == null && cal_data().gps_pad != null && cal_data().gps_pad.alt != AltosLib.MISSING && gps_altitude != null) {
288                         double gps_ground_altitude = cal_data().gps_pad.alt;
289                         gps_height = add_series(gps_height_name, AltosConvert.height);
290                         for (AltosTimeValue gps_alt : gps_altitude)
291                                 gps_height.add(gps_alt.time, gps_alt.value - gps_ground_altitude);
292                 }
293         }
294
295         public AltosTimeSeries speed_series;
296
297         public static final String speed_name = "Speed";
298
299         private AltosTimeSeries compute_speed() {
300                 AltosTimeSeries new_speed_series = null;
301                 AltosTimeSeries alt_speed_series = null;
302                 AltosTimeSeries accel_speed_series = null;
303
304                 if (altitude_series != null) {
305                         AltosTimeSeries temp_series;
306
307                         if (speed_filter_width > 0) {
308                                 temp_series = make_series(speed_name, AltosConvert.height);
309                                 altitude_series.filter(temp_series, speed_filter_width);
310                         } else
311                                 temp_series = altitude_series;
312
313                         alt_speed_series = make_series(speed_name, AltosConvert.speed);
314                         temp_series.differentiate(alt_speed_series);
315                 }
316                 if (accel_series != null && !accel_computed) {
317
318                         if (orient_series != null) {
319                                 vert_accel_series = add_series(vert_accel_name, AltosConvert.accel);
320
321                                 for (AltosTimeValue a : accel_series) {
322                                         double  orient = orient_series.value(a.time);
323                                         double  a_abs = a.value + AltosConvert.gravity;
324                                         double  v_a = a_abs * Math.cos(AltosConvert.degrees_to_radians(orient)) - AltosConvert.gravity;
325
326                                         vert_accel_series.add(a.time, v_a);
327                                 }
328                         }
329
330                         AltosTimeSeries temp_series = make_series(speed_name, AltosConvert.speed);
331
332                         if (vert_accel_series != null)
333                                 vert_accel_series.integrate(temp_series);
334                         else
335                                 accel_series.integrate(temp_series);
336
337                         accel_speed_series = make_series(speed_name, AltosConvert.speed);
338                         temp_series.filter(accel_speed_series, 0.1);
339                 }
340
341                 if (alt_speed_series != null && accel_speed_series != null) {
342                         double  apogee_time = AltosLib.MISSING;
343                         if (state_series != null) {
344                                 for (AltosTimeValue d : state_series) {
345                                         if (d.value >= AltosLib.ao_flight_drogue){
346                                                 apogee_time = d.time;
347                                                 break;
348                                         }
349                                 }
350                         }
351                         if (apogee_time == AltosLib.MISSING) {
352                                 new_speed_series = alt_speed_series;
353                         } else {
354                                 new_speed_series = make_series(speed_name, AltosConvert.speed);
355                                 for (AltosTimeValue d : accel_speed_series) {
356                                         if (d.time <= apogee_time)
357                                                 new_speed_series.add(d);
358                                 }
359                                 for (AltosTimeValue d : alt_speed_series) {
360                                         if (d.time > apogee_time)
361                                                 new_speed_series.add(d);
362                                 }
363
364                         }
365                 } else if (alt_speed_series != null) {
366                         new_speed_series = alt_speed_series;
367                 } else if (accel_speed_series != null) {
368                         new_speed_series = accel_speed_series;
369                 }
370                 return new_speed_series;
371         }
372
373         public AltosTimeSeries orient_series;
374
375         public static final String orient_name = "Tilt Angle";
376
377         private void compute_orient() {
378
379                 if (orient_series != null)
380                         return;
381
382                 if (accel_ground_across == AltosLib.MISSING)
383                         return;
384
385                 if (cal_data().pad_orientation == AltosLib.MISSING)
386                         return;
387
388                 if (cal_data().accel_zero_across == AltosLib.MISSING)
389                         return;
390
391                 AltosRotation rotation = new AltosRotation(AltosIMU.convert_accel(accel_ground_across - cal_data().accel_zero_across),
392                                                            AltosIMU.convert_accel(accel_ground_through - cal_data().accel_zero_through),
393                                                            AltosIMU.convert_accel(accel_ground_along - cal_data().accel_zero_along),
394                                                            cal_data().pad_orientation);
395                 double prev_time = ground_time;
396
397                 orient_series = add_series(orient_name, AltosConvert.orient);
398                 orient_series.add(ground_time, rotation.tilt());
399
400                 for (AltosTimeValue roll_v : gyro_roll) {
401                         double  time = roll_v.time;
402                         double  dt = time - prev_time;
403
404                         if (dt > 0) {
405                                 double  roll = AltosConvert.degrees_to_radians(roll_v.value) * dt;
406                                 double  pitch = AltosConvert.degrees_to_radians(gyro_pitch.value(time)) * dt;
407                                 double  yaw = AltosConvert.degrees_to_radians(gyro_yaw.value(time)) * dt;
408
409                                 rotation.rotate(pitch, yaw, roll);
410                                 orient_series.add(time, rotation.tilt());
411                         }
412                         prev_time = time;
413                 }
414         }
415
416         public AltosTimeSeries  kalman_height_series, kalman_speed_series, kalman_accel_series;
417
418         public static final String kalman_height_name = "Kalman Height";
419         public static final String kalman_speed_name = "Kalman Speed";
420         public static final String kalman_accel_name = "Kalman Accel";
421
422         public void set_kalman(double height, double speed, double acceleration) {
423                 if (kalman_height_series == null) {
424                         kalman_height_series = add_series(kalman_height_name, AltosConvert.height);
425                         kalman_speed_series = add_series(kalman_speed_name, AltosConvert.speed);
426                         kalman_accel_series = add_series(kalman_accel_name, AltosConvert.accel);
427                 }
428                 kalman_height_series.add(time(), height);
429                 kalman_speed_series.add(time(), speed);
430                 kalman_accel_series.add(time(), acceleration);
431         }
432
433         public AltosTimeSeries thrust_series;
434
435         public static final String thrust_name = "Thrust";
436
437         public  void set_thrust(double N) {
438                 if (thrust_series == null)
439                         thrust_series = add_series(thrust_name, AltosConvert.force);
440                 thrust_series.add(time(), N);
441         }
442
443         public AltosTimeSeries temperature_series;
444
445         public static final String temperature_name = "Temperature";
446
447         public  void set_temperature(double deg_c) {
448                 if (temperature_series == null)
449                         temperature_series = add_series(temperature_name, AltosConvert.temperature);
450                 temperature_series.add(time(), deg_c);
451         }
452
453         public AltosTimeSeries battery_voltage_series;
454
455         public static final String battery_voltage_name = "Battery Voltage";
456
457         public void set_battery_voltage(double volts) {
458                 if (volts == AltosLib.MISSING)
459                         return;
460                 if (battery_voltage_series == null)
461                         battery_voltage_series = add_series(battery_voltage_name, AltosConvert.voltage);
462                 battery_voltage_series.add(time(), volts);
463         }
464
465         public AltosTimeSeries apogee_voltage_series;
466
467         public static final String apogee_voltage_name = "Apogee Voltage";
468
469         public void set_apogee_voltage(double volts) {
470                 if (volts == AltosLib.MISSING)
471                         return;
472                 if (apogee_voltage_series == null)
473                         apogee_voltage_series = add_series(apogee_voltage_name, AltosConvert.voltage);
474                 apogee_voltage_series.add(time(), volts);
475         }
476
477         public AltosTimeSeries main_voltage_series;
478
479         public static final String main_voltage_name = "Main Voltage";
480
481         public void set_main_voltage(double volts) {
482                 if (volts == AltosLib.MISSING)
483                         return;
484                 if (main_voltage_series == null)
485                         main_voltage_series = add_series(main_voltage_name, AltosConvert.voltage);
486                 main_voltage_series.add(time(), volts);
487         }
488
489         public ArrayList<AltosGPSTimeValue> gps_series;
490
491         public AltosGPS gps_before(double time) {
492                 AltosGPS gps = null;
493                 for (AltosGPSTimeValue gtv : gps_series)
494                         if (gtv.time <= time)
495                                 gps = gtv.gps;
496                         else
497                                 break;
498                 return gps;
499         }
500
501         public AltosTimeSeries  sats_in_view;
502         public AltosTimeSeries sats_in_soln;
503         public AltosTimeSeries gps_altitude;
504         public AltosTimeSeries gps_height;
505         public AltosTimeSeries gps_ground_speed;
506         public AltosTimeSeries gps_ascent_rate;
507         public AltosTimeSeries gps_course;
508         public AltosTimeSeries gps_speed;
509         public AltosTimeSeries gps_pdop, gps_vdop, gps_hdop;
510
511         public static final String sats_in_view_name = "Satellites in view";
512         public static final String sats_in_soln_name = "Satellites in solution";
513         public static final String gps_altitude_name = "GPS Altitude";
514         public static final String gps_height_name = "GPS Height";
515         public static final String gps_ground_speed_name = "GPS Ground Speed";
516         public static final String gps_ascent_rate_name = "GPS Ascent Rate";
517         public static final String gps_course_name = "GPS Course";
518         public static final String gps_speed_name = "GPS Speed";
519         public static final String gps_pdop_name = "GPS Dilution of Precision";
520         public static final String gps_vdop_name = "GPS Vertical Dilution of Precision";
521         public static final String gps_hdop_name = "GPS Horizontal Dilution of Precision";
522
523         public void set_gps(AltosGPS gps) {
524                 if (gps_series == null)
525                         gps_series = new ArrayList<AltosGPSTimeValue>();
526                 gps_series.add(new AltosGPSTimeValue(time(), gps));
527
528                 if (sats_in_soln == null) {
529                         sats_in_soln = add_series(sats_in_soln_name, null);
530                 }
531                 sats_in_soln.add(time(), gps.nsat);
532                 if (gps.pdop != AltosLib.MISSING) {
533                         if (gps_pdop == null)
534                                 gps_pdop = add_series(gps_pdop_name, null);
535                         gps_pdop.add(time(), gps.pdop);
536                 }
537                 if (gps.hdop != AltosLib.MISSING) {
538                         if (gps_hdop == null)
539                                 gps_hdop = add_series(gps_hdop_name, null);
540                         gps_hdop.add(time(), gps.hdop);
541                 }
542                 if (gps.vdop != AltosLib.MISSING) {
543                         if (gps_vdop == null)
544                                 gps_vdop = add_series(gps_vdop_name, null);
545                         gps_vdop.add(time(), gps.vdop);
546                 }
547                 if (gps.locked) {
548                         if (gps.alt != AltosLib.MISSING) {
549                                 if (gps_altitude == null)
550                                         gps_altitude = add_series(gps_altitude_name, AltosConvert.height);
551                                 gps_altitude.add(time(), gps.alt);
552                         }
553                         if (gps.ground_speed != AltosLib.MISSING) {
554                                 if (gps_ground_speed == null)
555                                         gps_ground_speed = add_series(gps_ground_speed_name, AltosConvert.speed);
556                                 gps_ground_speed.add(time(), gps.ground_speed);
557                         }
558                         if (gps.climb_rate != AltosLib.MISSING) {
559                                 if (gps_ascent_rate == null)
560                                         gps_ascent_rate = add_series(gps_ascent_rate_name, AltosConvert.speed);
561                                 gps_ascent_rate.add(time(), gps.climb_rate);
562                         }
563                         if (gps.course != AltosLib.MISSING) {
564                                 if (gps_course == null)
565                                         gps_course = add_series(gps_course_name, null);
566                                 gps_course.add(time(), gps.course);
567                         }
568                         if (gps.ground_speed != AltosLib.MISSING && gps.climb_rate != AltosLib.MISSING) {
569                                 if (gps_speed == null)
570                                         gps_speed = add_series(gps_speed_name, null);
571                                 gps_speed.add(time(), Math.sqrt(gps.ground_speed * gps.ground_speed +
572                                                                 gps.climb_rate * gps.climb_rate));
573                         }
574                 }
575                 if (gps.cc_gps_sat != null) {
576                         if (sats_in_view == null)
577                                 sats_in_view = add_series(sats_in_view_name, null);
578                         sats_in_view.add(time(), gps.cc_gps_sat.length);
579                 }
580         }
581
582         public static final String accel_along_name = "Accel Along";
583         public static final String accel_across_name = "Accel Across";
584         public static final String accel_through_name = "Accel Through";
585
586         public AltosTimeSeries accel_along, accel_across, accel_through;
587
588         public static final String gyro_roll_name = "Roll Rate";
589         public static final String gyro_pitch_name = "Pitch Rate";
590         public static final String gyro_yaw_name = "Yaw Rate";
591
592         public AltosTimeSeries gyro_roll, gyro_pitch, gyro_yaw;
593
594         public static final String mag_along_name = "Magnetic Field Along";
595         public static final String mag_across_name = "Magnetic Field Across";
596         public static final String mag_through_name = "Magnetic Field Through";
597
598         public AltosTimeSeries mag_along, mag_across, mag_through;
599
600         public  void set_accel(double along, double across, double through) {
601                 if (accel_along == null) {
602                         accel_along = add_series(accel_along_name, AltosConvert.accel);
603                         accel_across = add_series(accel_across_name, AltosConvert.accel);
604                         accel_through = add_series(accel_through_name, AltosConvert.accel);
605                 }
606                 accel_along.add(time(), along);
607                 accel_across.add(time(), across);
608                 accel_through.add(time(), through);
609         }
610
611         private double  accel_ground_along = AltosLib.MISSING;
612         private double  accel_ground_across = AltosLib.MISSING;
613         private double  accel_ground_through = AltosLib.MISSING;
614
615         private double          ground_time;
616
617         public  void set_accel_ground(double along, double across, double through) {
618                 accel_ground_along = along;
619                 accel_ground_across = across;
620                 accel_ground_through = through;
621                 ground_time = time();
622         }
623
624         public  void set_gyro(double roll, double pitch, double yaw) {
625                 if (gyro_roll == null) {
626                         gyro_roll = add_series(gyro_roll_name, AltosConvert.rotation_rate);
627                         gyro_pitch = add_series(gyro_pitch_name, AltosConvert.rotation_rate);
628                         gyro_yaw = add_series(gyro_yaw_name, AltosConvert.rotation_rate);
629                 }
630                 gyro_roll.add(time(), roll);
631                 gyro_pitch.add(time(), pitch);
632                 gyro_yaw.add(time(), yaw);
633         }
634
635         public  void set_mag(double along, double across, double through) {
636                 if (mag_along == null) {
637                         mag_along = add_series(mag_along_name, AltosConvert.magnetic_field);
638                         mag_across = add_series(mag_across_name, AltosConvert.magnetic_field);
639                         mag_through = add_series(mag_through_name, AltosConvert.magnetic_field);
640                 }
641                 mag_along.add(time(), along);
642                 mag_across.add(time(), across);
643                 mag_through.add(time(), through);
644         }
645
646         public void set_orient(double orient) {
647                 if (orient_series == null)
648                         orient_series = add_series(orient_name, AltosConvert.orient);
649                 orient_series.add(time(), orient);
650         }
651
652         public static final String pyro_voltage_name = "Pyro Voltage";
653
654         public AltosTimeSeries pyro_voltage;
655
656         public  void set_pyro_voltage(double volts) {
657                 if (pyro_voltage == null)
658                         pyro_voltage = add_series(pyro_voltage_name, AltosConvert.voltage);
659                 pyro_voltage.add(time(), volts);
660         }
661
662         private static String[] igniter_voltage_names;
663
664         public String igniter_voltage_name(int channel) {
665                 if (igniter_voltage_names == null || igniter_voltage_names.length <= channel) {
666                         String[] new_igniter_voltage_names = new String[channel + 1];
667                         int     i = 0;
668
669                         if (igniter_voltage_names != null) {
670                                 for (; i < igniter_voltage_names.length; i++)
671                                         new_igniter_voltage_names[i] = igniter_voltage_names[i];
672                         }
673                         for (; i < channel+1; i++)
674                                 new_igniter_voltage_names[i] = AltosLib.igniter_name(i);
675                         igniter_voltage_names = new_igniter_voltage_names;
676                 }
677                 return igniter_voltage_names[channel];
678         }
679
680         public AltosTimeSeries[] igniter_voltage;
681
682         public  void set_igniter_voltage(double[] voltage) {
683                 int channels = voltage.length;
684                 if (igniter_voltage == null || igniter_voltage.length <= channels) {
685                         AltosTimeSeries[]       new_igniter_voltage = new AltosTimeSeries[channels];
686                         int                     i = 0;
687
688                         if (igniter_voltage != null) {
689                                 for (; i < igniter_voltage.length; i++)
690                                         new_igniter_voltage[i] = igniter_voltage[i];
691                         }
692                         for (; i < channels; i++)
693                                 new_igniter_voltage[i] = add_series(igniter_voltage_name(i), AltosConvert.voltage);
694                         igniter_voltage = new_igniter_voltage;
695                 }
696                 for (int channel = 0; channel < voltage.length; channel++)
697                         igniter_voltage[channel].add(time(), voltage[channel]);
698         }
699
700         public static final String pyro_fired_name = "Pyro Channel State";
701
702         public AltosTimeSeries pyro_fired_series;
703
704         int     last_pyro_mask;
705
706         public  void set_pyro_fired(int pyro_mask) {
707                 if (pyro_fired_series == null)
708                         pyro_fired_series = add_series(pyro_fired_name, AltosConvert.pyro_name);
709                 for (int channel = 0; channel < 32; channel++) {
710                         if ((last_pyro_mask & (1 << channel)) == 0 &&
711                             (pyro_mask & (1 << channel)) != 0) {
712                                 pyro_fired_series.add(time(), channel);
713                         }
714                 }
715                 last_pyro_mask = pyro_mask;
716         }
717
718         public void set_companion(AltosCompanion companion) {
719         }
720
721         public void finish() {
722                 compute_orient();
723                 if (speed_series == null) {
724                         speed_series = compute_speed();
725                         if (speed_series != null)
726                                 add_series(speed_series);
727                 }
728                 if (accel_series == null) {
729                         accel_series = compute_accel();
730                         if (accel_series != null) {
731                                 add_series(accel_series);
732                                 accel_computed = true;
733                         }
734                 }
735                 compute_height();
736         }
737
738         public AltosTimeSeries[] series() {
739                 finish();
740                 return series.toArray(new AltosTimeSeries[0]);
741         }
742
743         public AltosFlightSeries(AltosCalData cal_data) {
744                 super(cal_data);
745         }
746 }