mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 05:45:31 +03:00
Minimize latency in Acro modes with acc enabled
This commit is contained in:
parent
9277f64d85
commit
f39ca7add6
3 changed files with 86 additions and 51 deletions
|
@ -187,25 +187,28 @@ int16_t imuCalculateHeading(t_fp_vector *vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims)
|
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims, uint8_t imuUpdateSensors)
|
||||||
{
|
{
|
||||||
#if defined(NAZE)
|
|
||||||
uint32_t accProcessTime, gyroProcessTime;
|
|
||||||
#endif
|
|
||||||
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
||||||
uint32_t time = micros();
|
uint32_t time = micros();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(NAZE)
|
||||||
|
uint32_t accProcessTime, gyroProcessTime;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (imuUpdateSensors == ONLY_GYRO || imuUpdateSensors == ACC_AND_GYRO) {
|
||||||
gyroUpdate();
|
gyroUpdate();
|
||||||
#if defined(NAZE)
|
#if defined(NAZE)
|
||||||
while (gyroProcessTime < MAX_GYRO_PROCESSING ) {
|
while (gyroProcessTime < MAX_GYRO_PROCESSING ) {
|
||||||
gyroProcessTime = micros() - time;
|
gyroProcessTime = micros() - time;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef DEBUG_IMU_SPEED
|
#ifdef DEBUG_IMU_SPEED
|
||||||
debug[0] = micros() - time; // gyro read time
|
debug[0] = micros() - time; // gyro read time
|
||||||
#endif
|
#endif
|
||||||
if (sensors(SENSOR_ACC)) {
|
}
|
||||||
|
if (sensors(SENSOR_ACC) && (!imuUpdateSensors == ONLY_GYRO)) {
|
||||||
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
||||||
time = micros();
|
time = micros();
|
||||||
#endif
|
#endif
|
||||||
|
@ -222,31 +225,36 @@ void imuUpdate(rollAndPitchTrims_t *accelerometerTrims)
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_IMU_SPEED
|
#ifdef DEBUG_IMU_SPEED
|
||||||
debug[1] = micros() - time; // acc read time
|
debug[1] = micros() - time; // acc read time
|
||||||
|
if (imuUpdateSensors == ACC_AND_GYRO) {
|
||||||
debug[2] = debug[0] + debug[1]; // gyro + acc read time
|
debug[2] = debug[0] + debug[1]; // gyro + acc read time
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims)
|
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims, uint8_t imuUpdateSensors)
|
||||||
{
|
{
|
||||||
#if defined(NAZE)
|
|
||||||
uint32_t accProcessTime, gyroProcessTime;
|
|
||||||
#endif
|
|
||||||
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
||||||
uint32_t time = micros();
|
uint32_t time = micros();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(NAZE)
|
||||||
|
uint32_t accProcessTime, gyroProcessTime;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (imuUpdateSensors == ONLY_GYRO || imuUpdateSensors == ACC_AND_GYRO) {
|
||||||
gyroUpdate();
|
gyroUpdate();
|
||||||
#if defined(NAZE)
|
#if defined(NAZE)
|
||||||
while (gyroProcessTime < MAX_GYRO_PROCESSING ) {
|
while (gyroProcessTime < MAX_GYRO_PROCESSING ) {
|
||||||
gyroProcessTime = micros() - time;
|
gyroProcessTime = micros() - time;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef DEBUG_IMU_SPEED
|
#ifdef DEBUG_IMU_SPEED
|
||||||
debug[0] = micros() - time; // gyro read time
|
debug[0] = micros() - time; // gyro read time
|
||||||
#endif
|
#endif
|
||||||
if (sensors(SENSOR_ACC)) {
|
}
|
||||||
|
if (sensors(SENSOR_ACC) && (!imuUpdateSensors == ONLY_GYRO)) {
|
||||||
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
#if defined(NAZE) || defined(DEBUG_IMU_SPEED)
|
||||||
time = micros();
|
time = micros();
|
||||||
#endif
|
#endif
|
||||||
|
@ -263,7 +271,9 @@ void imuUpdate(rollAndPitchTrims_t *accelerometerTrims)
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_IMU_SPEED
|
#ifdef DEBUG_IMU_SPEED
|
||||||
debug[1] = micros() - time; // acc read time
|
debug[1] = micros() - time; // acc read time
|
||||||
|
if (imuUpdateSensors == ACC_AND_GYRO) {
|
||||||
debug[2] = debug[0] + debug[1]; // gyro + acc read time
|
debug[2] = debug[0] + debug[1]; // gyro + acc read time
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,12 @@ 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;
|
||||||
|
@ -84,4 +90,4 @@ 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);
|
void imuUpdate(rollAndPitchTrims_t *accelerometerTrims, uint8_t imuUpdateSensors);
|
||||||
|
|
|
@ -727,6 +727,14 @@ void filterRc(void){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool imuUpdateAccDelayed(void) {
|
||||||
|
if (flightModeFlags) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
static uint32_t loopTime;
|
static uint32_t loopTime;
|
||||||
|
@ -777,7 +785,13 @@ void loop(void)
|
||||||
if (gyroSyncCheckUpdate() || (int32_t)(currentTime - (loopTime + GYRO_WATCHDOG_DELAY)) >= 0) {
|
if (gyroSyncCheckUpdate() || (int32_t)(currentTime - (loopTime + GYRO_WATCHDOG_DELAY)) >= 0) {
|
||||||
|
|
||||||
loopTime = currentTime + targetLooptime;
|
loopTime = currentTime + targetLooptime;
|
||||||
imuUpdate(¤tProfile->accelerometerTrims);
|
|
||||||
|
// Determine current flight mode. When no acc needed in pid calculations we should only read gyro to reduce latency
|
||||||
|
if (imuUpdateAccDelayed()) {
|
||||||
|
imuUpdate(¤tProfile->accelerometerTrims, ONLY_GYRO); // When no level modes active read only gyro
|
||||||
|
} 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
|
||||||
currentTime = micros();
|
currentTime = micros();
|
||||||
|
@ -872,6 +886,11 @@ void loop(void)
|
||||||
writeMotors();
|
writeMotors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When no level modes active read acc after motor update
|
||||||
|
if (imuUpdateAccDelayed()) {
|
||||||
|
imuUpdate(¤tProfile->accelerometerTrims, ONLY_ACC);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef BLACKBOX
|
#ifdef BLACKBOX
|
||||||
if (!cliMode && feature(FEATURE_BLACKBOX)) {
|
if (!cliMode && feature(FEATURE_BLACKBOX)) {
|
||||||
handleBlackbox();
|
handleBlackbox();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue