Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Declination/tests/test_magfield.cpp
Views: 1799
#include <AP_gtest.h>12#include <AP_Math/AP_Math.h>3#include <AP_Declination/AP_Declination.h>45/*6test data from AP_Declination/generate/testvectors.py7*/8static struct {9float lat, lon;10Vector3f field;11} test_data[] = {12{-5.347785, -55.396586, {240.284, -79.152, -18.954}},13{-49.307646, 128.384946, {116.253, 0.061, -644.547}},14{-54.681456, -36.248963, {154.192, -18.211, -234.732}},15{-62.435767, -62.106564, {194.290, 43.804, -294.683}},16{8.779390, 37.908713, {357.108, 14.172, 14.024}},17{41.538128, -148.450769, {227.080, 53.006, 387.268}},18{36.054359, -80.267792, {220.590, -32.594, 440.521}},19{34.199500, 43.418665, {289.166, 26.382, 369.560}},20{-59.875966, -81.614124, {195.629, 84.684, -312.342}},21{17.601001, -93.758586, {274.301, 7.775, 274.744}},22{-86.268095, 101.445984, {-99.788, -126.515, -534.840}},23{68.089832, 99.531480, {70.104, 3.974, 607.705}},24{-30.787050, 104.800267, {232.740, -28.398, -519.563}},25{-45.686919, 23.376860, {111.202, -77.903, -239.402}},26{42.344796, 170.972092, {256.985, 1.579, 361.160}},27{11.180749, 126.619946, {392.427, -12.519, 60.590}},28{16.085182, 45.400453, {367.527, 13.863, 138.729}},29{85.912578, -111.799061, {8.172, -16.213, 568.954}},30{61.702909, 71.317152, {115.475, 38.354, 577.707}},31{-18.117488, -107.440690, {267.590, 53.018, -104.495}},32{-62.458351, 93.834118, {20.921, -130.137, -583.142}},33{-4.456960, 24.690442, {268.996, 0.281, -181.715}},34{-11.938973, 57.584278, {286.506, -51.380, -249.702}},35{-17.077653, 68.903062, {276.594, -67.083, -330.818}},36{-0.641855, -85.362927, {273.764, -0.021, 93.528}},37{70.208175, -70.794011, {54.788, -33.030, 565.194}},38{65.974445, -37.033989, {110.056, -41.337, 525.313}},39{-12.136829, 86.003211, {342.692, -33.667, -313.206}},40{-85.859369, -148.301355, {-48.300, 152.537, -536.334}},41{-19.307265, 115.056146, {324.659, 3.429, -396.785}},42{63.409946, -125.963384, {102.250, 34.962, 561.223}},43{10.445067, 60.380511, {384.749, -5.779, 62.938}},44{-54.102628, 134.827917, {84.120, 9.249, -655.864}},45{-37.512392, -13.418317, {98.314, -39.221, -216.540}},46{72.345349, 113.696131, {53.912, -7.336, 602.335}},47{55.212086, -11.672616, {179.144, -14.309, 464.924}},48{-69.962700, -143.828634, {72.069, 139.770, -551.999}},49{87.579976, -163.341588, {-9.629, -20.622, 569.787}},50{73.111174, 143.018689, {72.564, -23.169, 586.064}},51{23.697573, -29.994152, {309.137, -54.381, 178.330}},52{8.771240, -117.029349, {293.100, 40.791, 152.298}},53{-17.705434, 2.904797, {141.603, -31.071, -250.994}},54{36.273922, 68.280726, {289.178, 20.771, 423.563}},55{-23.761563, 163.511301, {300.464, 67.082, -379.323}},56{79.029797, 176.355901, {47.596, -4.724, 577.193}},57{-52.405560, 22.440300, {122.338, -88.770, -252.169}},58{72.485297, -46.002536, {70.887, -38.208, 546.530}},59{-22.183293, -159.478002, {295.811, 77.374, -257.498}},60{-24.950420, 35.883896, {150.668, -57.547, -261.731}},61{34.311721, -178.681293, {263.416, 26.642, 291.758}},62{-61.490634, 130.934200, {30.474, -18.155, -665.682}},63{2.793989, -178.226296, {331.384, 56.367, 5.643}},64{51.905236, 130.494014, {204.801, -48.610, 530.005}},65{-25.962740, -60.589052, {188.450, -40.089, -113.336}},66{64.153460, 76.711770, {98.437, 34.425, 588.123}},67{85.273389, 80.411045, {8.157, 23.324, 574.387}},68{72.227644, -175.679117, {94.668, 2.434, 565.494}},69{-15.800057, -88.398789, {255.341, 26.361, -44.696}},70{-32.252553, 140.907109, {249.932, 37.054, -516.256}},71{0.990803, 19.645312, {302.237, 6.632, -135.887}},72{13.221787, -167.051664, {297.419, 47.578, 134.337}},73{-55.704793, -147.770348, {153.269, 119.486, -498.314}},74{-21.527164, 98.030817, {291.813, -24.330, -432.389}},75{-29.459735, -169.175151, {269.771, 84.511, -361.577}},76{-77.026676, -128.521814, {57.096, 156.826, -529.076}},77{59.744040, 154.466555, {174.852, -31.321, 530.246}},78{-8.667233, -84.596843, {263.264, 6.250, 19.318}},79{-44.970992, -90.210588, {203.908, 78.088, -237.970}},80{-81.281504, 53.655592, {53.564, -172.598, -484.541}},81{-28.899249, -168.937713, {272.725, 84.310, -354.906}},82{-5.495801, -115.945089, {294.242, 45.813, 2.378}},83{-56.855722, -27.312216, {150.561, -22.699, -243.436}},84{-5.160334, -104.515570, {287.811, 39.169, 23.270}},85{-4.765155, 27.513017, {270.761, 0.084, -179.570}},86{38.850519, -83.245266, {208.706, -24.590, 466.759}},87{82.903976, -111.774971, {15.131, -10.610, 569.636}},88{65.049275, 72.501496, {95.332, 38.164, 582.824}},89{62.904242, 91.633672, {102.309, 14.476, 603.680}},90{-26.703878, 172.749541, {285.797, 77.084, -385.509}},91{-33.226726, 75.903795, {173.490, -100.050, -456.333}},92{24.643218, -30.321324, {307.312, -53.948, 191.067}},93{16.206490, 22.434794, {358.048, 19.103, 94.086}},94{46.445304, -34.626939, {217.483, -45.670, 423.301}},95{19.266180, 125.974692, {377.297, -24.128, 183.176}},96{-24.732609, -162.086198, {289.118, 80.970, -291.171}},97{10.102379, -89.724793, {278.231, 3.333, 201.223}},98{44.251765, 81.116331, {239.108, 19.539, 512.551}},99{-72.418531, -130.000797, {82.558, 150.448, -523.607}},100{12.703973, 18.436378, {353.684, 14.320, 30.949}},101{29.149731, -105.686368, {248.213, 29.644, 376.837}},102{-17.956078, -35.751483, {164.178, -72.043, -167.376}},103{-38.321171, -141.763622, {232.842, 93.184, -359.596}},104{21.175405, 50.561510, {355.480, 13.624, 223.431}},105{54.947454, -169.310847, {199.460, 23.943, 468.886}},106{-23.361657, 44.446547, {177.462, -68.674, -281.151}},107{-24.280380, 19.644762, {122.126, -31.739, -246.213}},108{-63.110180, -122.152350, {143.859, 136.021, -464.339}},109{4.519890, 40.756994, {348.158, 6.163, -44.400}},110{-61.062289, 59.265124, {84.041, -166.618, -424.664}},111{-42.770992, -60.512815, {174.635, -6.856, -175.937}}};112113114TEST(MagField, test_field_error)115{116for (const auto &d : test_data) {117Location loc(d.lat*1.0e7, d.lon*1.0e7, 0, Location::AltFrame::ABSOLUTE);118const Vector3f m = AP_Declination::get_earth_field_ga(loc);119EXPECT_FLOAT_EQ(roundf(m.x*1000), roundf(d.field.x));120EXPECT_FLOAT_EQ(roundf(m.y*1000), roundf(d.field.y));121EXPECT_FLOAT_EQ(roundf(m.z*1000), roundf(d.field.z));122}123}124125126AP_GTEST_MAIN()127int hal = 0;128129130131