Introduced 'baroStartCalibration()' / 'baroSetGroundLevel()' to… (#9178)
Introduced 'baroStartCalibration()' / 'baroSetGroundLevel()' to make barometer code more self contained.
This commit is contained in:
commit
6d79e8a8fc
|
@ -879,7 +879,7 @@ void init(void)
|
|||
#endif
|
||||
gyroStartCalibration(false);
|
||||
#ifdef USE_BARO
|
||||
baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
|
||||
baroStartCalibration();
|
||||
#endif
|
||||
|
||||
#if defined(USE_VTX_COMMON) || defined(USE_VTX_CONTROL)
|
||||
|
|
|
@ -241,8 +241,9 @@ void processRcStickPositions()
|
|||
#endif
|
||||
|
||||
#ifdef USE_BARO
|
||||
if (sensors(SENSOR_BARO))
|
||||
baroSetCalibrationCycles(10); // calibrate baro to new ground level (10 * 25 ms = ~250 ms non blocking)
|
||||
if (sensors(SENSOR_BARO)) {
|
||||
baroSetGroundLevel();
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
|
|
@ -48,12 +48,9 @@
|
|||
|
||||
#include "fc/runtime_config.h"
|
||||
|
||||
#include "sensors/barometer.h"
|
||||
#include "sensors/sensors.h"
|
||||
|
||||
#ifdef USE_HARDWARE_REVISION_DETECTION
|
||||
#include "hardware_revision.h"
|
||||
#endif
|
||||
#include "barometer.h"
|
||||
|
||||
baro_t baro; // barometer access functions
|
||||
|
||||
|
@ -139,6 +136,11 @@ static int32_t baroGroundAltitude = 0;
|
|||
static int32_t baroGroundPressure = 8*101325;
|
||||
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)
|
||||
{
|
||||
#ifdef USE_SPI
|
||||
|
@ -278,12 +280,20 @@ bool isBaroCalibrationComplete(void)
|
|||
return calibratingB == 0;
|
||||
}
|
||||
|
||||
void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired)
|
||||
static void baroSetCalibrationCycles(uint16_t 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
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ extern baro_t baro;
|
|||
void baroPreInit(void);
|
||||
bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse);
|
||||
bool isBaroCalibrationComplete(void);
|
||||
void baroSetCalibrationCycles(uint16_t calibrationCyclesRequired);
|
||||
void baroStartCalibration(void);
|
||||
void baroSetGroundLevel(void);
|
||||
uint32_t baroUpdate(void);
|
||||
bool isBaroReady(void);
|
||||
int32_t baroCalculateAltitude(void);
|
||||
|
|
|
@ -44,8 +44,6 @@ typedef union flightDynamicsTrims_u {
|
|||
flightDynamicsTrims_def_t values;
|
||||
} flightDynamicsTrims_t;
|
||||
|
||||
#define CALIBRATING_BARO_CYCLES 200 // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles
|
||||
|
||||
typedef enum {
|
||||
SENSOR_GYRO = 1 << 0, // always present
|
||||
SENSOR_ACC = 1 << 1,
|
||||
|
|
|
@ -1071,7 +1071,7 @@ extern "C" {
|
|||
void transponderUpdate(timeUs_t) {}
|
||||
void GPS_reset_home_position(void) {}
|
||||
void accStartCalibration(void) {}
|
||||
void baroSetCalibrationCycles(uint16_t) {}
|
||||
void baroSetGroundLevel(void) {}
|
||||
void changePidProfile(uint8_t) {}
|
||||
void changeControlRateProfile(uint8_t) {}
|
||||
void dashboardEnablePageCycling(void) {}
|
||||
|
|
|
@ -631,7 +631,7 @@ uint8_t getCurrentControlRateProfileIndex(void) {
|
|||
return 0;
|
||||
}
|
||||
void GPS_reset_home_position(void) {}
|
||||
void baroSetCalibrationCycles(uint16_t) {}
|
||||
void baroSetGroundLevel(void) {}
|
||||
|
||||
void blackboxLogEvent(FlightLogEvent, flightLogEventData_t *) {}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ extern "C" {
|
|||
void transponderUpdate(timeUs_t) {}
|
||||
void GPS_reset_home_position(void) {}
|
||||
void accStartCalibration(void) {}
|
||||
void baroSetCalibrationCycles(uint16_t) {}
|
||||
void baroSetGroundLevel(void) {}
|
||||
void changePidProfile(uint8_t) {}
|
||||
void changeControlRateProfile(uint8_t) {}
|
||||
void dashboardEnablePageCycling(void) {}
|
||||
|
|
Loading…
Reference in New Issue