mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 11:59:58 +03:00
Introduced 'baroStartCalibration()' / 'baroSetGroundLevel()' to make barometer code more self contained.
This commit is contained in:
parent
dd0b45dc87
commit
ef556c0f59
8 changed files with 25 additions and 15 deletions
|
@ -879,7 +879,7 @@ void init(void)
|
||||||
#endif
|
#endif
|
||||||
gyroStartCalibration(false);
|
gyroStartCalibration(false);
|
||||||
#ifdef USE_BARO
|
#ifdef USE_BARO
|
||||||
baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
|
baroStartCalibration();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_VTX_COMMON) || defined(USE_VTX_CONTROL)
|
#if defined(USE_VTX_COMMON) || defined(USE_VTX_CONTROL)
|
||||||
|
|
|
@ -241,8 +241,9 @@ void processRcStickPositions()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_BARO
|
#ifdef USE_BARO
|
||||||
if (sensors(SENSOR_BARO))
|
if (sensors(SENSOR_BARO)) {
|
||||||
baroSetCalibrationCycles(10); // calibrate baro to new ground level (10 * 25 ms = ~250 ms non blocking)
|
baroSetGroundLevel();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -48,12 +48,9 @@
|
||||||
|
|
||||||
#include "fc/runtime_config.h"
|
#include "fc/runtime_config.h"
|
||||||
|
|
||||||
#include "sensors/barometer.h"
|
|
||||||
#include "sensors/sensors.h"
|
#include "sensors/sensors.h"
|
||||||
|
|
||||||
#ifdef USE_HARDWARE_REVISION_DETECTION
|
#include "barometer.h"
|
||||||
#include "hardware_revision.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
baro_t baro; // barometer access functions
|
baro_t baro; // barometer access functions
|
||||||
|
|
||||||
|
@ -139,6 +136,11 @@ static int32_t baroGroundAltitude = 0;
|
||||||
static int32_t baroGroundPressure = 8*101325;
|
static int32_t baroGroundPressure = 8*101325;
|
||||||
static uint32_t baroPressureSum = 0;
|
static uint32_t baroPressureSum = 0;
|
||||||
|
|
||||||
|
#define CALIBRATING_BARO_CYCLES 200 // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles
|
||||||
|
#define SET_GROUND_LEVEL_BARO_CYCLES 10 // calibrate baro to new ground level (10 * 25 ms = ~250 ms non blocking)
|
||||||
|
|
||||||
|
static bool baroReady = false;
|
||||||
|
|
||||||
void baroPreInit(void)
|
void baroPreInit(void)
|
||||||
{
|
{
|
||||||
#ifdef USE_SPI
|
#ifdef USE_SPI
|
||||||
|
@ -278,12 +280,20 @@ bool isBaroCalibrationComplete(void)
|
||||||
return calibratingB == 0;
|
return calibratingB == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired)
|
static void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired)
|
||||||
{
|
{
|
||||||
calibratingB = calibrationCyclesRequired;
|
calibratingB = calibrationCyclesRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool baroReady = false;
|
void baroStartCalibration(void)
|
||||||
|
{
|
||||||
|
baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
|
||||||
|
}
|
||||||
|
|
||||||
|
void baroSetGroundLevel(void)
|
||||||
|
{
|
||||||
|
baroSetCalibrationCycles(SET_GROUND_LEVEL_BARO_CYCLES);
|
||||||
|
}
|
||||||
|
|
||||||
#define PRESSURE_SAMPLES_MEDIAN 3
|
#define PRESSURE_SAMPLES_MEDIAN 3
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,8 @@ extern baro_t baro;
|
||||||
void baroPreInit(void);
|
void baroPreInit(void);
|
||||||
bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse);
|
bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse);
|
||||||
bool isBaroCalibrationComplete(void);
|
bool isBaroCalibrationComplete(void);
|
||||||
void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired);
|
void baroStartCalibration(void);
|
||||||
|
void baroSetGroundLevel(void);
|
||||||
uint32_t baroUpdate(void);
|
uint32_t baroUpdate(void);
|
||||||
bool isBaroReady(void);
|
bool isBaroReady(void);
|
||||||
int32_t baroCalculateAltitude(void);
|
int32_t baroCalculateAltitude(void);
|
||||||
|
|
|
@ -44,8 +44,6 @@ typedef union flightDynamicsTrims_u {
|
||||||
flightDynamicsTrims_def_t values;
|
flightDynamicsTrims_def_t values;
|
||||||
} flightDynamicsTrims_t;
|
} flightDynamicsTrims_t;
|
||||||
|
|
||||||
#define CALIBRATING_BARO_CYCLES 200 // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SENSOR_GYRO = 1 << 0, // always present
|
SENSOR_GYRO = 1 << 0, // always present
|
||||||
SENSOR_ACC = 1 << 1,
|
SENSOR_ACC = 1 << 1,
|
||||||
|
|
|
@ -1071,7 +1071,7 @@ extern "C" {
|
||||||
void transponderUpdate(timeUs_t) {}
|
void transponderUpdate(timeUs_t) {}
|
||||||
void GPS_reset_home_position(void) {}
|
void GPS_reset_home_position(void) {}
|
||||||
void accStartCalibration(void) {}
|
void accStartCalibration(void) {}
|
||||||
void baroSetCalibrationCycles(uint16_t) {}
|
void baroSetGroundLevel(void) {}
|
||||||
void changePidProfile(uint8_t) {}
|
void changePidProfile(uint8_t) {}
|
||||||
void changeControlRateProfile(uint8_t) {}
|
void changeControlRateProfile(uint8_t) {}
|
||||||
void dashboardEnablePageCycling(void) {}
|
void dashboardEnablePageCycling(void) {}
|
||||||
|
|
|
@ -631,7 +631,7 @@ uint8_t getCurrentControlRateProfileIndex(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void GPS_reset_home_position(void) {}
|
void GPS_reset_home_position(void) {}
|
||||||
void baroSetCalibrationCycles(uint16_t) {}
|
void baroSetGroundLevel(void) {}
|
||||||
|
|
||||||
void blackboxLogEvent(FlightLogEvent, flightLogEventData_t *) {}
|
void blackboxLogEvent(FlightLogEvent, flightLogEventData_t *) {}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ extern "C" {
|
||||||
void transponderUpdate(timeUs_t) {}
|
void transponderUpdate(timeUs_t) {}
|
||||||
void GPS_reset_home_position(void) {}
|
void GPS_reset_home_position(void) {}
|
||||||
void accStartCalibration(void) {}
|
void accStartCalibration(void) {}
|
||||||
void baroSetCalibrationCycles(uint16_t) {}
|
void baroSetGroundLevel(void) {}
|
||||||
void changePidProfile(uint8_t) {}
|
void changePidProfile(uint8_t) {}
|
||||||
void changeControlRateProfile(uint8_t) {}
|
void changeControlRateProfile(uint8_t) {}
|
||||||
void dashboardEnablePageCycling(void) {}
|
void dashboardEnablePageCycling(void) {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue