@@ -55,8 +55,6 @@ VehicleAngularVelocity::VehicleAngularVelocity() :
55
55
VehicleAngularVelocity::~VehicleAngularVelocity ()
56
56
{
57
57
Stop ();
58
-
59
- perf_free (_interval_perf);
60
58
}
61
59
62
60
bool VehicleAngularVelocity::Start ()
@@ -88,37 +86,36 @@ void VehicleAngularVelocity::Stop()
88
86
89
87
void VehicleAngularVelocity::CheckFilters ()
90
88
{
91
- if ((hrt_elapsed_time (&_filter_check_last) > 100_ms)) {
92
- _filter_check_last = hrt_absolute_time ();
89
+ // check filter periodically (roughly once every 1-3 seconds depending on sensor configuration)
90
+ if (_interval_count > 2500 ) {
91
+ bool sample_rate_changed = false ;
93
92
94
93
// calculate sensor update rate
95
- const float sample_interval_avg = perf_mean (_interval_perf) ;
94
+ const float sample_interval_avg = _interval_sum / _interval_count ;
96
95
97
96
if (PX4_ISFINITE (sample_interval_avg) && (sample_interval_avg > 0 .0f )) {
98
97
99
- const float update_rate_hz = 1 .0f / sample_interval_avg;
98
+ const float update_rate_hz = 1 .e6f / sample_interval_avg;
100
99
101
100
if ((fabsf (update_rate_hz) > 0 .0f ) && PX4_ISFINITE (update_rate_hz)) {
102
101
_update_rate_hz = update_rate_hz;
103
102
104
103
// check if sample rate error is greater than 1%
105
104
if ((fabsf (_update_rate_hz - _filter_sample_rate) / _filter_sample_rate) > 0 .01f ) {
106
- ++_sample_rate_incorrect_count ;
105
+ sample_rate_changed = true ;
107
106
}
108
107
}
109
108
}
110
109
111
- const bool sample_rate_updated = (_sample_rate_incorrect_count > 50 );
112
-
113
110
const bool lp_velocity_updated = (fabsf (_lp_filter_velocity.get_cutoff_freq () - _param_imu_gyro_cutoff.get ()) > 0 .01f );
114
111
const bool notch_updated = ((fabsf (_notch_filter_velocity.getNotchFreq () - _param_imu_gyro_nf_freq.get ()) > 0 .01f )
115
112
|| (fabsf (_notch_filter_velocity.getBandwidth () - _param_imu_gyro_nf_bw.get ()) > 0 .01f ));
116
113
117
114
const bool lp_acceleration_updated = (fabsf (_lp_filter_acceleration.get_cutoff_freq () - _param_imu_dgyro_cutoff.get ()) >
118
115
0 .01f );
119
116
120
- if (sample_rate_updated || lp_velocity_updated || notch_updated || lp_acceleration_updated) {
121
- PX4_INFO ( " updating filter , sample rate: %.3f Hz -> %.3f Hz" , (double )_filter_sample_rate, (double )_update_rate_hz);
117
+ if (sample_rate_changed || lp_velocity_updated || notch_updated || lp_acceleration_updated) {
118
+ PX4_DEBUG ( " resetting filters , sample rate: %.3f Hz -> %.3f Hz" , (double )_filter_sample_rate, (double )_update_rate_hz);
122
119
_filter_sample_rate = _update_rate_hz;
123
120
124
121
// update software low pass filters
@@ -130,10 +127,10 @@ void VehicleAngularVelocity::CheckFilters()
130
127
131
128
_lp_filter_acceleration.set_cutoff_frequency (_filter_sample_rate, _param_imu_dgyro_cutoff.get ());
132
129
_lp_filter_acceleration.reset (_angular_acceleration_prev);
133
-
134
- // reset state
135
- _sample_rate_incorrect_count = 0 ;
136
130
}
131
+
132
+ // reset sample interval accumulator
133
+ _timestamp_sample_last = 0 ;
137
134
}
138
135
}
139
136
@@ -182,8 +179,8 @@ bool VehicleAngularVelocity::SensorSelectionUpdate(bool force)
182
179
183
180
_corrections.set_device_id (report.device_id );
184
181
185
- // reset sample rate monitor
186
- _sample_rate_incorrect_count = 0 ;
182
+ // reset sample interval accumulator on sensor change
183
+ _timestamp_sample_last = 0 ;
187
184
188
185
return true ;
189
186
}
@@ -233,7 +230,17 @@ void VehicleAngularVelocity::Run()
233
230
if (_sensor_sub[_selected_sensor_sub_index].copy (&sensor_data)) {
234
231
235
232
if (sensor_updated) {
236
- perf_count_interval (_interval_perf, sensor_data.timestamp_sample );
233
+ // collect sample interval average for filters
234
+ if ((_timestamp_sample_last > 0 ) && (sensor_data.timestamp_sample > _timestamp_sample_last)) {
235
+ _interval_sum += (sensor_data.timestamp_sample - _timestamp_sample_last);
236
+ _interval_count++;
237
+
238
+ } else {
239
+ _interval_sum = 0 .f ;
240
+ _interval_count = 0 .f ;
241
+ }
242
+
243
+ _timestamp_sample_last = sensor_data.timestamp_sample ;
237
244
}
238
245
239
246
// Guard against too small (< 0.2ms) and too large (> 20ms) dt's.
0 commit comments