Collect GPS data asynchronously. Maybe we can reduce the update rate on the GPS to save power?

master
Richard Meadows 2015-10-06 20:17:39 +01:00
rodzic a625416787
commit 599e677a20
4 zmienionych plików z 28 dodań i 55 usunięć

Wyświetl plik

@ -33,7 +33,6 @@
*/
typedef enum {
IDLE_NONE,
IDLE_WAIT_FOR_GPS = 0x90137526,
IDLE_TELEMETRY_ACTIVE = 0x15476064,
IDLE_WAIT_FOR_NEXT_TELEMETRY = 0x36749870,
} idle_wait_t;
@ -43,12 +42,10 @@ typedef enum {
* is triggered. Values defined to be well above values encountered in
* normal operation.
*/
#define MAXIDLE_WAIT_FOR_GPS 2400
#define MAXIDLE_WHILE_TELEMETRY_ACTIVE 60000
#define MAXIDLE_WAIT_FOR_NEXT_TELEMETRY 30000
struct idle_counter {
uint32_t wait_for_gps;
uint32_t while_telemetry_active;
uint32_t wait_for_next_telemetry;
};

Wyświetl plik

@ -115,7 +115,7 @@ void read_gps_time(void)
while (gps_update_time_pending() &&
(cron_current_job_ticks() - ticks_delta_start) <= 3) {
idle(IDLE_WAIT_FOR_GPS);
idle(IDLE_WAIT_FOR_NEXT_TELEMETRY);
}
/* If no error and no timeout */
@ -220,7 +220,7 @@ void do_cron(void)
if ((time.second % 30) == 0) {
dp = collect_data();
memcpy(&dp->time, &time, sizeof(struct tracker_time));
} else if ((time.second % 30) == 20) {
} else if ((time.second % 30) == 25) {
collect_data_async();
}

Wyświetl plik

@ -34,12 +34,6 @@
#include "telemetry.h"
#include "watchdog.h"
/**
* GPS timeout and retries
*/
#define GPS_POSITION_RETRIES 5
uint32_t ticks_delta_start;
struct tracker_datapoint datapoint = {.time={0}};
void xosc_measure_callback(uint32_t result)
@ -49,10 +43,13 @@ void xosc_measure_callback(uint32_t result)
/**
* Collect data asynchronously
* Collect data asynchronously. Should be run a few seconds before the collect_data routine
*/
void collect_data_async(void)
{
/* Ask GPS for latest fix */
gps_update_position();
/* Measure XOSC against gps timepulse */
measure_xosc(XOSC_MEASURE_TIMEPULSE, xosc_measure_callback);
@ -60,12 +57,10 @@ void collect_data_async(void)
start_adc_conversion_sequence();
}
/**
* Collect Data synchronously and return datapoint
* Collects data synchronously and return datapoint
*/
struct tracker_datapoint* collect_data(void)
{
uint8_t gps_retries = 0;
/**
* ---- Analogue ----
*/
@ -73,47 +68,34 @@ struct tracker_datapoint* collect_data(void)
datapoint.solar = get_solar(); /* Will return zero by default */
datapoint.temperature = telemetry_si_temperature();
/**
* ---- GPS ----
*/
do {
/* Record current ticks */
ticks_delta_start = cron_current_job_ticks();
if (gps_update_position_pending() || (gps_get_error_state() != GPS_NOERROR)) {
/* Error updating GPS position */
gps_update_position();
/* TODO: Hit reset on the GPS? */
/* In the meantime just wait for the watchdog */
while (1);
/* Wait for the gps update. Timeout after 3 ticks */
while (gps_update_position_pending() &&
(cron_current_job_ticks() - ticks_delta_start) <= 3) {
} else { /* GPS position updated correctly */
idle(IDLE_WAIT_FOR_GPS);
/* GPS Status */
struct ubx_nav_sol sol = gps_get_nav_sol();
datapoint.satillite_count = sol.payload.numSV;
/* GPS Position */
if (gps_is_locked()) {
struct ubx_nav_posllh pos = gps_get_nav_posllh();
datapoint.latitude = pos.payload.lat;
datapoint.longitude = pos.payload.lon;
datapoint.altitude = pos.payload.height;
}
/* In the case of a error or timeout keep retrying up to 5
* times */
} while (((gps_get_error_state() != GPS_NOERROR) ||
(cron_current_job_ticks() - ticks_delta_start) > 3)
&& gps_retries++ < GPS_POSITION_RETRIES);
/* Halt and wait for hw watchdog */
if (gps_retries >= GPS_POSITION_RETRIES) { while (1); }
/* GPS Status */
struct ubx_nav_sol sol = gps_get_nav_sol();
datapoint.satillite_count = sol.payload.numSV;
/* GPS Position */
if (gps_is_locked()) {
struct ubx_nav_posllh pos = gps_get_nav_posllh();
datapoint.latitude = pos.payload.lat;
datapoint.longitude = pos.payload.lon;
datapoint.altitude = pos.payload.height;
/* GPS Powersave */
gps_set_powersave_auto();
}
/* GPS Powersave */
gps_set_powersave_auto();
return &datapoint;
}

Wyświetl plik

@ -47,9 +47,6 @@ idle_wait_t last_idle_t = IDLE_NONE;
void increment_idle_counter(idle_wait_t idle_t)
{
switch (idle_t) {
case IDLE_WAIT_FOR_GPS:
idle_count.wait_for_gps++;
break;
case IDLE_TELEMETRY_ACTIVE:
idle_count.while_telemetry_active++;
break;
@ -66,8 +63,7 @@ void increment_idle_counter(idle_wait_t idle_t)
*/
void check_idle_counters(void)
{
if ((idle_count.wait_for_gps > MAXIDLE_WAIT_FOR_GPS) ||
(idle_count.while_telemetry_active > MAXIDLE_WHILE_TELEMETRY_ACTIVE) ||
if ((idle_count.while_telemetry_active > MAXIDLE_WHILE_TELEMETRY_ACTIVE) ||
(idle_count.wait_for_next_telemetry > MAXIDLE_WAIT_FOR_NEXT_TELEMETRY)) {
/* Oh dear. Let's die here */
while (1);
@ -80,7 +76,6 @@ void check_idle_counters(void)
*/
void clear_idle_counters(void)
{
SET_COUNT_MAX(wait_for_gps);
SET_COUNT_MAX(while_telemetry_active);
SET_COUNT_MAX(wait_for_next_telemetry);
@ -118,8 +113,7 @@ void kick_the_watchdog(void)
void idle(idle_wait_t idle_t)
{
/* Check valid */
if ((idle_t != IDLE_WAIT_FOR_GPS) &&
(idle_t != IDLE_TELEMETRY_ACTIVE) &&
if ((idle_t != IDLE_TELEMETRY_ACTIVE) &&
(idle_t != IDLE_WAIT_FOR_NEXT_TELEMETRY)) {
/* Oh dear */
while (1);