mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 02:16:53 +08:00
vehicle_imu/vehicle_magnetometer add calibration indicator to message
- vehicle_imu/vehicle_magnetometer add monotonically increasing `calibration_count` field so that downstream subscribers are aware of calibration changes
This commit is contained in:
@@ -15,3 +15,5 @@ uint8 CLIPPING_X = 1
|
|||||||
uint8 CLIPPING_Y = 2
|
uint8 CLIPPING_Y = 2
|
||||||
uint8 CLIPPING_Z = 4
|
uint8 CLIPPING_Z = 4
|
||||||
uint8 delta_velocity_clipping # bitfield indicating if there was any accelerometer clipping (per axis) during the integration time frame
|
uint8 delta_velocity_clipping # bitfield indicating if there was any accelerometer clipping (per axis) during the integration time frame
|
||||||
|
|
||||||
|
uint8 calibration_count # Calibration changed counter. Monotonically increases whenever calibration changes.
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ uint64 timestamp_sample # the timestamp of the raw data (microseconds)
|
|||||||
uint32 device_id # unique device ID for the selected magnetometer
|
uint32 device_id # unique device ID for the selected magnetometer
|
||||||
|
|
||||||
float32[3] magnetometer_ga # Magnetic field in NED body frame, in Gauss
|
float32[3] magnetometer_ga # Magnetic field in NED body frame, in Gauss
|
||||||
|
|
||||||
|
uint8 calibration_count # Calibration changed counter. Monotonically increases whenever calibration changes.
|
||||||
|
|||||||
@@ -149,11 +149,27 @@ void Accelerometer::ParametersUpdate()
|
|||||||
_priority = DEFAULT_PRIORITY;
|
_priority = DEFAULT_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool calibration_changed = false;
|
||||||
|
|
||||||
// CAL_ACCx_OFF{X,Y,Z}
|
// CAL_ACCx_OFF{X,Y,Z}
|
||||||
_offset = GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index);
|
const Vector3f offset = GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index);
|
||||||
|
|
||||||
|
if (Vector3f(_offset - offset).norm_squared() > 0.001f * 0.001f) {
|
||||||
|
calibration_changed = true;
|
||||||
|
_offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
// CAL_ACCx_SCALE{X,Y,Z}
|
// CAL_ACCx_SCALE{X,Y,Z}
|
||||||
_scale = GetCalibrationParamsVector3f(SensorString(), "SCALE", _calibration_index);
|
const Vector3f scale = GetCalibrationParamsVector3f(SensorString(), "SCALE", _calibration_index);
|
||||||
|
|
||||||
|
if (Vector3f(_scale - scale).norm_squared() > 0.001f * 0.001f) {
|
||||||
|
calibration_changed = true;
|
||||||
|
_scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calibration_changed) {
|
||||||
|
_calibration_count++;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Reset();
|
Reset();
|
||||||
@@ -170,6 +186,8 @@ void Accelerometer::Reset()
|
|||||||
_priority = _external ? DEFAULT_EXTERNAL_PRIORITY : DEFAULT_PRIORITY;
|
_priority = _external ? DEFAULT_EXTERNAL_PRIORITY : DEFAULT_PRIORITY;
|
||||||
|
|
||||||
_calibration_index = -1;
|
_calibration_index = -1;
|
||||||
|
|
||||||
|
_calibration_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Accelerometer::ParametersSave()
|
bool Accelerometer::ParametersSave()
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public:
|
|||||||
void set_offset(const matrix::Vector3f &offset) { _offset = offset; }
|
void set_offset(const matrix::Vector3f &offset) { _offset = offset; }
|
||||||
void set_scale(const matrix::Vector3f &scale) { _scale = scale; }
|
void set_scale(const matrix::Vector3f &scale) { _scale = scale; }
|
||||||
|
|
||||||
|
uint8_t calibration_count() const { return _calibration_count; }
|
||||||
uint32_t device_id() const { return _device_id; }
|
uint32_t device_id() const { return _device_id; }
|
||||||
bool enabled() const { return (_priority > 0); }
|
bool enabled() const { return (_priority > 0); }
|
||||||
bool external() const { return _external; }
|
bool external() const { return _external; }
|
||||||
@@ -98,5 +99,7 @@ private:
|
|||||||
int32_t _priority{-1};
|
int32_t _priority{-1};
|
||||||
|
|
||||||
bool _external{false};
|
bool _external{false};
|
||||||
|
|
||||||
|
uint8_t _calibration_count{0};
|
||||||
};
|
};
|
||||||
} // namespace calibration
|
} // namespace calibration
|
||||||
|
|||||||
@@ -149,8 +149,19 @@ void Gyroscope::ParametersUpdate()
|
|||||||
_priority = DEFAULT_PRIORITY;
|
_priority = DEFAULT_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool calibration_changed = false;
|
||||||
|
|
||||||
// CAL_GYROx_OFF{X,Y,Z}
|
// CAL_GYROx_OFF{X,Y,Z}
|
||||||
_offset = GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index);
|
const Vector3f offset = GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index);
|
||||||
|
|
||||||
|
if (Vector3f(_offset - offset).norm_squared() > 0.001f * 0.001f) {
|
||||||
|
calibration_changed = true;
|
||||||
|
_offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calibration_changed) {
|
||||||
|
_calibration_count++;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Reset();
|
Reset();
|
||||||
@@ -166,6 +177,8 @@ void Gyroscope::Reset()
|
|||||||
_priority = _external ? DEFAULT_EXTERNAL_PRIORITY : DEFAULT_PRIORITY;
|
_priority = _external ? DEFAULT_EXTERNAL_PRIORITY : DEFAULT_PRIORITY;
|
||||||
|
|
||||||
_calibration_index = -1;
|
_calibration_index = -1;
|
||||||
|
|
||||||
|
_calibration_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Gyroscope::ParametersSave()
|
bool Gyroscope::ParametersSave()
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public:
|
|||||||
void set_external(bool external = true);
|
void set_external(bool external = true);
|
||||||
void set_offset(const matrix::Vector3f &offset) { _offset = offset; }
|
void set_offset(const matrix::Vector3f &offset) { _offset = offset; }
|
||||||
|
|
||||||
|
uint8_t calibration_count() const { return _calibration_count; }
|
||||||
uint32_t device_id() const { return _device_id; }
|
uint32_t device_id() const { return _device_id; }
|
||||||
bool enabled() const { return (_priority > 0); }
|
bool enabled() const { return (_priority > 0); }
|
||||||
bool external() const { return _external; }
|
bool external() const { return _external; }
|
||||||
@@ -96,5 +97,7 @@ private:
|
|||||||
int32_t _priority{-1};
|
int32_t _priority{-1};
|
||||||
|
|
||||||
bool _external{false};
|
bool _external{false};
|
||||||
|
|
||||||
|
uint8_t _calibration_count{0};
|
||||||
};
|
};
|
||||||
} // namespace calibration
|
} // namespace calibration
|
||||||
|
|||||||
@@ -157,21 +157,42 @@ void Magnetometer::ParametersUpdate()
|
|||||||
_priority = new_priority;
|
_priority = new_priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool calibration_changed = false;
|
||||||
|
|
||||||
// CAL_MAGx_OFF{X,Y,Z}
|
// CAL_MAGx_OFF{X,Y,Z}
|
||||||
_offset = GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index);
|
const Vector3f offset = GetCalibrationParamsVector3f(SensorString(), "OFF", _calibration_index);
|
||||||
|
|
||||||
|
if (Vector3f(_offset - offset).norm_squared() > 0.001f * 0.001f) {
|
||||||
|
calibration_changed = true;
|
||||||
|
_offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
// CAL_MAGx_SCALE{X,Y,Z}
|
// CAL_MAGx_SCALE{X,Y,Z}
|
||||||
const Vector3f diag = GetCalibrationParamsVector3f(SensorString(), "SCALE", _calibration_index);
|
const Vector3f diag = GetCalibrationParamsVector3f(SensorString(), "SCALE", _calibration_index);
|
||||||
|
|
||||||
|
if (Vector3f(_scale.diag() - diag).norm_squared() > 0.001f * 0.001f) {
|
||||||
|
calibration_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
// CAL_MAGx_ODIAG{X,Y,Z}
|
// CAL_MAGx_ODIAG{X,Y,Z}
|
||||||
const Vector3f offdiag = GetCalibrationParamsVector3f(SensorString(), "ODIAG", _calibration_index);
|
const Vector3f offdiag = GetCalibrationParamsVector3f(SensorString(), "ODIAG", _calibration_index);
|
||||||
|
|
||||||
float scale[9] {
|
if (Vector3f(Vector3f{_scale(0, 1), _scale(0, 2), _scale(1, 2)} - offdiag).norm_squared() > 0.001f * 0.001f) {
|
||||||
diag(0), offdiag(0), offdiag(1),
|
calibration_changed = true;
|
||||||
offdiag(0), diag(1), offdiag(2),
|
}
|
||||||
offdiag(1), offdiag(2), diag(2)
|
|
||||||
};
|
if (calibration_changed) {
|
||||||
_scale = Matrix3f{scale};
|
|
||||||
|
float scale[9] {
|
||||||
|
diag(0), offdiag(0), offdiag(1),
|
||||||
|
offdiag(0), diag(1), offdiag(2),
|
||||||
|
offdiag(1), offdiag(2), diag(2)
|
||||||
|
};
|
||||||
|
_scale = Matrix3f{scale};
|
||||||
|
|
||||||
|
_calibration_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// CAL_MAGx_COMP{X,Y,Z}
|
// CAL_MAGx_COMP{X,Y,Z}
|
||||||
_power_compensation = GetCalibrationParamsVector3f(SensorString(), "COMP", _calibration_index);
|
_power_compensation = GetCalibrationParamsVector3f(SensorString(), "COMP", _calibration_index);
|
||||||
@@ -194,6 +215,8 @@ void Magnetometer::Reset()
|
|||||||
_priority = _external ? DEFAULT_EXTERNAL_PRIORITY : DEFAULT_PRIORITY;
|
_priority = _external ? DEFAULT_EXTERNAL_PRIORITY : DEFAULT_PRIORITY;
|
||||||
|
|
||||||
_calibration_index = -1;
|
_calibration_index = -1;
|
||||||
|
|
||||||
|
_calibration_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Magnetometer::ParametersSave()
|
bool Magnetometer::ParametersSave()
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ public:
|
|||||||
void set_offdiagonal(const matrix::Vector3f &offdiagonal);
|
void set_offdiagonal(const matrix::Vector3f &offdiagonal);
|
||||||
void set_rotation(Rotation rotation);
|
void set_rotation(Rotation rotation);
|
||||||
|
|
||||||
|
uint8_t calibration_count() const { return _calibration_count; }
|
||||||
uint32_t device_id() const { return _device_id; }
|
uint32_t device_id() const { return _device_id; }
|
||||||
bool enabled() const { return (_priority > 0); }
|
bool enabled() const { return (_priority > 0); }
|
||||||
bool external() const { return _external; }
|
bool external() const { return _external; }
|
||||||
@@ -105,5 +106,7 @@ private:
|
|||||||
int32_t _priority{-1};
|
int32_t _priority{-1};
|
||||||
|
|
||||||
bool _external{false};
|
bool _external{false};
|
||||||
|
|
||||||
|
uint8_t _calibration_count{0};
|
||||||
};
|
};
|
||||||
} // namespace calibration
|
} // namespace calibration
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ void VehicleIMU::Run()
|
|||||||
imu.delta_angle_dt = gyro_integral_dt;
|
imu.delta_angle_dt = gyro_integral_dt;
|
||||||
imu.delta_velocity_dt = accel_integral_dt;
|
imu.delta_velocity_dt = accel_integral_dt;
|
||||||
imu.delta_velocity_clipping = _delta_velocity_clipping;
|
imu.delta_velocity_clipping = _delta_velocity_clipping;
|
||||||
|
imu.calibration_count = _accel_calibration.calibration_count() + _gyro_calibration.calibration_count();
|
||||||
imu.timestamp = hrt_absolute_time();
|
imu.timestamp = hrt_absolute_time();
|
||||||
_vehicle_imu_pub.publish(imu);
|
_vehicle_imu_pub.publish(imu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,6 +357,7 @@ void VehicleMagnetometer::Publish(uint8_t instance, bool multi)
|
|||||||
out.timestamp_sample = timestamp_sample;
|
out.timestamp_sample = timestamp_sample;
|
||||||
out.device_id = _calibration[instance].device_id();
|
out.device_id = _calibration[instance].device_id();
|
||||||
magnetometer_data.copyTo(out.magnetometer_ga);
|
magnetometer_data.copyTo(out.magnetometer_ga);
|
||||||
|
out.calibration_count = _calibration[instance].calibration_count();
|
||||||
|
|
||||||
out.timestamp = hrt_absolute_time();
|
out.timestamp = hrt_absolute_time();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user