@@ -35,16 +35,17 @@ bool AP_GPS_Blended::_calc_weights(void)
35
35
uint32_t max_rate_ms = 0 ; // largest update interval of a GPS receiver
36
36
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
37
37
// Find largest and smallest times
38
- if (gps.state [i].last_gps_time_ms > max_ms) {
39
- max_ms = gps.state [i].last_gps_time_ms ;
38
+ const auto &state_i = gps.state [i];
39
+ if (state_i.last_gps_time_ms > max_ms) {
40
+ max_ms = state_i.last_gps_time_ms ;
40
41
}
41
- if ((gps. state [i]. last_gps_time_ms < min_ms) && (gps. state [i] .last_gps_time_ms > 0 )) {
42
- min_ms = gps. state [i] .last_gps_time_ms ;
42
+ if ((state_i. last_gps_time_ms < min_ms) && (state_i .last_gps_time_ms > 0 )) {
43
+ min_ms = state_i .last_gps_time_ms ;
43
44
}
44
45
max_rate_ms = MAX (gps.get_rate_ms (i), max_rate_ms);
45
- if (isinf (gps. state [i] .speed_accuracy ) ||
46
- isinf (gps. state [i] .horizontal_accuracy ) ||
47
- isinf (gps. state [i] .vertical_accuracy )) {
46
+ if (isinf (state_i .speed_accuracy ) ||
47
+ isinf (state_i .horizontal_accuracy ) ||
48
+ isinf (state_i .vertical_accuracy )) {
48
49
return false ;
49
50
}
50
51
}
@@ -60,9 +61,10 @@ bool AP_GPS_Blended::_calc_weights(void)
60
61
float speed_accuracy_sum_sq = 0 .0f ;
61
62
if (gps._blend_mask & BLEND_MASK_USE_SPD_ACC) {
62
63
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
63
- if (gps.state [i].status >= AP_GPS::GPS_OK_FIX_3D) {
64
- if (gps.state [i].have_speed_accuracy && gps.state [i].speed_accuracy > 0 .0f ) {
65
- speed_accuracy_sum_sq += sq (gps.state [i].speed_accuracy );
64
+ const auto &state_i = gps.state [i];
65
+ if (state_i.status >= AP_GPS::GPS_OK_FIX_3D) {
66
+ if (state_i.have_speed_accuracy && state_i.speed_accuracy > 0 .0f ) {
67
+ speed_accuracy_sum_sq += sq (state_i.speed_accuracy );
66
68
} else {
67
69
// not all receivers support this metric so set it to zero and don't use it
68
70
speed_accuracy_sum_sq = 0 .0f ;
@@ -76,9 +78,10 @@ bool AP_GPS_Blended::_calc_weights(void)
76
78
float horizontal_accuracy_sum_sq = 0 .0f ;
77
79
if (gps._blend_mask & BLEND_MASK_USE_HPOS_ACC) {
78
80
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
79
- if (gps.state [i].status >= AP_GPS::GPS_OK_FIX_2D) {
80
- if (gps.state [i].have_horizontal_accuracy && gps.state [i].horizontal_accuracy > 0 .0f ) {
81
- horizontal_accuracy_sum_sq += sq (gps.state [i].horizontal_accuracy );
81
+ const auto &state_i = gps.state [i];
82
+ if (state_i.status >= AP_GPS::GPS_OK_FIX_2D) {
83
+ if (state_i.have_horizontal_accuracy && state_i.horizontal_accuracy > 0 .0f ) {
84
+ horizontal_accuracy_sum_sq += sq (state_i.horizontal_accuracy );
82
85
} else {
83
86
// not all receivers support this metric so set it to zero and don't use it
84
87
horizontal_accuracy_sum_sq = 0 .0f ;
@@ -92,9 +95,10 @@ bool AP_GPS_Blended::_calc_weights(void)
92
95
float vertical_accuracy_sum_sq = 0 .0f ;
93
96
if (gps._blend_mask & BLEND_MASK_USE_VPOS_ACC) {
94
97
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
95
- if (gps.state [i].status >= AP_GPS::GPS_OK_FIX_3D) {
96
- if (gps.state [i].have_vertical_accuracy && gps.state [i].vertical_accuracy > 0 .0f ) {
97
- vertical_accuracy_sum_sq += sq (gps.state [i].vertical_accuracy );
98
+ const auto &state_i = gps.state [i];
99
+ if (state_i.status >= AP_GPS::GPS_OK_FIX_3D) {
100
+ if (state_i.have_vertical_accuracy && state_i.vertical_accuracy > 0 .0f ) {
101
+ vertical_accuracy_sum_sq += sq (state_i.vertical_accuracy );
98
102
} else {
99
103
// not all receivers support this metric so set it to zero and don't use it
100
104
vertical_accuracy_sum_sq = 0 .0f ;
@@ -119,8 +123,9 @@ bool AP_GPS_Blended::_calc_weights(void)
119
123
// calculate the weights using the inverse of the variances
120
124
float sum_of_hpos_weights = 0 .0f ;
121
125
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
122
- if (gps.state [i].status >= AP_GPS::GPS_OK_FIX_2D && gps.state [i].horizontal_accuracy >= 0 .001f ) {
123
- hpos_blend_weights[i] = horizontal_accuracy_sum_sq / sq (gps.state [i].horizontal_accuracy );
126
+ const auto &state_i = gps.state [i];
127
+ if (state_i.status >= AP_GPS::GPS_OK_FIX_2D && state_i.horizontal_accuracy >= 0 .001f ) {
128
+ hpos_blend_weights[i] = horizontal_accuracy_sum_sq / sq (state_i.horizontal_accuracy );
124
129
sum_of_hpos_weights += hpos_blend_weights[i];
125
130
}
126
131
}
@@ -139,8 +144,9 @@ bool AP_GPS_Blended::_calc_weights(void)
139
144
// calculate the weights using the inverse of the variances
140
145
float sum_of_vpos_weights = 0 .0f ;
141
146
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
142
- if (gps.state [i].status >= AP_GPS::GPS_OK_FIX_3D && gps.state [i].vertical_accuracy >= 0 .001f ) {
143
- vpos_blend_weights[i] = vertical_accuracy_sum_sq / sq (gps.state [i].vertical_accuracy );
147
+ const auto &state_i = gps.state [i];
148
+ if (state_i.status >= AP_GPS::GPS_OK_FIX_3D && state_i.vertical_accuracy >= 0 .001f ) {
149
+ vpos_blend_weights[i] = vertical_accuracy_sum_sq / sq (state_i.vertical_accuracy );
144
150
sum_of_vpos_weights += vpos_blend_weights[i];
145
151
}
146
152
}
@@ -159,8 +165,9 @@ bool AP_GPS_Blended::_calc_weights(void)
159
165
// calculate the weights using the inverse of the variances
160
166
float sum_of_spd_weights = 0 .0f ;
161
167
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
162
- if (gps.state [i].status >= AP_GPS::GPS_OK_FIX_3D && gps.state [i].speed_accuracy >= 0 .001f ) {
163
- spd_blend_weights[i] = speed_accuracy_sum_sq / sq (gps.state [i].speed_accuracy );
168
+ const auto &state_i = gps.state [i];
169
+ if (state_i.status >= AP_GPS::GPS_OK_FIX_3D && state_i.speed_accuracy >= 0 .001f ) {
170
+ spd_blend_weights[i] = speed_accuracy_sum_sq / sq (state_i.speed_accuracy );
164
171
sum_of_spd_weights += spd_blend_weights[i];
165
172
}
166
173
}
@@ -243,45 +250,46 @@ void AP_GPS_Blended::calc_state(void)
243
250
244
251
// combine the states into a blended solution
245
252
for (uint8_t i=0 ; i<GPS_MAX_RECEIVERS; i++) {
253
+ const auto &state_i = gps.state [i];
246
254
// use the highest status
247
- if (gps. state [i] .status > state.status ) {
248
- state.status = gps. state [i] .status ;
255
+ if (state_i .status > state.status ) {
256
+ state.status = state_i .status ;
249
257
}
250
258
251
259
// calculate a blended average velocity
252
- state.velocity += gps. state [i] .velocity * _blend_weights[i];
260
+ state.velocity += state_i .velocity * _blend_weights[i];
253
261
254
262
// report the best valid accuracies and DOP metrics
255
263
256
- if (gps. state [i]. have_horizontal_accuracy && gps. state [i]. horizontal_accuracy > 0 .0f && gps. state [i] .horizontal_accuracy < state.horizontal_accuracy ) {
264
+ if (state_i. have_horizontal_accuracy && state_i. horizontal_accuracy > 0 .0f && state_i .horizontal_accuracy < state.horizontal_accuracy ) {
257
265
state.have_horizontal_accuracy = true ;
258
- state.horizontal_accuracy = gps. state [i] .horizontal_accuracy ;
266
+ state.horizontal_accuracy = state_i .horizontal_accuracy ;
259
267
}
260
268
261
- if (gps. state [i]. have_vertical_accuracy && gps. state [i]. vertical_accuracy > 0 .0f && gps. state [i] .vertical_accuracy < state.vertical_accuracy ) {
269
+ if (state_i. have_vertical_accuracy && state_i. vertical_accuracy > 0 .0f && state_i .vertical_accuracy < state.vertical_accuracy ) {
262
270
state.have_vertical_accuracy = true ;
263
- state.vertical_accuracy = gps. state [i] .vertical_accuracy ;
271
+ state.vertical_accuracy = state_i .vertical_accuracy ;
264
272
}
265
273
266
- if (gps. state [i] .have_vertical_velocity ) {
274
+ if (state_i .have_vertical_velocity ) {
267
275
state.have_vertical_velocity = true ;
268
276
}
269
277
270
- if (gps. state [i]. have_speed_accuracy && gps. state [i]. speed_accuracy > 0 .0f && gps. state [i] .speed_accuracy < state.speed_accuracy ) {
278
+ if (state_i. have_speed_accuracy && state_i. speed_accuracy > 0 .0f && state_i .speed_accuracy < state.speed_accuracy ) {
271
279
state.have_speed_accuracy = true ;
272
- state.speed_accuracy = gps. state [i] .speed_accuracy ;
280
+ state.speed_accuracy = state_i .speed_accuracy ;
273
281
}
274
282
275
- if (gps. state [i]. hdop > 0 && gps. state [i] .hdop < state.hdop ) {
276
- state.hdop = gps. state [i] .hdop ;
283
+ if (state_i. hdop > 0 && state_i .hdop < state.hdop ) {
284
+ state.hdop = state_i .hdop ;
277
285
}
278
286
279
- if (gps. state [i]. vdop > 0 && gps. state [i] .vdop < state.vdop ) {
280
- state.vdop = gps. state [i] .vdop ;
287
+ if (state_i. vdop > 0 && state_i .vdop < state.vdop ) {
288
+ state.vdop = state_i .vdop ;
281
289
}
282
290
283
- if (gps. state [i]. num_sats > 0 && gps. state [i] .num_sats > state.num_sats ) {
284
- state.num_sats = gps. state [i] .num_sats ;
291
+ if (state_i. num_sats > 0 && state_i .num_sats > state.num_sats ) {
292
+ state.num_sats = state_i .num_sats ;
285
293
}
286
294
287
295
// report a blended average GPS antenna position
0 commit comments