1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-24 16:55:29 +03:00

add ins gravity

This commit is contained in:
JuliooCesarMDM 2021-12-04 20:16:33 -03:00
parent bee6ac200a
commit 19894a5a80
8 changed files with 80 additions and 28 deletions

View file

@ -2142,6 +2142,16 @@ If defined to 'OFF', it will ignore the gyroscope calibration done at each start
---
### ins_gravity_cmss
Calculated 1G of Acc axis Z to use in INS
| Default | Min | Max |
| --- | --- | --- |
| 0.0 | 0 | 1000 |
---
### iterm_windup
Used to prevent Iterm accumulation on during maneuvers. Iterm will be dampened when motors are reaching it's limit (when requested motor correction range is above percentage specified by this parameter)

View file

@ -465,11 +465,18 @@ void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex)
beeperConfirmationBeeps(profileIndex + 1);
}
void setCalibrationGyroAndWriteEEPROM(int16_t getGyroZero[XYZ_AXIS_COUNT]) {
void setGyroCalibrationAndWriteEEPROM(int16_t getGyroZero[XYZ_AXIS_COUNT]) {
gyroConfigMutable()->gyro_zero_cal[X] = getGyroZero[X];
gyroConfigMutable()->gyro_zero_cal[Y] = getGyroZero[Y];
gyroConfigMutable()->gyro_zero_cal[Z] = getGyroZero[Z];
// save gyro calibration
// save the calibration
writeEEPROM();
readEEPROM();
}
void setGravityCalibrationAndWriteEEPROM(float getGravity) {
gyroConfigMutable()->gravity_cmss_cal = getGravity;
// save the calibration
writeEEPROM();
readEEPROM();
}

View file

@ -132,7 +132,8 @@ uint8_t getConfigBatteryProfile(void);
bool setConfigBatteryProfile(uint8_t profileIndex);
void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex);
void setCalibrationGyroAndWriteEEPROM(int16_t getGyroZero[XYZ_AXIS_COUNT]);
void setGyroCalibrationAndWriteEEPROM(int16_t getGyroZero[XYZ_AXIS_COUNT]);
void setGravityCalibrationAndWriteEEPROM(float getGravity);
bool canSoftwareSerialBeUsed(void);
void applyAndSaveBoardAlignmentDelta(int16_t roll, int16_t pitch);

View file

@ -332,6 +332,12 @@ groups:
field: gyro_zero_cal[Z]
min: INT16_MIN
max: INT16_MAX
- name: ins_gravity_cmss
description: "Calculated 1G of Acc axis Z to use in INS"
default_value: 0.0
field: gravity_cmss_cal
min: 0
max: 1000
- name: PG_ADC_CHANNEL_CONFIG
type: adcChannelConfig_t

View file

@ -63,6 +63,7 @@
#define MR_RTH_CLIMB_OVERSHOOT_CM 100 // target this amount of cm *above* the target altitude to ensure it is actually reached (Vz > 0 at target alt)
#define MR_RTH_CLIMB_MARGIN_MIN_CM 100 // start cruising home this amount of cm *before* reaching the cruise altitude (while continuing the ascend)
#define MR_RTH_CLIMB_MARGIN_PERCENT 15 // on high RTH altitudes use even bigger margin - percent of the altitude set
// Planes:
#define FW_RTH_CLIMB_OVERSHOOT_CM 100
#define FW_RTH_CLIMB_MARGIN_MIN_CM 100

View file

@ -51,6 +51,7 @@
#include "sensors/acceleration.h"
#include "sensors/barometer.h"
#include "sensors/compass.h"
#include "sensors/gyro.h"
#include "sensors/pitotmeter.h"
#include "sensors/opflow.h"
@ -353,11 +354,19 @@ void updatePositionEstimator_PitotTopic(timeUs_t currentTimeUs)
*/
static void restartGravityCalibration(void)
{
if (!gyroConfig()->init_gyro_cal_enabled) {
return;
}
zeroCalibrationStartS(&posEstimator.imu.gravityCalibration, CALIBRATING_GRAVITY_TIME_MS, positionEstimationConfig()->gravity_calibration_tolerance, false);
}
static bool gravityCalibrationComplete(void)
{
if (!gyroConfig()->init_gyro_cal_enabled) {
return true;
}
return zeroCalibrationIsCompleteS(&posEstimator.imu.gravityCalibration);
}
@ -393,9 +402,9 @@ static void updateIMUTopic(timeUs_t currentTimeUs)
posEstimator.imu.lastUpdateTime = currentTimeUs;
if (!isImuReady()) {
posEstimator.imu.accelNEU.x = 0;
posEstimator.imu.accelNEU.y = 0;
posEstimator.imu.accelNEU.z = 0;
posEstimator.imu.accelNEU.x = 0.0f;
posEstimator.imu.accelNEU.y = 0.0f;
posEstimator.imu.accelNEU.z = 0.0f;
restartGravityCalibration();
}
@ -424,13 +433,19 @@ static void updateIMUTopic(timeUs_t currentTimeUs)
posEstimator.imu.accelNEU.z = accelBF.z;
/* When unarmed, assume that accelerometer should measure 1G. Use that to correct accelerometer gain */
if (!ARMING_FLAG(ARMED) && !gravityCalibrationComplete()) {
zeroCalibrationAddValueS(&posEstimator.imu.gravityCalibration, posEstimator.imu.accelNEU.z);
if (gyroConfig()->init_gyro_cal_enabled) {
if (!ARMING_FLAG(ARMED) && !gravityCalibrationComplete()) {
zeroCalibrationAddValueS(&posEstimator.imu.gravityCalibration, posEstimator.imu.accelNEU.z);
if (gravityCalibrationComplete()) {
zeroCalibrationGetZeroS(&posEstimator.imu.gravityCalibration, &posEstimator.imu.calibratedGravityCMSS);
LOG_D(POS_ESTIMATOR, "Gravity calibration complete (%d)", (int)lrintf(posEstimator.imu.calibratedGravityCMSS));
if (gravityCalibrationComplete()) {
zeroCalibrationGetZeroS(&posEstimator.imu.gravityCalibration, &posEstimator.imu.calibratedGravityCMSS);
setGravityCalibrationAndWriteEEPROM(posEstimator.imu.calibratedGravityCMSS);
LOG_D(POS_ESTIMATOR, "Gravity calibration complete (%d)", (int)lrintf(posEstimator.imu.calibratedGravityCMSS));
}
}
} else {
posEstimator.imu.gravityCalibration.params.state = ZERO_CALIBRATION_DONE;
posEstimator.imu.calibratedGravityCMSS = gyroConfig()->gravity_cmss_cal;
}
/* If calibration is incomplete - report zero acceleration */
@ -438,9 +453,9 @@ static void updateIMUTopic(timeUs_t currentTimeUs)
posEstimator.imu.accelNEU.z -= posEstimator.imu.calibratedGravityCMSS;
}
else {
posEstimator.imu.accelNEU.x = 0;
posEstimator.imu.accelNEU.y = 0;
posEstimator.imu.accelNEU.z = 0;
posEstimator.imu.accelNEU.x = 0.0f;
posEstimator.imu.accelNEU.y = 0.0f;
posEstimator.imu.accelNEU.z = 0.0f;
}
/* Update blackbox values */

View file

@ -99,7 +99,7 @@ EXTENDED_FASTRAM dynamicGyroNotchState_t dynamicGyroNotchState;
#endif
PG_REGISTER_WITH_RESET_TEMPLATE(gyroConfig_t, gyroConfig, PG_GYRO_CONFIG, 2);
PG_REGISTER_WITH_RESET_TEMPLATE(gyroConfig_t, gyroConfig, PG_GYRO_CONFIG, 3);
PG_RESET_TEMPLATE(gyroConfig_t, gyroConfig,
.gyro_lpf = SETTING_GYRO_HARDWARE_LPF_DEFAULT,
@ -128,6 +128,7 @@ PG_RESET_TEMPLATE(gyroConfig_t, gyroConfig,
#endif
.init_gyro_cal_enabled = SETTING_INIT_GYRO_CAL_DEFAULT,
.gyro_zero_cal = {SETTING_GYRO_ZERO_X_DEFAULT, SETTING_GYRO_ZERO_Y_DEFAULT, SETTING_GYRO_ZERO_Z_DEFAULT},
.gravity_cmss_cal = SETTING_INS_GRAVITY_CMSS_DEFAULT,
);
STATIC_UNIT_TESTED gyroSensor_e gyroDetect(gyroDev_t *dev, gyroSensor_e gyroHardware)
@ -340,6 +341,10 @@ void gyroStartCalibration(void)
if (!gyro.initialized) {
return;
}
if (!gyroConfig()->init_gyro_cal_enabled) {
return;
}
zeroCalibrationStartV(&gyroCalibration[0], CALIBRATING_GYRO_TIME_MS, gyroConfig()->gyroMovementCalibrationThreshold, false);
}
@ -349,23 +354,16 @@ bool gyroIsCalibrationComplete(void)
if (!gyro.initialized) {
return true;
}
if (!gyroConfig()->init_gyro_cal_enabled) {
return true;
}
return zeroCalibrationIsCompleteV(&gyroCalibration[0]) && zeroCalibrationIsSuccessfulV(&gyroCalibration[0]);
}
STATIC_UNIT_TESTED void performGyroCalibration(gyroDev_t *dev, zeroCalibrationVector_t *gyroCalibration)
{
#ifndef USE_IMU_FAKE // fixes Test Unit compilation error
if (!gyroConfig()->init_gyro_cal_enabled) {
gyroCalibration[0].params.state = ZERO_CALIBRATION_DONE; // calibration ended
// pass the calibration values
dev->gyroZero[X] = gyroConfig()->gyro_zero_cal[X];
dev->gyroZero[Y] = gyroConfig()->gyro_zero_cal[Y];
dev->gyroZero[Z] = gyroConfig()->gyro_zero_cal[Z];
return; // skip gyro calibration and use values read from storage
}
#endif
fpVector3_t v;
// Consume gyro reading
@ -383,7 +381,7 @@ STATIC_UNIT_TESTED void performGyroCalibration(gyroDev_t *dev, zeroCalibrationVe
dev->gyroZero[Z] = v.v[Z];
#ifndef USE_IMU_FAKE // fixes Test Unit compilation error
setCalibrationGyroAndWriteEEPROM(dev->gyroZero);
setGyroCalibrationAndWriteEEPROM(dev->gyroZero);
#endif
LOG_D(GYRO, "Gyro calibration complete (%d, %d, %d)", dev->gyroZero[X], dev->gyroZero[Y], dev->gyroZero[Z]);
@ -407,8 +405,21 @@ void gyroGetMeasuredRotationRate(fpVector3_t *measuredRotationRate)
static bool FAST_CODE NOINLINE gyroUpdateAndCalibrate(gyroDev_t * gyroDev, zeroCalibrationVector_t * gyroCal, float * gyroADCf)
{
// range: +/- 8192; +/- 2000 deg/sec
if (gyroDev->readFn(gyroDev)) {
#ifndef USE_IMU_FAKE // fixes Test Unit compilation error
if (!gyroConfig()->init_gyro_cal_enabled) {
// marks that the gyro calibration has ended
gyroCalibration[0].params.state = ZERO_CALIBRATION_DONE;
// pass the calibration values
gyroDev->gyroZero[X] = gyroConfig()->gyro_zero_cal[X];
gyroDev->gyroZero[Y] = gyroConfig()->gyro_zero_cal[Y];
gyroDev->gyroZero[Z] = gyroConfig()->gyro_zero_cal[Z];
}
#endif
if (zeroCalibrationIsCompleteV(gyroCal)) {
int32_t gyroADCtmp[XYZ_AXIS_COUNT];
@ -508,7 +519,7 @@ void FAST_CODE NOINLINE gyroUpdate()
// At this point gyro.gyroADCf contains unfiltered gyro value [deg/s]
float gyroADCf = gyro.gyroADCf[axis];
DEBUG_SET(DEBUG_GYRO, axis, lrintf(gyroADCf));
//DEBUG_SET(DEBUG_GYRO, axis, lrintf(gyroADCf));
/*
* First gyro LPF is the only filter applied with the full gyro sampling speed

View file

@ -75,6 +75,7 @@ typedef struct gyroConfig_s {
#endif
bool init_gyro_cal_enabled;
int16_t gyro_zero_cal[XYZ_AXIS_COUNT];
float gravity_cmss_cal;
} gyroConfig_t;
PG_DECLARE(gyroConfig_t, gyroConfig);