Introduced 'baroStartCalibration()' / 'baroSetGroundLevel()' to… (#9178)

Introduced 'baroStartCalibration()' / 'baroSetGroundLevel()' to make barometer code more self contained.
This commit is contained in:
Michael Keller 2019-11-18 13:25:26 +13:00 committed by GitHub
commit 6d79e8a8fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 15 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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,

View File

@ -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) {}

View File

@ -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 *) {}

View File

@ -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) {}