Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/sensors/gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ bool gyroInit(void)
return true;
}

/* Zero calibration works on raw gyro readings, so the movement threshold has to be
* expressed in that sensor's LSB. Each gyro is asked for its own scale: a dual-IMU
* board may pair two unrelated parts, and the primary's sensitivity would be the
* wrong reference for the secondary. */
static float gyroMovementThreshold(uint8_t index)
{
return CALIBRATING_GYRO_MORON_THRESHOLD_DPS / gyroDev[index].scale;
}

void gyroStartCalibration(void)
{
if (!gyro.initialized) {
Expand All @@ -377,7 +386,7 @@ void gyroStartCalibration(void)
#endif

gyroCalibrationComplete = false;
zeroCalibrationStartV(&gyroCalibration[0], CALIBRATING_GYRO_TIME_MS, CALIBRATING_GYRO_MORON_THRESHOLD, false);
zeroCalibrationStartV(&gyroCalibration[0], CALIBRATING_GYRO_TIME_MS, gyroMovementThreshold(0), false);
}

bool gyroIsCalibrationComplete(void)
Expand Down
5 changes: 4 additions & 1 deletion src/main/sensors/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ typedef union flightDynamicsTrims_u {
#define CALIBRATING_PITOT_TIME_MS 4000
#define CALIBRATING_GYRO_TIME_MS 2000
#define CALIBRATING_ACC_TIME_MS 500
#define CALIBRATING_GYRO_MORON_THRESHOLD 32
// Gyro zero calibration movement threshold, in dps. Expressed as a physical rotation rate so
// that it does not depend on the gyro sensitivity. Equals the legacy threshold of 32 LSB at
// the default scale of 16.4 LSB/dps
#define CALIBRATING_GYRO_MORON_THRESHOLD_DPS (32.0f / 16.4f)

// These bits have to be aligned with sensorIndex_e
typedef enum {
Expand Down
Loading