Fixed tilt calulation error #29

This commit is contained in:
Magnus Persson
2022-02-06 21:22:46 +01:00
parent 95216ecc54
commit 914b4125d8
4 changed files with 19 additions and 3 deletions

View File

@ -65,6 +65,7 @@ Config::Config() {
//
void Config::createJson(DynamicJsonDocument& doc) {
doc[PARAM_MDNS] = getMDNS();
doc[PARAM_CONFIG_VER] = getConfigVersion();
doc[PARAM_ID] = getID();
doc[PARAM_OTA] = getOtaURL();
doc[PARAM_SSID] = getWifiSSID();
@ -292,6 +293,13 @@ bool Config::loadFile() {
if (!doc[PARAM_FORMULA_DATA]["g5"].isNull())
_formulaData.g[4] = doc[PARAM_FORMULA_DATA]["g5"].as<double>();
if( doc[PARAM_CONFIG_VER].isNull() ) {
// If this parameter is missing we need to reset the gyrocalibaration due to bug #29
_gyroCalibration.ax = _gyroCalibration.ay = _gyroCalibration.az = 0;
_gyroCalibration.gx = _gyroCalibration.gy = _gyroCalibration.gz = 0;
Log.warning(F("CFG : Old configuration format, clearing gyro calibration." CR));
}
_saveNeeded = false; // Reset save flag
Log.notice(F("CFG : Configuration file " CFG_FILENAME " loaded." CR));
return true;

View File

@ -89,6 +89,7 @@ class HardwareConfig {
class Config {
private:
bool _saveNeeded = false;
int _configVersion = 2;
// Device configuration
String _id = "";
@ -145,6 +146,8 @@ class Config {
_saveNeeded = true;
}
int getConfigVersion() { return _configVersion; }
const bool isGyroTemp() { return _gyroTemp; }
void setGyroTemp(bool b) {
_gyroTemp = b;

View File

@ -196,11 +196,15 @@ float GyroSensor::calculateAngle(RawGyroData &raw) {
az = (static_cast<float>(raw.az)) / 16384;
// Source: https://www.nxp.com/docs/en/application-note/AN3461.pdf
float v = (acos(ay / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
//float vY = (acos(abs(ay) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
float vZ = (acos(abs(az) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
//float vX = (acos(abs(ax) / sqrt(ax * ax + ay * ay + az * az)) * 180.0 / PI);
#if LOG_LEVEL == 6 && !defined(GYRO_DISABLE_LOGGING)
Log.verbose(F("GYRO: angle = %F." CR), v);
//Log.verbose(F("GYRO: angleX= %F." CR), vX);
//Log.verbose(F("GYRO: angleY= %F." CR), vY);
Log.verbose(F("GYRO: angleZ= %F." CR), 90-vZ);
#endif
return v;
return 90-vZ;
}
//

View File

@ -27,6 +27,7 @@ SOFTWARE.
// Common strings used in json formats.
#define PARAM_ID "id"
#define PARAM_MDNS "mdns"
#define PARAM_CONFIG_VER "config-version"
#define PARAM_OTA "ota-url"
#define PARAM_SSID "wifi-ssid"
#define PARAM_PASS "wifi-pass"