X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fao_flight.c;h=0a9cc046f2c946e74585c6bd307a5dbe148e96f3;hb=refs%2Ftags%2Fdebian%2F1.0.3;hp=c6cbbf7cbaeb3e26f64bf6069e427fe864f4a561;hpb=011e37f27b3926a42c8c1a74e0f179bb48829ec7;p=fw%2Faltos diff --git a/src/ao_flight.c b/src/ao_flight.c index c6cbbf7c..0a9cc046 100644 --- a/src/ao_flight.c +++ b/src/ao_flight.c @@ -43,8 +43,7 @@ __pdata uint16_t ao_launch_tick; /* time of launch detect */ __pdata uint16_t ao_interval_end; __pdata int16_t ao_interval_min_height; __pdata int16_t ao_interval_max_height; - -__xdata uint8_t ao_flight_force_idle; +__pdata uint8_t ao_flight_force_idle; /* We also have a clock, which can be used to sanity check things in * case of other failures @@ -55,7 +54,7 @@ __xdata uint8_t ao_flight_force_idle; /* Landing is detected by getting constant readings from both pressure and accelerometer * for a fairly long time (AO_INTERVAL_TICKS) */ -#define AO_INTERVAL_TICKS AO_SEC_TO_TICKS(5) +#define AO_INTERVAL_TICKS AO_SEC_TO_TICKS(10) #define abs(a) ((a) < 0 ? -(a) : (a)) @@ -92,6 +91,8 @@ ao_flight(void) */ ao_flight_state = ao_flight_invalid; + /* Turn on packet system in invalid mode on TeleMetrum */ + ao_packet_slave_start(); } else #endif if (!ao_flight_force_idle @@ -109,8 +110,10 @@ ao_flight(void) ao_usb_disable(); #endif - /* Disable packet mode in pad state */ +#if !HAS_ACCEL + /* Disable packet mode in pad state on TeleMini */ ao_packet_slave_stop(); +#endif /* Turn on telemetry system */ ao_rdf_set(1); @@ -122,6 +125,11 @@ ao_flight(void) /* Set idle mode */ ao_flight_state = ao_flight_idle; +#if HAS_ACCEL + /* Turn on packet system in idle mode on TeleMetrum */ + ao_packet_slave_start(); +#endif + /* signal successful initialization by turning off the LED */ ao_led_off(AO_LED_RED); } @@ -170,7 +178,6 @@ ao_flight(void) #endif ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); - break; } break; case ao_flight_boost: @@ -194,7 +201,6 @@ ao_flight(void) ao_flight_state = ao_flight_coast; #endif ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); - break; } break; #if HAS_ACCEL @@ -208,7 +214,6 @@ ao_flight(void) { ao_flight_state = ao_flight_coast; ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); - break; } break; #endif @@ -237,16 +242,6 @@ ao_flight(void) /* Turn the RDF beacon back on */ ao_rdf_set(1); - /* - * Start recording min/max height - * to figure out when the rocket has landed - */ - - /* initialize interval values */ - ao_interval_end = ao_sample_tick + AO_INTERVAL_TICKS; - - ao_interval_min_height = ao_interval_max_height = ao_height; - /* and enter drogue state */ ao_flight_state = ao_flight_drogue; ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); @@ -270,26 +265,37 @@ ao_flight(void) if (ao_height <= ao_config.main_deploy) { ao_ignite(ao_igniter_main); + + /* + * Start recording min/max height + * to figure out when the rocket has landed + */ + + /* initialize interval values */ + ao_interval_end = ao_sample_tick + AO_INTERVAL_TICKS; + + ao_interval_min_height = ao_interval_max_height = ao_avg_height; + ao_flight_state = ao_flight_main; ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); } + break; /* fall through... */ case ao_flight_main: - /* drogue/main to land: + /* main to land: * - * barometer: altitude stable and within 1000m of the launch altitude + * barometer: altitude stable */ - if (ao_height < ao_interval_min_height) - ao_interval_min_height = ao_height; - if (ao_height > ao_interval_max_height) - ao_interval_max_height = ao_height; + if (ao_avg_height < ao_interval_min_height) + ao_interval_min_height = ao_avg_height; + if (ao_avg_height > ao_interval_max_height) + ao_interval_max_height = ao_avg_height; if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) { - if (ao_height < AO_M_TO_HEIGHT(1000) && - ao_interval_max_height - ao_interval_min_height < AO_M_TO_HEIGHT(5)) + if (ao_interval_max_height - ao_interval_min_height <= AO_M_TO_HEIGHT(4)) { ao_flight_state = ao_flight_landed; @@ -298,7 +304,7 @@ ao_flight(void) ao_wakeup(DATA_TO_XDATA(&ao_flight_state)); } - ao_interval_min_height = ao_interval_max_height = ao_height; + ao_interval_min_height = ao_interval_max_height = ao_avg_height; ao_interval_end = ao_sample_tick + AO_INTERVAL_TICKS; } break;