mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 08:23:34 +08:00
lib/sensor_calibration: add simple offset and scale sanity checks
This commit is contained in:
@@ -126,10 +126,11 @@ void Accelerometer::SensorCorrectionsUpdate(bool force)
|
|||||||
bool Accelerometer::set_offset(const Vector3f &offset)
|
bool Accelerometer::set_offset(const Vector3f &offset)
|
||||||
{
|
{
|
||||||
if (Vector3f(_offset - offset).longerThan(0.01f)) {
|
if (Vector3f(_offset - offset).longerThan(0.01f)) {
|
||||||
_offset = offset;
|
if (PX4_ISFINITE(offset(0)) && PX4_ISFINITE(offset(1)) && PX4_ISFINITE(offset(2))) {
|
||||||
|
_offset = offset;
|
||||||
_calibration_count++;
|
_calibration_count++;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -138,10 +139,13 @@ bool Accelerometer::set_offset(const Vector3f &offset)
|
|||||||
bool Accelerometer::set_scale(const Vector3f &scale)
|
bool Accelerometer::set_scale(const Vector3f &scale)
|
||||||
{
|
{
|
||||||
if (Vector3f(_scale - scale).longerThan(0.01f)) {
|
if (Vector3f(_scale - scale).longerThan(0.01f)) {
|
||||||
_scale = scale;
|
if ((scale(0) > 0.f) && (scale(1) > 0.f) && (scale(2) > 0.f) &&
|
||||||
|
PX4_ISFINITE(scale(0)) && PX4_ISFINITE(scale(1)) && PX4_ISFINITE(scale(2))) {
|
||||||
|
|
||||||
_calibration_count++;
|
_scale = scale;
|
||||||
return true;
|
_calibration_count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -126,10 +126,11 @@ void Gyroscope::SensorCorrectionsUpdate(bool force)
|
|||||||
bool Gyroscope::set_offset(const Vector3f &offset)
|
bool Gyroscope::set_offset(const Vector3f &offset)
|
||||||
{
|
{
|
||||||
if (Vector3f(_offset - offset).longerThan(0.01f)) {
|
if (Vector3f(_offset - offset).longerThan(0.01f)) {
|
||||||
_offset = offset;
|
if (PX4_ISFINITE(offset(0)) && PX4_ISFINITE(offset(1)) && PX4_ISFINITE(offset(2))) {
|
||||||
|
_offset = offset;
|
||||||
_calibration_count++;
|
_calibration_count++;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -86,10 +86,11 @@ void Magnetometer::set_external(bool external)
|
|||||||
bool Magnetometer::set_offset(const Vector3f &offset)
|
bool Magnetometer::set_offset(const Vector3f &offset)
|
||||||
{
|
{
|
||||||
if (Vector3f(_offset - offset).longerThan(0.01f)) {
|
if (Vector3f(_offset - offset).longerThan(0.01f)) {
|
||||||
_offset = offset;
|
if (PX4_ISFINITE(offset(0)) && PX4_ISFINITE(offset(1)) && PX4_ISFINITE(offset(2))) {
|
||||||
|
_offset = offset;
|
||||||
_calibration_count++;
|
_calibration_count++;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -98,12 +99,16 @@ bool Magnetometer::set_offset(const Vector3f &offset)
|
|||||||
bool Magnetometer::set_scale(const Vector3f &scale)
|
bool Magnetometer::set_scale(const Vector3f &scale)
|
||||||
{
|
{
|
||||||
if (Vector3f(_scale.diag() - scale).longerThan(0.01f)) {
|
if (Vector3f(_scale.diag() - scale).longerThan(0.01f)) {
|
||||||
_scale(0, 0) = scale(0);
|
if ((scale(0) > 0.f) && (scale(1) > 0.f) && (scale(2) > 0.f) &&
|
||||||
_scale(1, 1) = scale(1);
|
PX4_ISFINITE(scale(0)) && PX4_ISFINITE(scale(1)) && PX4_ISFINITE(scale(2))) {
|
||||||
_scale(2, 2) = scale(2);
|
|
||||||
|
|
||||||
_calibration_count++;
|
_scale(0, 0) = scale(0);
|
||||||
return true;
|
_scale(1, 1) = scale(1);
|
||||||
|
_scale(2, 2) = scale(2);
|
||||||
|
|
||||||
|
_calibration_count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -112,17 +117,20 @@ bool Magnetometer::set_scale(const Vector3f &scale)
|
|||||||
bool Magnetometer::set_offdiagonal(const Vector3f &offdiagonal)
|
bool Magnetometer::set_offdiagonal(const Vector3f &offdiagonal)
|
||||||
{
|
{
|
||||||
if (Vector3f(Vector3f{_scale(0, 1), _scale(0, 2), _scale(1, 2)} - offdiagonal).longerThan(0.01f)) {
|
if (Vector3f(Vector3f{_scale(0, 1), _scale(0, 2), _scale(1, 2)} - offdiagonal).longerThan(0.01f)) {
|
||||||
_scale(0, 1) = offdiagonal(0);
|
if (PX4_ISFINITE(offdiagonal(0)) && PX4_ISFINITE(offdiagonal(1)) && PX4_ISFINITE(offdiagonal(2))) {
|
||||||
_scale(1, 0) = offdiagonal(0);
|
|
||||||
|
|
||||||
_scale(0, 2) = offdiagonal(1);
|
_scale(0, 1) = offdiagonal(0);
|
||||||
_scale(2, 0) = offdiagonal(1);
|
_scale(1, 0) = offdiagonal(0);
|
||||||
|
|
||||||
_scale(1, 2) = offdiagonal(2);
|
_scale(0, 2) = offdiagonal(1);
|
||||||
_scale(2, 1) = offdiagonal(2);
|
_scale(2, 0) = offdiagonal(1);
|
||||||
|
|
||||||
_calibration_count++;
|
_scale(1, 2) = offdiagonal(2);
|
||||||
return true;
|
_scale(2, 1) = offdiagonal(2);
|
||||||
|
|
||||||
|
_calibration_count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -275,7 +283,7 @@ void Magnetometer::PrintStatus()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG_BUILD)
|
#if defined(DEBUG_BUILD)
|
||||||
_scale.print()
|
_scale.print();
|
||||||
#endif // DEBUG_BUILD
|
#endif // DEBUG_BUILD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user