1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Enables Vario on targets that support barometers

OSD and telemetry output of vario data is enabled on F4 and up targets
that have
USE_BARO defined.  Settings and telem elements are removed from all
other targets.

F3 targets are not supported to free memory.
This commit is contained in:
Blaine 2018-07-30 17:16:05 -07:00
parent adc965327f
commit 2e552841f1
12 changed files with 64 additions and 5 deletions

View file

@ -101,7 +101,9 @@ OSD_Entry menuOsdActiveElemsEntries[] =
{"PIT ANG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PITCH_ANGLE], 0}, {"PIT ANG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PITCH_ANGLE], 0},
{"ROL ANG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ROLL_ANGLE], 0}, {"ROL ANG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ROLL_ANGLE], 0},
{"HEADING", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_NUMERICAL_HEADING], 0}, {"HEADING", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_NUMERICAL_HEADING], 0},
#ifdef USE_VARIO
{"VARIO", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_NUMERICAL_VARIO], 0}, {"VARIO", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_NUMERICAL_VARIO], 0},
#endif
{"G-FORCE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_G_FORCE], 0}, {"G-FORCE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_G_FORCE], 0},
{"FLIP ARROW", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_FLIP_ARROW], 0}, {"FLIP ARROW", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_FLIP_ARROW], 0},
{"BACK", OME_Back, NULL, NULL, 0}, {"BACK", OME_Back, NULL, NULL, 0},

View file

@ -22,6 +22,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <limits.h>
#include "build/debug.h" #include "build/debug.h"
@ -42,6 +43,28 @@ static int32_t estimatedAltitudeCm = 0; // in cm
#define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25) #define BARO_UPDATE_FREQUENCY_40HZ (1000 * 25)
#ifdef USE_VARIO
static int16_t estimatedVario = 0; // in cm/s
int16_t calculateEstimatedVario(int32_t baroAlt, const uint32_t dTime) {
static float vel = 0;
static int32_t lastBaroAlt = 0;
int32_t baroVel = 0;
baroVel = (baroAlt - lastBaroAlt) * 1000000.0f / dTime;
lastBaroAlt = baroAlt;
baroVel = constrain(baroVel, -1500.0f, 1500.0f);
baroVel = applyDeadband(baroVel, 10.0f);
vel = vel * CONVERT_PARAMETER_TO_FLOAT(barometerConfig()->baro_cf_vel) + baroVel * (1.0f - CONVERT_PARAMETER_TO_FLOAT(barometerConfig()->baro_cf_vel));
int32_t vel_tmp = lrintf(vel);
vel_tmp = applyDeadband(vel_tmp, 5.0f);
return constrain(vel_tmp, SHRT_MIN, SHRT_MAX);
}
#endif
#if defined(USE_BARO) || defined(USE_GPS) #if defined(USE_BARO) || defined(USE_GPS)
static bool altitudeOffsetSet = false; static bool altitudeOffsetSet = false;
@ -100,10 +123,16 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) {
if (haveGpsAlt && haveBaroAlt) { if (haveGpsAlt && haveBaroAlt) {
estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust); estimatedAltitudeCm = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust);
#ifdef USE_VARIO
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
#endif
} else if (haveGpsAlt) { } else if (haveGpsAlt) {
estimatedAltitudeCm = gpsAlt; estimatedAltitudeCm = gpsAlt;
} else if (haveBaroAlt) { } else if (haveBaroAlt) {
estimatedAltitudeCm = baroAlt; estimatedAltitudeCm = baroAlt;
#ifdef USE_VARIO
estimatedVario = calculateEstimatedVario(baroAlt, dTime);
#endif
} }
DEBUG_SET(DEBUG_ALTITUDE, 0, (int32_t)(100 * gpsTrust)); DEBUG_SET(DEBUG_ALTITUDE, 0, (int32_t)(100 * gpsTrust));
@ -125,5 +154,9 @@ int32_t getEstimatedAltitudeCm(void)
// This should be removed or fixed, but it would require changing a lot of other things to get rid of. // This should be removed or fixed, but it would require changing a lot of other things to get rid of.
int16_t getEstimatedVario(void) int16_t getEstimatedVario(void)
{ {
#ifdef USE_VARIO
return estimatedVario;
#else
return 0; return 0;
#endif
} }

View file

@ -25,4 +25,4 @@
bool isAltitudeOffset(void); bool isAltitudeOffset(void);
void calculateEstimatedAltitude(timeUs_t currentTimeUs); void calculateEstimatedAltitude(timeUs_t currentTimeUs);
int32_t getEstimatedAltitudeCm(void); int32_t getEstimatedAltitudeCm(void);
int16_t getEstimatedVario(void); int16_t getEstimatedVario(void);

View file

@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h>
#include "platform.h" #include "platform.h"
@ -889,7 +890,11 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
#else #else
sbufWriteU32(dst, 0); sbufWriteU32(dst, 0);
#endif #endif
#ifdef USE_VARIO
sbufWriteU16(dst, getEstimatedVario()); sbufWriteU16(dst, getEstimatedVario());
#else
sbufWriteU16(dst, 0);
#endif
break; break;
case MSP_SONAR_ALTITUDE: case MSP_SONAR_ALTITUDE:

View file

@ -1004,7 +1004,9 @@ const clivalue_t valueTable[] = {
{ "osd_battery_usage_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MAIN_BATT_USAGE]) }, { "osd_battery_usage_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MAIN_BATT_USAGE]) },
{ "osd_disarmed_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_DISARMED]) }, { "osd_disarmed_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_DISARMED]) },
{ "osd_nheading_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_HEADING]) }, { "osd_nheading_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_HEADING]) },
#ifdef USE_VARIO
{ "osd_nvario_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_VARIO]) }, { "osd_nvario_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_VARIO]) },
#endif
{ "osd_esc_tmp_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_TMP]) }, { "osd_esc_tmp_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_TMP]) },
{ "osd_esc_rpm_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_RPM]) }, { "osd_esc_rpm_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_RPM]) },
{ "osd_rtc_date_time_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RTC_DATETIME]) }, { "osd_rtc_date_time_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RTC_DATETIME]) },

View file

@ -976,7 +976,7 @@ static bool osdDrawSingleElement(uint8_t item)
tfp_sprintf(buff, "%c%03d", osdGetDirectionSymbolFromHeading(heading), heading); tfp_sprintf(buff, "%c%03d", osdGetDirectionSymbolFromHeading(heading), heading);
break; break;
} }
#ifdef USE_VARIO
case OSD_NUMERICAL_VARIO: case OSD_NUMERICAL_VARIO:
{ {
const int verticalSpeed = osdGetMetersToSelectedUnit(getEstimatedVario()); const int verticalSpeed = osdGetMetersToSelectedUnit(getEstimatedVario());
@ -984,6 +984,7 @@ static bool osdDrawSingleElement(uint8_t item)
tfp_sprintf(buff, "%c%01d.%01d", directionSymbol, abs(verticalSpeed / 100), abs((verticalSpeed % 100) / 10)); tfp_sprintf(buff, "%c%01d.%01d", directionSymbol, abs(verticalSpeed / 100), abs((verticalSpeed % 100) / 10));
break; break;
} }
#endif
#ifdef USE_ESC_SENSOR #ifdef USE_ESC_SENSOR
case OSD_ESC_TMP: case OSD_ESC_TMP:

View file

@ -56,6 +56,10 @@
#endif #endif
#endif #endif
#ifndef USE_BARO
#undef USE_VARIO
#endif
#if !defined(USE_SERIAL_RX) #if !defined(USE_SERIAL_RX)
#undef USE_SERIALRX_CRSF #undef USE_SERIALRX_CRSF
#undef USE_SERIALRX_IBUS #undef USE_SERIALRX_IBUS

View file

@ -222,4 +222,5 @@
#define USE_ABSOLUTE_CONTROL #define USE_ABSOLUTE_CONTROL
#define USE_HOTT_TEXTMODE #define USE_HOTT_TEXTMODE
#define USE_LED_STRIP #define USE_LED_STRIP
#define USE_VARIO
#endif #endif

View file

@ -529,7 +529,9 @@ void processFrSkyHubTelemetry(timeUs_t currentTimeUs)
// Sent every 125ms // Sent every 125ms
// Send vertical speed for opentx. ID_VERT_SPEED // Send vertical speed for opentx. ID_VERT_SPEED
// Unit is cm/s // Unit is cm/s
#ifdef USE_VARIO
frSkyHubWriteFrame(ID_VERT_SPEED, getEstimatedVario()); frSkyHubWriteFrame(ID_VERT_SPEED, getEstimatedVario());
#endif
// Sent every 500ms // Sent every 500ms
if ((cycleNum % 4) == 0) { if ((cycleNum % 4) == 0) {

View file

@ -309,6 +309,7 @@ static inline void hottEAMUpdateAltitude(HOTT_EAM_MSG_t *hottEAMMessage)
hottEAMMessage->altitude_H = hottEamAltitude >> 8; hottEAMMessage->altitude_H = hottEamAltitude >> 8;
} }
#ifdef USE_VARIO
static inline void hottEAMUpdateClimbrate(HOTT_EAM_MSG_t *hottEAMMessage) static inline void hottEAMUpdateClimbrate(HOTT_EAM_MSG_t *hottEAMMessage)
{ {
const int32_t vario = getEstimatedVario(); const int32_t vario = getEstimatedVario();
@ -316,6 +317,7 @@ static inline void hottEAMUpdateClimbrate(HOTT_EAM_MSG_t *hottEAMMessage)
hottEAMMessage->climbrate_H = (30000 + vario) >> 8; hottEAMMessage->climbrate_H = (30000 + vario) >> 8;
hottEAMMessage->climbrate3s = 120 + (vario / 100); hottEAMMessage->climbrate3s = 120 + (vario / 100);
} }
#endif
void hottPrepareEAMResponse(HOTT_EAM_MSG_t *hottEAMMessage) void hottPrepareEAMResponse(HOTT_EAM_MSG_t *hottEAMMessage)
{ {
@ -327,7 +329,9 @@ void hottPrepareEAMResponse(HOTT_EAM_MSG_t *hottEAMMessage)
hottEAMUpdateCurrentMeter(hottEAMMessage); hottEAMUpdateCurrentMeter(hottEAMMessage);
hottEAMUpdateBatteryDrawnCapacity(hottEAMMessage); hottEAMUpdateBatteryDrawnCapacity(hottEAMMessage);
hottEAMUpdateAltitude(hottEAMMessage); hottEAMUpdateAltitude(hottEAMMessage);
#ifdef USE_VARIO
hottEAMUpdateClimbrate(hottEAMMessage); hottEAMUpdateClimbrate(hottEAMMessage);
#endif
} }
static void hottSerialWrite(uint8_t c) static void hottSerialWrite(uint8_t c)

View file

@ -31,6 +31,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h>
// #include <string.h> // #include <string.h>
#include "platform.h" #include "platform.h"
@ -420,10 +421,10 @@ static void setValue(uint8_t* bufferPtr, uint8_t sensorType, uint8_t length)
break; break;
case IBUS_SENSOR_TYPE_VERTICAL_SPEED: case IBUS_SENSOR_TYPE_VERTICAL_SPEED:
case IBUS_SENSOR_TYPE_CLIMB_RATE: case IBUS_SENSOR_TYPE_CLIMB_RATE:
if(sensors(SENSOR_SONAR) || sensors(SENSOR_BARO)) { #ifdef USE_VARIO
value.int16 = (int16_t)getEstimatedVario(); value.int16 = (int16_t) constrain(getEstimatedVario(), SHRT_MIN, SHRT_MAX);
}
break; break;
#endif
case IBUS_SENSOR_TYPE_ALT: case IBUS_SENSOR_TYPE_ALT:
case IBUS_SENSOR_TYPE_ALT_MAX: case IBUS_SENSOR_TYPE_ALT_MAX:
value.int32 = baro.BaroAlt; value.int32 = baro.BaroAlt;

View file

@ -196,7 +196,9 @@ void initJetiExBusTelemetry(void)
} }
if (sensors(SENSOR_BARO)) { if (sensors(SENSOR_BARO)) {
bitArraySet(&exSensorEnabled, EX_ALTITUDE); bitArraySet(&exSensorEnabled, EX_ALTITUDE);
#ifdef USE_VARIO
bitArraySet(&exSensorEnabled, EX_VARIO); bitArraySet(&exSensorEnabled, EX_VARIO);
#endif
} }
if (sensors(SENSOR_ACC)) { if (sensors(SENSOR_ACC)) {
bitArraySet(&exSensorEnabled, EX_ROLL_ANGLE); bitArraySet(&exSensorEnabled, EX_ROLL_ANGLE);
@ -259,9 +261,11 @@ int32_t getSensorValue(uint8_t sensor)
return attitude.values.yaw; return attitude.values.yaw;
break; break;
#ifdef USE_VARIO
case EX_VARIO: case EX_VARIO:
return getEstimatedVario(); return getEstimatedVario();
break; break;
#endif
default: default:
return -1; return -1;