mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Altitde source calculation option (#8127)
Altitde source calculation option
This commit is contained in:
commit
adb4ca39ec
5 changed files with 38 additions and 3 deletions
|
@ -455,6 +455,10 @@ static const char * const lookupTableGyroFilterDebug[] = {
|
|||
"ROLL", "PITCH", "YAW"
|
||||
};
|
||||
|
||||
static const char * const lookupTablePositionAltSource[] = {
|
||||
"DEFAULT", "BARO_ONLY", "GPS_ONLY"
|
||||
};
|
||||
|
||||
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
||||
|
||||
const lookupTableEntry_t lookupTables[] = {
|
||||
|
@ -566,6 +570,8 @@ const lookupTableEntry_t lookupTables[] = {
|
|||
#endif
|
||||
|
||||
LOOKUP_TABLE_ENTRY(lookupTableGyroFilterDebug),
|
||||
|
||||
LOOKUP_TABLE_ENTRY(lookupTablePositionAltSource)
|
||||
};
|
||||
|
||||
#undef LOOKUP_TABLE_ENTRY
|
||||
|
@ -1445,6 +1451,9 @@ const clivalue_t valueTable[] = {
|
|||
#ifdef USE_OSD
|
||||
{ "display_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, displayName) },
|
||||
#endif
|
||||
|
||||
// PG_POSITION
|
||||
{ "position_alt_source", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_POSITION_ALT_SOURCE }, PG_POSITION, offsetof(positionConfig_t, altSource) },
|
||||
};
|
||||
|
||||
const uint16_t valueTableEntryCount = ARRAYLEN(valueTable);
|
||||
|
|
|
@ -133,6 +133,7 @@ typedef enum {
|
|||
TABLE_LEDSTRIP_COLOR,
|
||||
#endif
|
||||
TABLE_GYRO_FILTER_DEBUG,
|
||||
TABLE_POSITION_ALT_SOURCE,
|
||||
LOOKUP_TABLE_COUNT
|
||||
} lookupTableIndex_e;
|
||||
|
||||
|
|
|
@ -41,6 +41,21 @@
|
|||
#include "sensors/sensors.h"
|
||||
#include "sensors/barometer.h"
|
||||
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
|
||||
typedef enum {
|
||||
DEFAULT = 0,
|
||||
BARO_ONLY,
|
||||
GPS_ONLY
|
||||
} altSource_e;
|
||||
|
||||
PG_REGISTER_WITH_RESET_TEMPLATE(positionConfig_t, positionConfig, PG_POSITION, 1);
|
||||
|
||||
PG_RESET_TEMPLATE(positionConfig_t, positionConfig,
|
||||
.altSource = DEFAULT,
|
||||
);
|
||||
|
||||
static int32_t estimatedAltitudeCm = 0; // in cm
|
||||
|
||||
#define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25)
|
||||
|
@ -129,24 +144,27 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
|
|||
baroAlt -= baroAltOffset;
|
||||
gpsAlt -= gpsAltOffset;
|
||||
|
||||
if (haveGpsAlt && haveBaroAlt) {
|
||||
|
||||
if (haveGpsAlt && haveBaroAlt && positionConfig()->altSource == DEFAULT) {
|
||||
estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust);
|
||||
#ifdef USE_VARIO
|
||||
// baro is a better source for vario, so ignore gpsVertSpeed
|
||||
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
|
||||
#endif
|
||||
} else if (haveGpsAlt) {
|
||||
} else if (haveGpsAlt && (positionConfig()->altSource == GPS_ONLY || positionConfig()->altSource == DEFAULT )) {
|
||||
estimatedAltitudeCm = gpsAlt;
|
||||
#if defined(USE_VARIO) && defined(USE_GPS)
|
||||
estimatedVario = gpsVertSpeed;
|
||||
#endif
|
||||
} else if (haveBaroAlt) {
|
||||
} else if (haveBaroAlt && (positionConfig()->altSource == BARO_ONLY || positionConfig()->altSource == DEFAULT)) {
|
||||
estimatedAltitudeCm = baroAlt;
|
||||
#ifdef USE_VARIO
|
||||
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEBUG_SET(DEBUG_ALTITUDE, 0, (int32_t)(100 * gpsTrust));
|
||||
DEBUG_SET(DEBUG_ALTITUDE, 1, baroAlt);
|
||||
DEBUG_SET(DEBUG_ALTITUDE, 2, gpsAlt);
|
||||
|
|
|
@ -22,6 +22,12 @@
|
|||
|
||||
#include "common/time.h"
|
||||
|
||||
typedef struct positionConfig_s {
|
||||
uint8_t altSource;
|
||||
} positionConfig_t;
|
||||
|
||||
PG_DECLARE(positionConfig_t, positionConfig);
|
||||
|
||||
bool isAltitudeOffset(void);
|
||||
void calculateEstimatedAltitude(timeUs_t currentTimeUs);
|
||||
int32_t getEstimatedAltitudeCm(void);
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#define PG_IBUS_TELEMETRY_CONFIG 53 // CF 1.x
|
||||
//#define PG_VTX_CONFIG 54 // CF 1.x
|
||||
#define PG_GPS_RESCUE 55 // struct OK
|
||||
#define PG_POSITION 56
|
||||
|
||||
// Driver configuration
|
||||
#define PG_DRIVER_PWM_RX_CONFIG 100 // does not exist in betaflight
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue