altos/altosui: Log averaged baro sensor data in Tm/Tn
authorKeith Packard <keithp@keithp.com>
Sun, 10 Apr 2011 05:53:12 +0000 (22:53 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 10 Apr 2011 05:53:12 +0000 (22:53 -0700)
Instead of logging the best height guess from the kalman filter, log
barometer data. The logged data consists of the average value betwen
log points to reduce noise.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/Altos.java
altosui/AltosDataPoint.java
altosui/AltosDataPointReader.java
altosui/AltosEepromDownload.java
altosui/AltosEepromIterable.java
altosui/AltosGraphUI.java
src/ao_log_tiny.c

index 1f791da5b8b0f77b7c7dcd8f28ca5aa549d3c6fe..54aced3222fa27571cc02acefebd826990bae7e3 100644 (file)
@@ -34,7 +34,7 @@ public class Altos {
        static final int AO_LOG_GPS_ALT = 'H';
        static final int AO_LOG_GPS_SAT = 'V';
        static final int AO_LOG_GPS_DATE = 'Y';
        static final int AO_LOG_GPS_ALT = 'H';
        static final int AO_LOG_GPS_SAT = 'V';
        static final int AO_LOG_GPS_DATE = 'Y';
-       static final int AO_LOG_HEIGHT = 'h';
+       static final int AO_LOG_PRESSURE = 'P';
 
        /* Added for header fields in eeprom files */
        static final int AO_LOG_CONFIG_VERSION = 1000;
 
        /* Added for header fields in eeprom files */
        static final int AO_LOG_CONFIG_VERSION = 1000;
index 66313e03a8a2b3fe06c50435bb5d918ed3977f6f..5e07732026aeb2562b33eabeecfe7884b172c65c 100644 (file)
@@ -25,5 +25,6 @@ interface AltosDataPoint {
     double battery_voltage();
     double drogue_voltage();
     double main_voltage();
     double battery_voltage();
     double drogue_voltage();
     double main_voltage();
+    boolean has_accel();
 }
 
 }
 
index 4335421c21a96922e0ef0f3bf6f3026efcdcfb3f..fa48013f3b1053a65678ee02f6535aa834cb5035 100644 (file)
@@ -59,6 +59,7 @@ class AltosDataPointReader implements Iterable<AltosDataPoint> {
             public double battery_voltage() { return record.battery_voltage(); }
             public double drogue_voltage() { return record.drogue_voltage(); }
             public double main_voltage() { return record.main_voltage(); }
             public double battery_voltage() { return record.battery_voltage(); }
             public double drogue_voltage() { return record.drogue_voltage(); }
             public double main_voltage() { return record.main_voltage(); }
+           public boolean has_accel() { return has_accel; }
         };
     }
 
         };
     }
 
index fad1646072e2890604773c14f31ab51594e4f03b..a42f401c50654d1683e903e29f27764b6960e7d4 100644 (file)
@@ -162,7 +162,8 @@ public class AltosEepromDownload implements Runnable {
                                } else {
                                        if (v != 0xffff)
                                                any_valid = true;
                                } else {
                                        if (v != 0xffff)
                                                any_valid = true;
-                                       r = new AltosEepromRecord(Altos.AO_LOG_HEIGHT, tiny_tick, v, 0);
+
+                                       r = new AltosEepromRecord(Altos.AO_LOG_PRESSURE, tiny_tick, 0, v);
 
                                        /*
                                         * The flight software records ascent data every 100ms, and descent
 
                                        /*
                                         * The flight software records ascent data every 100ms, and descent
index 624e1dd31bb7c1645a4f3d8f098db2df6f2e0edd..16349b884ec8729e52b9ad18fe4c7373f6c8eee7 100644 (file)
@@ -134,8 +134,13 @@ public class AltosEepromIterable extends AltosRecordIterable {
                        eeprom.seen |= seen_sensor;
                        has_accel = true;
                        break;
                        eeprom.seen |= seen_sensor;
                        has_accel = true;
                        break;
-               case Altos.AO_LOG_HEIGHT:
-                       state.height = (short) record.a;
+               case Altos.AO_LOG_PRESSURE:
+                       state.pres = record.b;
+                       state.flight_pres = state.pres;
+                       if (eeprom.n_pad_samples == 0) {
+                               eeprom.n_pad_samples++;
+                               state.ground_pres = state.pres;
+                       }
                        eeprom.seen |= seen_sensor;
                        break;
                case Altos.AO_LOG_TEMP_VOLT:
                        eeprom.seen |= seen_sensor;
                        break;
                case Altos.AO_LOG_TEMP_VOLT:
index e98c302bf9af1c4863dd50cbf52390fd359d0a28..4b994b4775cafd84ddadc4a0d6cc4211cdd9ab6b 100644 (file)
@@ -35,7 +35,7 @@ public class AltosGraphUI extends JFrame
         AltosGraphTime.Element speed =
             new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { 
                 public void gotTimeData(double time, AltosDataPoint d) {
         AltosGraphTime.Element speed =
             new AltosGraphTime.TimeSeries("Speed (m/s)", "Vertical Speed", green) { 
                 public void gotTimeData(double time, AltosDataPoint d) {
-                    if (d.state() < Altos.ao_flight_drogue) {
+                   if (d.state() < Altos.ao_flight_drogue && d.has_accel()) {
                         series.add(time, d.accel_speed());
                     } else {
                         series.add(time, d.baro_speed());
                         series.add(time, d.accel_speed());
                     } else {
                         series.add(time, d.baro_speed());
index f0c0662aa4dbd6a3ba0437121d8622d57ea390d9..6c2468fc3ea7e6f56b6cb5d89bc118bdb928b8f8 100644 (file)
@@ -44,9 +44,12 @@ static void ao_log_tiny_data(uint16_t d)
 void
 ao_log(void)
 {
 void
 ao_log(void)
 {
-       uint16_t                time;
-       int16_t                 delay;
+       uint16_t                last_time;
+       uint16_t                now;
        enum ao_flight_state    ao_log_tiny_state;
        enum ao_flight_state    ao_log_tiny_state;
+       int32_t                 sum;
+       int16_t                 count;
+       uint8_t                 ao_log_adc;
 
        ao_storage_setup();
 
 
        ao_storage_setup();
 
@@ -57,9 +60,19 @@ ao_log(void)
        while (!ao_log_running)
                ao_sleep(&ao_log_running);
 
        while (!ao_log_running)
                ao_sleep(&ao_log_running);
 
-       time = ao_time();
        ao_log_tiny_data(ao_flight_number);
        ao_log_tiny_data(ao_flight_number);
+       ao_log_tiny_data(ao_ground_pres);
+       sum = 0;
+       count = 0;
+       ao_log_adc = ao_sample_adc;
+       last_time = ao_time();
        for (;;) {
        for (;;) {
+               ao_sleep(DATA_TO_XDATA(&ao_sample_adc));
+               while (ao_log_adc != ao_sample_adc) {
+                       sum += ao_adc_ring[ao_log_adc].pres;
+                       count++;
+                       ao_log_adc = ao_adc_ring_next(ao_log_adc);
+               }
                if (ao_flight_state != ao_log_tiny_state) {
                        ao_log_tiny_data(ao_flight_state | 0x8000);
                        ao_log_tiny_state = ao_flight_state;
                if (ao_flight_state != ao_log_tiny_state) {
                        ao_log_tiny_data(ao_flight_state | 0x8000);
                        ao_log_tiny_state = ao_flight_state;
@@ -69,14 +82,16 @@ ao_log(void)
                        if (ao_log_tiny_state == ao_flight_landed)
                                ao_log_stop();
                }
                        if (ao_log_tiny_state == ao_flight_landed)
                                ao_log_stop();
                }
-               ao_log_tiny_data(ao_height);
-               time += ao_log_tiny_interval;
-               delay = time - ao_time();
-               if (delay > 0)
-                       ao_delay(delay);
                /* Stop logging when told to */
                /* Stop logging when told to */
-               while (!ao_log_running)
-                       ao_sleep(&ao_log_running);
+               if (!ao_log_running)
+                       ao_exit();
+               now = ao_time();
+               if ((int16_t) (now - (last_time + ao_log_tiny_interval)) >= 0 && count) {
+                       ao_log_tiny_data(sum / count);
+                       sum = 0;
+                       count = 0;
+                       last_time = now;
+               }
        }
 }
 
        }
 }