|
|
|
@ -123,6 +123,17 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
@@ -123,6 +123,17 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
|
|
|
|
|
|
|
|
|
|
const Vector3f raw{x, y, z}; |
|
|
|
|
|
|
|
|
|
// Clipping
|
|
|
|
|
sensor_gyro_status_s &status = _sensor_status_pub.get(); |
|
|
|
|
const float clip_limit = (_range / _scale) * 0.95f; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) { |
|
|
|
|
if (fabsf(raw(i)) > clip_limit) { |
|
|
|
|
status.clipping[i]++; |
|
|
|
|
_integrator_clipping++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Apply range scale and the calibrating offset/scale
|
|
|
|
|
const Vector3f val_calibrated{((raw * _scale) - _calibration_offset)}; |
|
|
|
|
|
|
|
|
@ -157,6 +168,8 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
@@ -157,6 +168,8 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
|
|
|
|
|
Vector3f integrated_value; |
|
|
|
|
uint32_t integral_dt = 0; |
|
|
|
|
|
|
|
|
|
_integrator_samples++; |
|
|
|
|
|
|
|
|
|
if (_integrator.put(timestamp, val_calibrated, integrated_value, integral_dt)) { |
|
|
|
|
|
|
|
|
|
sensor_gyro_s report{}; |
|
|
|
@ -176,12 +189,34 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
@@ -176,12 +189,34 @@ PX4Gyroscope::update(hrt_abstime timestamp, float x, float y, float z)
|
|
|
|
|
report.z = val_filtered(2); |
|
|
|
|
|
|
|
|
|
report.integral_dt = integral_dt; |
|
|
|
|
report.integral_samples = _integrator_samples; |
|
|
|
|
report.x_integral = integrated_value(0); |
|
|
|
|
report.y_integral = integrated_value(1); |
|
|
|
|
report.z_integral = integrated_value(2); |
|
|
|
|
report.integral_clip_count = _integrator_clipping; |
|
|
|
|
|
|
|
|
|
_sensor_pub.publish(report); |
|
|
|
|
|
|
|
|
|
// reset integrator
|
|
|
|
|
ResetIntegrator(); |
|
|
|
|
|
|
|
|
|
// update vibration metrics
|
|
|
|
|
const Vector3f delta_angle = integrated_value * (integral_dt * 1.e-6f); |
|
|
|
|
UpdateVibrationMetrics(delta_angle); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// publish status
|
|
|
|
|
status.device_id = _device_id; |
|
|
|
|
status.error_count = _error_count; |
|
|
|
|
status.full_scale_range = _range; |
|
|
|
|
status.rotation = _rotation; |
|
|
|
|
status.measure_rate = _update_rate; |
|
|
|
|
status.sample_rate = _sample_rate; |
|
|
|
|
status.temperature = _temperature; |
|
|
|
|
status.vibration_metric = _vibration_metric; |
|
|
|
|
status.coning_vibration = _coning_vibration; |
|
|
|
|
status.timestamp = hrt_absolute_time(); |
|
|
|
|
_sensor_status_pub.publish(status); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
@ -342,6 +377,9 @@ PX4Gyroscope::updateFIFO(const FIFOSample &sample)
@@ -342,6 +377,9 @@ PX4Gyroscope::updateFIFO(const FIFOSample &sample)
|
|
|
|
|
report.timestamp = _integrator_timestamp_sample; |
|
|
|
|
_sensor_pub.publish(report); |
|
|
|
|
|
|
|
|
|
// update vibration metrics
|
|
|
|
|
const Vector3f delta_angle = val_int_calibrated * (integrator_dt_us * 1.e-6f); |
|
|
|
|
UpdateVibrationMetrics(delta_angle); |
|
|
|
|
|
|
|
|
|
// reset integrator
|
|
|
|
|
ResetIntegrator(); |
|
|
|
@ -390,6 +428,20 @@ PX4Gyroscope::ConfigureFilter(float cutoff_freq)
@@ -390,6 +428,20 @@ PX4Gyroscope::ConfigureFilter(float cutoff_freq)
|
|
|
|
|
_filterArrayZ.set_cutoff_frequency(_sample_rate, cutoff_freq); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
PX4Gyroscope::UpdateVibrationMetrics(const Vector3f &delta_angle) |
|
|
|
|
{ |
|
|
|
|
// Gyro high frequency vibe = filtered length of (delta_angle - prev_delta_angle)
|
|
|
|
|
const Vector3f delta_angle_diff = delta_angle - _delta_angle_prev; |
|
|
|
|
_vibration_metric = 0.99f * _vibration_metric + 0.01f * delta_angle_diff.norm(); |
|
|
|
|
|
|
|
|
|
// Gyro delta angle coning metric = filtered length of (delta_angle x prev_delta_angle)
|
|
|
|
|
const Vector3f coning_metric = delta_angle % _delta_angle_prev; |
|
|
|
|
_coning_vibration = 0.99f * _coning_vibration + 0.01f * coning_metric.norm(); |
|
|
|
|
|
|
|
|
|
_delta_angle_prev = delta_angle; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
PX4Gyroscope::print_status() |
|
|
|
|
{ |
|
|
|
|