AP_Compass: AP_Compass_test: code enhancements
- Use panic() instead of looping forever. - Readability improvement with the use of MAX() and MIN().
This commit is contained in:
parent
a61f9855d3
commit
e5de4f2348
@ -16,9 +16,7 @@ void setup() {
|
|||||||
hal.console->println("Compass library test");
|
hal.console->println("Compass library test");
|
||||||
|
|
||||||
if (!compass.init()) {
|
if (!compass.init()) {
|
||||||
hal.console->println("compass initialisation failed!");
|
AP_HAL::panic("compass initialisation failed!");
|
||||||
while (1)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
hal.console->printf("init done - %u compasses detected\n", compass.get_count());
|
hal.console->printf("init done - %u compasses detected\n", compass.get_count());
|
||||||
|
|
||||||
@ -64,26 +62,14 @@ void loop()
|
|||||||
const Vector3f &mag = compass.get_field(i);
|
const Vector3f &mag = compass.get_field(i);
|
||||||
|
|
||||||
// capture min
|
// capture min
|
||||||
if (mag.x < min[i][0]) {
|
min[i][0] = MIN(mag.x, min[i][0]);
|
||||||
min[i][0] = mag.x;
|
min[i][1] = MIN(mag.y, min[i][1]);
|
||||||
}
|
min[i][2] = MIN(mag.z, min[i][2]);
|
||||||
if (mag.y < min[i][1]) {
|
|
||||||
min[i][1] = mag.y;
|
|
||||||
}
|
|
||||||
if (mag.z < min[i][2]) {
|
|
||||||
min[i][2] = mag.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
// capture max
|
// capture max
|
||||||
if (mag.x > max[i][0]) {
|
max[i][0] = MAX(mag.x, max[i][0]);
|
||||||
max[i][0] = mag.x;
|
max[i][1] = MAX(mag.y, max[i][1]);
|
||||||
}
|
max[i][2] = MAX(mag.z, max[i][2]);
|
||||||
if (mag.y > max[i][1]) {
|
|
||||||
max[i][1] = mag.y;
|
|
||||||
}
|
|
||||||
if (mag.z > max[i][2]) {
|
|
||||||
max[i][2] = mag.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate offsets
|
// calculate offsets
|
||||||
offset[i][0] = -(max[i][0] + min[i][0]) / 2;
|
offset[i][0] = -(max[i][0] + min[i][0]) / 2;
|
||||||
|
Loading…
Reference in New Issue
Block a user