diff options
Diffstat (limited to 'ao-tools/lib')
-rw-r--r-- | ao-tools/lib/cc-analyse.c | 14 | ||||
-rw-r--r-- | ao-tools/lib/cc-integrate.c | 21 | ||||
-rw-r--r-- | ao-tools/lib/cc-period.c | 26 | ||||
-rw-r--r-- | ao-tools/lib/cc-process.c | 20 | ||||
-rw-r--r-- | ao-tools/lib/cc.h | 12 |
5 files changed, 60 insertions, 33 deletions
diff --git a/ao-tools/lib/cc-analyse.c b/ao-tools/lib/cc-analyse.c index cdb16f02..27c416a6 100644 --- a/ao-tools/lib/cc-analyse.c +++ b/ao-tools/lib/cc-analyse.c @@ -18,6 +18,20 @@ #include "cc.h" #include <math.h> +void +cc_timedata_limits(struct cc_timedata *d, double min_time, double max_time, int *start, int *stop) +{ + int i; + + *start = -1; + for (i = 0; i < d->num; i++) { + if (*start < 0 && min_time <= d->data[i].time) + *start = i; + if (d->data[i].time <= max_time) + *stop = i; + } +} + int cc_timedata_min(struct cc_timedata *d, double min_time, double max_time) { diff --git a/ao-tools/lib/cc-integrate.c b/ao-tools/lib/cc-integrate.c index f9793dcd..ba50761b 100644 --- a/ao-tools/lib/cc-integrate.c +++ b/ao-tools/lib/cc-integrate.c @@ -37,24 +37,27 @@ cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), doub } struct cc_timedata * -cc_timedata_integrate(struct cc_timedata *d) +cc_timedata_integrate(struct cc_timedata *d, double min_time, double max_time) { struct cc_timedata *i; - int n; + int n, m; + int start, stop; + cc_timedata_limits(d, min_time, max_time, &start, &stop); i = calloc (1, sizeof (struct cc_timedata)); - i->num = d->num; - i->size = d->num; + i->num = stop - start + 1; + i->size = i->num; i->data = calloc (i->size, sizeof (struct cc_timedataelt)); - i->time_offset = d->time_offset; - for (n = 0; n < d->num; n++) { - i->data[n].time = d->data[n].time; + i->time_offset = d->data[start].time; + for (n = 0; n < i->num; n++) { + m = n + start; + i->data[n].time = d->data[m].time; if (n == 0) { i->data[n].value = 0; } else { i->data[n].value = i->data[n-1].value + - (d->data[n].value + d->data[n-1].value) / 2 * - ((d->data[n].time - d->data[n-1].time) / 100.0); + (d->data[m].value + d->data[m-1].value) / 2 * + ((d->data[m].time - d->data[m-1].time) / 100.0); } } return i; diff --git a/ao-tools/lib/cc-period.c b/ao-tools/lib/cc-period.c index c74cf9dc..2a4e5952 100644 --- a/ao-tools/lib/cc-period.c +++ b/ao-tools/lib/cc-period.c @@ -17,35 +17,27 @@ #include "cc.h" #include <stdlib.h> +#include <math.h> struct cc_perioddata * cc_period_make(struct cc_timedata *td, double start_time, double stop_time) { int len = stop_time - start_time + 1; struct cc_perioddata *pd; - int i; - double prev_time; - double next_time; - double interval; + int i, j; + double t; pd = calloc(1, sizeof (struct cc_perioddata)); pd->start = start_time; pd->step = 1; pd->num = len; pd->data = calloc(len, sizeof(double)); - prev_time = start_time; - for (i = 0; i < td->num; i++) { - if (start_time <= td->data[i].time && td->data[i].time <= stop_time) { - int pos = td->data[i].time - start_time; - - if (i < td->num - 1 && td->data[i+1].time < stop_time) - next_time = (td->data[i].time + td->data[i+1].time) / 2.0; - else - next_time = stop_time; - interval = next_time - prev_time; - pd->data[pos] = td->data[i].value * interval; - prev_time = next_time; - } + j = 0; + for (i = 0; i < pd->num; i++) { + t = start_time + i * pd->step; + while (j < td->num - 1 && fabs(t - td->data[j].time) > fabs(t - td->data[j+1].time)) + j++; + pd->data[i] = td->data[j].value; } return pd; } diff --git a/ao-tools/lib/cc-process.c b/ao-tools/lib/cc-process.c index 469ad2f2..5c1acc6b 100644 --- a/ao-tools/lib/cc-process.c +++ b/ao-tools/lib/cc-process.c @@ -33,8 +33,6 @@ cook_timed(struct cc_timedata *td, struct cc_perioddata *pd, free (filtered); free (unfiltered->data); free (unfiltered); - free (td->data); - free (td); } static double @@ -93,11 +91,15 @@ cc_flight_cook(struct cc_flightraw *raw) } else { flight_stop = raw->accel.data[raw->accel.num-1].time; } + cooked->flight_start = flight_start; + cooked->flight_stop = flight_stop; /* Integrate the accelerometer data to get speed and position */ accel = cc_timedata_convert(&raw->accel, cc_accelerometer_to_acceleration, raw->ground_accel); - accel_speed = cc_timedata_integrate(accel); - accel_pos = cc_timedata_integrate(accel_speed); + cooked->accel = *accel; + free(accel); + accel_speed = cc_timedata_integrate(&cooked->accel, flight_start - 10, flight_stop); + accel_pos = cc_timedata_integrate(accel_speed, flight_start - 10, flight_stop); #define ACCEL_OMEGA_PASS (2 * M_PI * 5 / 100) #define ACCEL_OMEGA_STOP (2 * M_PI * 8 / 100) @@ -105,20 +107,24 @@ cc_flight_cook(struct cc_flightraw *raw) #define BARO_OMEGA_STOP (2 * M_PI * 1 / 100) #define FILTER_ERROR (1e-8) - cook_timed(accel, &cooked->accel_accel, + cook_timed(&cooked->accel, &cooked->accel_accel, flight_start, flight_stop, ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); cook_timed(accel_speed, &cooked->accel_speed, flight_start, flight_stop, ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + free(accel_speed->data); free(accel_speed); cook_timed(accel_pos, &cooked->accel_pos, flight_start, flight_stop, ACCEL_OMEGA_PASS, ACCEL_OMEGA_STOP, FILTER_ERROR); + free(accel_pos->data); free(accel_pos); /* Filter the pressure data */ pres = cc_timedata_convert(&raw->pres, barometer_to_altitude, cc_barometer_to_altitude(raw->ground_pres)); - cook_timed(pres, &cooked->pres_pos, + cooked->pres = *pres; + free(pres); + cook_timed(&cooked->pres, &cooked->pres_pos, flight_start, flight_stop, BARO_OMEGA_PASS, BARO_OMEGA_STOP, FILTER_ERROR); /* differentiate twice to get to acceleration */ @@ -154,5 +160,7 @@ cc_flightcooked_free(struct cc_flightcooked *cooked) if_free(cooked->gps_lon.data); if_free(cooked->gps_alt.data); if_free(cooked->state.data); + if_free(cooked->accel.data); + if_free(cooked->pres.data); free(cooked); } diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h index 4e9aadc4..01226958 100644 --- a/ao-tools/lib/cc.h +++ b/ao-tools/lib/cc.h @@ -142,6 +142,9 @@ void cc_flightraw_free(struct cc_flightraw *raw); struct cc_flightcooked { + double flight_start; + double flight_stop; + struct cc_perioddata accel_accel; struct cc_perioddata accel_speed; struct cc_perioddata accel_pos; @@ -151,6 +154,10 @@ struct cc_flightcooked { struct cc_perioddata gps_lat; struct cc_perioddata gps_lon; struct cc_perioddata gps_alt; + + /* unfiltered, but converted */ + struct cc_timedata pres; + struct cc_timedata accel; struct cc_timedata state; }; @@ -262,6 +269,9 @@ cc_great_circle (double start_lat, double start_lon, double end_lat, double end_lon, double *dist, double *bearing); +void +cc_timedata_limits(struct cc_timedata *d, double min_time, double max_time, int *start, int *stop); + int cc_timedata_min(struct cc_timedata *d, double min_time, double max_time); @@ -314,7 +324,7 @@ struct cc_timedata * cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), double a); struct cc_timedata * -cc_timedata_integrate(struct cc_timedata *d); +cc_timedata_integrate(struct cc_timedata *d, double min_time, double max_time); struct cc_perioddata * cc_perioddata_differentiate(struct cc_perioddata *i); |