forked from iNavFlight/inav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
156 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* This file is part of INAV. | ||
* | ||
* INAV is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* INAV is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with INAV. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "platform.h" | ||
|
||
#include "build/debug.h" | ||
|
||
#include "common/maths.h" | ||
|
||
#include "config/parameter_group.h" | ||
#include "config/parameter_group_ids.h" | ||
|
||
#include "drivers/time.h" | ||
|
||
#include "fc/runtime_config.h" | ||
|
||
#include "io/beeper.h" | ||
|
||
#include "navigation/navigation.h" | ||
#include "navigation/navigation_pos_estimator_private.h" | ||
|
||
#include "sensors/acceleration.h" | ||
#include "sensors/barometer.h" | ||
#include "sensors/sensors.h" | ||
|
||
sensor_compensation_t sensor_comp_data[SENSOR_INDEX_COUNT]; | ||
|
||
float applySensorTempCompensation(int16_t sensorTemp, float sensorMeasurement, sensorIndex_e sensorType) | ||
{ | ||
float setting = 0.0f; | ||
if (sensorType == SENSOR_INDEX_ACC) { | ||
// setting = positionEstimationConfig()->acc_temp_correction; | ||
setting = accelerometerConfig()->acc_temp_correction; | ||
} else if (sensorType == SENSOR_INDEX_BARO) { | ||
setting = barometerConfig()->baro_temp_correction; | ||
// setting = positionEstimationConfig()->baro_temp_correction; | ||
} | ||
|
||
if (!setting) { | ||
return 0.0f; | ||
} | ||
DEBUG_SET(DEBUG_ALWAYS, 1, sensorTemp); | ||
DEBUG_SET(DEBUG_ALWAYS, 0, sensor_comp_data[sensorType].correctionFactor * 100); | ||
DEBUG_SET(DEBUG_ALWAYS, 5, sensorMeasurement); | ||
static timeMs_t startTimeMs = 0; | ||
if (sensor_comp_data[sensorType].calibrationState == SENSOR_TEMP_CAL_COMPLETE) { | ||
startTimeMs = 0; | ||
float tempCal = sensor_comp_data[sensorType].correctionFactor * CENTIDEGREES_TO_DEGREES(sensor_comp_data[sensorType].referenceTemp - sensorTemp); | ||
DEBUG_SET(DEBUG_ALWAYS, 2, tempCal); | ||
return tempCal; | ||
// return correctionFactor * CENTIDEGREES_TO_DEGREES(referenceTemp - baro.baroTemperature); | ||
} | ||
|
||
if (!ARMING_FLAG(WAS_EVER_ARMED)) { | ||
static float referenceMeasurement = 0.0f; | ||
static int16_t lastTemp = 0.0f; | ||
|
||
if (sensor_comp_data[sensorType].calibrationState == SENSOR_TEMP_CAL_INITIALISE) { | ||
sensor_comp_data[sensorType].referenceTemp = lastTemp = sensorTemp; | ||
referenceMeasurement = sensorMeasurement; | ||
sensor_comp_data[sensorType].calibrationState = SENSOR_TEMP_CAL_IN_PROGRESS; | ||
startTimeMs = millis(); | ||
} | ||
|
||
if (setting == 51.0f) { | ||
float referenceDeltaTemp = ABS(sensorTemp - sensor_comp_data[sensorType].referenceTemp); | ||
if (referenceDeltaTemp > 300 && referenceDeltaTemp > ABS(lastTemp - sensor_comp_data[sensorType].referenceTemp)) { // centidegrees | ||
lastTemp = sensorTemp; | ||
sensor_comp_data[sensorType].correctionFactor = 0.8f * sensor_comp_data[sensorType].correctionFactor + 0.2f * (sensorMeasurement - referenceMeasurement) / CENTIDEGREES_TO_DEGREES(lastTemp - sensor_comp_data[sensorType].referenceTemp); | ||
sensor_comp_data[sensorType].correctionFactor = constrainf(sensor_comp_data[sensorType].correctionFactor, -50.0f, 50.0f); | ||
} | ||
} else { | ||
sensor_comp_data[sensorType].correctionFactor = setting; | ||
sensor_comp_data[sensorType].calibrationState = SENSOR_TEMP_CAL_COMPLETE; | ||
} | ||
} | ||
|
||
if (sensor_comp_data[sensorType].calibrationState == SENSOR_TEMP_CAL_IN_PROGRESS && (ARMING_FLAG(WAS_EVER_ARMED) || millis() > startTimeMs + 300000)) { | ||
if (sensorType == SENSOR_INDEX_ACC) { | ||
// positionEstimationConfigMutable()->acc_temp_correction = sensor_comp_data[sensorType].correctionFactor; | ||
accelerometerConfigMutable()->acc_temp_correction = sensor_comp_data[sensorType].correctionFactor; | ||
} else if (sensorType == SENSOR_INDEX_BARO) { | ||
// positionEstimationConfigMutable()->baro_temp_correction = sensor_comp_data[sensorType].correctionFactor; | ||
barometerConfigMutable()->baro_temp_correction = sensor_comp_data[sensorType].correctionFactor; | ||
} | ||
sensor_comp_data[sensorType].calibrationState = SENSOR_TEMP_CAL_COMPLETE; | ||
if (!ARMING_FLAG(WAS_EVER_ARMED)) { | ||
beeper(sensor_comp_data[sensorType].correctionFactor ? BEEPER_ACTION_SUCCESS : BEEPER_ACTION_FAIL); | ||
} | ||
} | ||
|
||
return 0.0f; | ||
} |
Oops, something went wrong.