calibration params: avoid using NaN as default

- NaN is not supported by JSON, and leads to parsing failure in QGC.
 - fixes https://github.com/PX4/PX4-Autopilot/issues/18095
This commit is contained in:
Beat Küng 2021-08-19 17:29:26 +02:00 committed by GitHub
parent 507cce78d5
commit c4b91c8558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 72 additions and 18 deletions

View File

@ -210,7 +210,14 @@ void Accelerometer::ParametersUpdate()
}
// CAL_ACCx_TEMP
set_temperature(GetCalibrationParamFloat(SensorString(), "TEMP", _calibration_index));
float cal_temp = GetCalibrationParamFloat(SensorString(), "TEMP", _calibration_index);
if (cal_temp > TEMPERATURE_INVALID) {
set_temperature(cal_temp);
} else {
set_temperature(NAN);
}
// CAL_ACCx_OFF{X,Y,Z}
set_offset(GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index));
@ -263,7 +270,12 @@ bool Accelerometer::ParametersSave()
success &= SetCalibrationParam(SensorString(), "ROT", _calibration_index, -1);
}
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, _temperature);
if (PX4_ISFINITE(_temperature)) {
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, _temperature);
} else {
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, TEMPERATURE_INVALID);
}
return success;
}

View File

@ -92,6 +92,8 @@ public:
void SensorCorrectionsUpdate(bool force = false);
private:
static constexpr float TEMPERATURE_INVALID = -1000.f;
uORB::Subscription _sensor_correction_sub{ORB_ID(sensor_correction)};
Rotation _rotation_enum{ROTATION_NONE};

View File

@ -195,7 +195,14 @@ void Gyroscope::ParametersUpdate()
}
// CAL_GYROx_TEMP
set_temperature(GetCalibrationParamFloat(SensorString(), "TEMP", _calibration_index));
float cal_temp = GetCalibrationParamFloat(SensorString(), "TEMP", _calibration_index);
if (cal_temp > TEMPERATURE_INVALID) {
set_temperature(cal_temp);
} else {
set_temperature(NAN);
}
// CAL_GYROx_OFF{X,Y,Z}
set_offset(GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index));
@ -243,7 +250,12 @@ bool Gyroscope::ParametersSave()
success &= SetCalibrationParam(SensorString(), "ROT", _calibration_index, -1);
}
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, _temperature);
if (PX4_ISFINITE(_temperature)) {
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, _temperature);
} else {
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, TEMPERATURE_INVALID);
}
return success;
}

View File

@ -96,6 +96,8 @@ public:
void SensorCorrectionsUpdate(bool force = false);
private:
static constexpr float TEMPERATURE_INVALID = -1000.f;
uORB::Subscription _sensor_correction_sub{ORB_ID(sensor_correction)};
Rotation _rotation_enum{ROTATION_NONE};

View File

@ -195,7 +195,14 @@ void Magnetometer::ParametersUpdate()
}
// CAL_MAGx_TEMP
set_temperature(GetCalibrationParamFloat(SensorString(), "TEMP", _calibration_index));
float cal_temp = GetCalibrationParamFloat(SensorString(), "TEMP", _calibration_index);
if (cal_temp > TEMPERATURE_INVALID) {
set_temperature(cal_temp);
} else {
set_temperature(NAN);
}
// CAL_MAGx_OFF{X,Y,Z}
set_offset(GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index));
@ -263,7 +270,12 @@ bool Magnetometer::ParametersSave()
success &= SetCalibrationParam(SensorString(), "ROT", _calibration_index, -1);
}
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, _temperature);
if (PX4_ISFINITE(_temperature)) {
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, _temperature);
} else {
success &= SetCalibrationParam(SensorString(), "TEMP", _calibration_index, TEMPERATURE_INVALID);
}
return success;
}

View File

@ -100,6 +100,8 @@ public:
void UpdatePower(float power) { _power = power; }
private:
static constexpr float TEMPERATURE_INVALID = -1000.f;
Rotation _rotation_enum{ROTATION_NONE};
matrix::Dcmf _rotation;

View File

@ -172,8 +172,9 @@ PARAM_DEFINE_FLOAT(CAL_ACC0_ZSCALE, 1.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_ACC0_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_ACC0_TEMP, -1000.f);

View File

@ -172,8 +172,9 @@ PARAM_DEFINE_FLOAT(CAL_ACC1_ZSCALE, 1.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_ACC1_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_ACC1_TEMP, -1000.f);

View File

@ -172,8 +172,9 @@ PARAM_DEFINE_FLOAT(CAL_ACC2_ZSCALE, 1.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_ACC2_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_ACC2_TEMP, -1000.f);

View File

@ -172,8 +172,9 @@ PARAM_DEFINE_FLOAT(CAL_ACC3_ZSCALE, 1.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_ACC3_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_ACC3_TEMP, -1000.f);

View File

@ -145,8 +145,9 @@ PARAM_DEFINE_FLOAT(CAL_GYRO0_ZOFF, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_GYRO0_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_GYRO0_TEMP, -1000.f);

View File

@ -145,8 +145,9 @@ PARAM_DEFINE_FLOAT(CAL_GYRO1_ZOFF, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_GYRO1_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_GYRO1_TEMP, -1000.f);

View File

@ -145,8 +145,9 @@ PARAM_DEFINE_FLOAT(CAL_GYRO2_ZOFF, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_GYRO2_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_GYRO2_TEMP, -1000.f);

View File

@ -145,8 +145,9 @@ PARAM_DEFINE_FLOAT(CAL_GYRO3_ZOFF, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_GYRO3_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_GYRO3_TEMP, -1000.f);

View File

@ -241,8 +241,9 @@ PARAM_DEFINE_FLOAT(CAL_MAG0_ZCOMP, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_MAG0_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_MAG0_TEMP, -1000.f);

View File

@ -241,8 +241,9 @@ PARAM_DEFINE_FLOAT(CAL_MAG1_ZCOMP, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_MAG1_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_MAG1_TEMP, -1000.f);

View File

@ -241,8 +241,9 @@ PARAM_DEFINE_FLOAT(CAL_MAG2_ZCOMP, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_MAG2_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_MAG2_TEMP, -1000.f);

View File

@ -241,8 +241,9 @@ PARAM_DEFINE_FLOAT(CAL_MAG3_ZCOMP, 0.0f);
*
* Temperature during last calibration.
*
* @unit celcius
* @category system
* @group Sensor Calibration
* @volatile
*/
PARAM_DEFINE_FLOAT(CAL_MAG3_TEMP, NAN);
PARAM_DEFINE_FLOAT(CAL_MAG3_TEMP, -1000.f);