mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 22:05:17 +03:00
Split up imuUpdate for gyro and acc
This commit is contained in:
parent
81299e34de
commit
b3f0bd1402
3 changed files with 14 additions and 17 deletions
|
@ -425,12 +425,14 @@ static void imuCalculateEstimatedAttitude(void)
|
||||||
imuCalculateAcceleration(deltaT); // rotate acc vector into earth frame
|
imuCalculateAcceleration(deltaT); // rotate acc vector into earth frame
|
||||||
}
|
}
|
||||||
|
|
||||||
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims, uint8_t imuUpdateSensors)
|
void imuUpdateGyro(void)
|
||||||
{
|
{
|
||||||
if (imuUpdateSensors == ONLY_GYRO || imuUpdateSensors == ACC_AND_GYRO) {
|
|
||||||
gyroUpdate();
|
gyroUpdate();
|
||||||
}
|
}
|
||||||
if (sensors(SENSOR_ACC) && (!imuUpdateSensors == ONLY_GYRO)) {
|
|
||||||
|
void imuUpdateAcc(rollAndPitchTrims_t *accelerometerTrims)
|
||||||
|
{
|
||||||
|
if (sensors(SENSOR_ACC)) {
|
||||||
updateAccelerationReadings(accelerometerTrims);
|
updateAccelerationReadings(accelerometerTrims);
|
||||||
imuCalculateEstimatedAttitude();
|
imuCalculateEstimatedAttitude();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -66,12 +66,6 @@ typedef enum {
|
||||||
ACCPROC_COPY
|
ACCPROC_COPY
|
||||||
} accProcessorState_e;
|
} accProcessorState_e;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ONLY_GYRO = 0,
|
|
||||||
ONLY_ACC,
|
|
||||||
ACC_AND_GYRO
|
|
||||||
} imuUpdateMode_e;
|
|
||||||
|
|
||||||
typedef struct accProcessor_s {
|
typedef struct accProcessor_s {
|
||||||
accProcessorState_e state;
|
accProcessorState_e state;
|
||||||
} accProcessor_t;
|
} accProcessor_t;
|
||||||
|
@ -92,4 +86,5 @@ float calculateAccZLowPassFilterRCTimeConstant(float accz_lpf_cutoff);
|
||||||
int16_t imuCalculateHeading(t_fp_vector *vec);
|
int16_t imuCalculateHeading(t_fp_vector *vec);
|
||||||
|
|
||||||
void imuResetAccelerationSum(void);
|
void imuResetAccelerationSum(void);
|
||||||
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims, uint8_t imuUpdateSensors);
|
void imuUpdateGyro(void);
|
||||||
|
void imuUpdateAcc(rollAndPitchTrims_t *accelerometerTrims);
|
||||||
|
|
|
@ -774,11 +774,11 @@ void loop(void)
|
||||||
|
|
||||||
haveProcessedRxOnceBeforeLoop = false;
|
haveProcessedRxOnceBeforeLoop = false;
|
||||||
|
|
||||||
|
imuUpdateGyro();
|
||||||
|
|
||||||
// Determine current flight mode. When no acc needed in pid calculations we should only read gyro to reduce latency
|
// Determine current flight mode. When no acc needed in pid calculations we should only read gyro to reduce latency
|
||||||
if (!flightModeFlags) {
|
if (flightModeFlags) {
|
||||||
imuUpdate(¤tProfile->accelerometerTrims, ONLY_GYRO); // When no level modes active read only gyro
|
imuUpdateAcc(¤tProfile->accelerometerTrims); // When level modes active read gyro and acc
|
||||||
} else {
|
|
||||||
imuUpdate(¤tProfile->accelerometerTrims, ACC_AND_GYRO); // When level modes active read gyro and acc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Measure loop rate just after reading the sensors
|
// Measure loop rate just after reading the sensors
|
||||||
|
@ -859,7 +859,7 @@ void loop(void)
|
||||||
|
|
||||||
// When no level modes active read acc after motor update
|
// When no level modes active read acc after motor update
|
||||||
if (!flightModeFlags) {
|
if (!flightModeFlags) {
|
||||||
imuUpdate(¤tProfile->accelerometerTrims, ONLY_ACC);
|
imuUpdateAcc(¤tProfile->accelerometerTrims);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BLACKBOX
|
#ifdef BLACKBOX
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue