mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +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"
|
"ROLL", "PITCH", "YAW"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char * const lookupTablePositionAltSource[] = {
|
||||||
|
"DEFAULT", "BARO_ONLY", "GPS_ONLY"
|
||||||
|
};
|
||||||
|
|
||||||
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
|
||||||
|
|
||||||
const lookupTableEntry_t lookupTables[] = {
|
const lookupTableEntry_t lookupTables[] = {
|
||||||
|
@ -566,6 +570,8 @@ const lookupTableEntry_t lookupTables[] = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LOOKUP_TABLE_ENTRY(lookupTableGyroFilterDebug),
|
LOOKUP_TABLE_ENTRY(lookupTableGyroFilterDebug),
|
||||||
|
|
||||||
|
LOOKUP_TABLE_ENTRY(lookupTablePositionAltSource)
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef LOOKUP_TABLE_ENTRY
|
#undef LOOKUP_TABLE_ENTRY
|
||||||
|
@ -1445,6 +1451,9 @@ const clivalue_t valueTable[] = {
|
||||||
#ifdef USE_OSD
|
#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) },
|
{ "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
|
#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);
|
const uint16_t valueTableEntryCount = ARRAYLEN(valueTable);
|
||||||
|
|
|
@ -133,6 +133,7 @@ typedef enum {
|
||||||
TABLE_LEDSTRIP_COLOR,
|
TABLE_LEDSTRIP_COLOR,
|
||||||
#endif
|
#endif
|
||||||
TABLE_GYRO_FILTER_DEBUG,
|
TABLE_GYRO_FILTER_DEBUG,
|
||||||
|
TABLE_POSITION_ALT_SOURCE,
|
||||||
LOOKUP_TABLE_COUNT
|
LOOKUP_TABLE_COUNT
|
||||||
} lookupTableIndex_e;
|
} lookupTableIndex_e;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,21 @@
|
||||||
#include "sensors/sensors.h"
|
#include "sensors/sensors.h"
|
||||||
#include "sensors/barometer.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
|
static int32_t estimatedAltitudeCm = 0; // in cm
|
||||||
|
|
||||||
#define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25)
|
#define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25)
|
||||||
|
@ -129,24 +144,27 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
|
||||||
baroAlt -= baroAltOffset;
|
baroAlt -= baroAltOffset;
|
||||||
gpsAlt -= gpsAltOffset;
|
gpsAlt -= gpsAltOffset;
|
||||||
|
|
||||||
if (haveGpsAlt && haveBaroAlt) {
|
|
||||||
|
if (haveGpsAlt && haveBaroAlt && positionConfig()->altSource == DEFAULT) {
|
||||||
estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust);
|
estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust);
|
||||||
#ifdef USE_VARIO
|
#ifdef USE_VARIO
|
||||||
// baro is a better source for vario, so ignore gpsVertSpeed
|
// baro is a better source for vario, so ignore gpsVertSpeed
|
||||||
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
|
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
|
||||||
#endif
|
#endif
|
||||||
} else if (haveGpsAlt) {
|
} else if (haveGpsAlt && (positionConfig()->altSource == GPS_ONLY || positionConfig()->altSource == DEFAULT )) {
|
||||||
estimatedAltitudeCm = gpsAlt;
|
estimatedAltitudeCm = gpsAlt;
|
||||||
#if defined(USE_VARIO) && defined(USE_GPS)
|
#if defined(USE_VARIO) && defined(USE_GPS)
|
||||||
estimatedVario = gpsVertSpeed;
|
estimatedVario = gpsVertSpeed;
|
||||||
#endif
|
#endif
|
||||||
} else if (haveBaroAlt) {
|
} else if (haveBaroAlt && (positionConfig()->altSource == BARO_ONLY || positionConfig()->altSource == DEFAULT)) {
|
||||||
estimatedAltitudeCm = baroAlt;
|
estimatedAltitudeCm = baroAlt;
|
||||||
#ifdef USE_VARIO
|
#ifdef USE_VARIO
|
||||||
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
|
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DEBUG_SET(DEBUG_ALTITUDE, 0, (int32_t)(100 * gpsTrust));
|
DEBUG_SET(DEBUG_ALTITUDE, 0, (int32_t)(100 * gpsTrust));
|
||||||
DEBUG_SET(DEBUG_ALTITUDE, 1, baroAlt);
|
DEBUG_SET(DEBUG_ALTITUDE, 1, baroAlt);
|
||||||
DEBUG_SET(DEBUG_ALTITUDE, 2, gpsAlt);
|
DEBUG_SET(DEBUG_ALTITUDE, 2, gpsAlt);
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
|
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
|
|
||||||
|
typedef struct positionConfig_s {
|
||||||
|
uint8_t altSource;
|
||||||
|
} positionConfig_t;
|
||||||
|
|
||||||
|
PG_DECLARE(positionConfig_t, positionConfig);
|
||||||
|
|
||||||
bool isAltitudeOffset(void);
|
bool isAltitudeOffset(void);
|
||||||
void calculateEstimatedAltitude(timeUs_t currentTimeUs);
|
void calculateEstimatedAltitude(timeUs_t currentTimeUs);
|
||||||
int32_t getEstimatedAltitudeCm(void);
|
int32_t getEstimatedAltitudeCm(void);
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
#define PG_IBUS_TELEMETRY_CONFIG 53 // CF 1.x
|
#define PG_IBUS_TELEMETRY_CONFIG 53 // CF 1.x
|
||||||
//#define PG_VTX_CONFIG 54 // CF 1.x
|
//#define PG_VTX_CONFIG 54 // CF 1.x
|
||||||
#define PG_GPS_RESCUE 55 // struct OK
|
#define PG_GPS_RESCUE 55 // struct OK
|
||||||
|
#define PG_POSITION 56
|
||||||
|
|
||||||
// Driver configuration
|
// Driver configuration
|
||||||
#define PG_DRIVER_PWM_RX_CONFIG 100 // does not exist in betaflight
|
#define PG_DRIVER_PWM_RX_CONFIG 100 // does not exist in betaflight
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue