Minor issue: Earthconstants are inconsistent throughout the code
Hi! Some scalingfactors from gps coords to cm or m and back are inconsistent in the libraries. It is all an interpretation thing of the earth radius. But perhaps different Interpretations in different code parts can lead to some circeling etc. Here are some numbers:
637100078,5 Earthradius in cm 1,1119494034539336550129551771138 lat to cm 89,932149510922279499920285779867 m to lat
637813700 Earthradius in cm 1,1131949079327357264771338267056 89,831528411952143512750125646537
637810000 Earthradius in cm 1,1131884502145033474576992090497 89,832049533689219166833625709993
LATLON_TO_CM 1.113195f RADIUS_OF_EARTH 6378100 AP_INERTIALNAV_LATLON_TO_CM 1.1113175f
location.cpp ... void location_offset(struct Location *loc, float ofs_north, float ofs_east) ... float dlat = ofs_north * 89.831520982f; ..
Cheers Kraut Rob
Thanks for this.
I've replaced the AP_INERTIALNAV_LATLON_TO_CM with the Location.cpp's equivalent. https://github.com/diydrones/ardupilot/commit/c20eac7a705011d9294e3af4493b159697d9dafa
Similarly switched to use AP_Math's longitude_scale function: https://github.com/diydrones/ardupilot/commit/30faf8771517b9427393627bdb182aeb21679ab6
..and removed the unused radius_of_earth constant: https://github.com/diydrones/ardupilot/commit/ae2ad8e81942a810ad5fc5c95b831b4f8af74284
I agree that our conversions from lat/lon to meters or cm is not perfectly accurate because it assumes the earth is spherical when actually it bulges in the middle but I'm not sure that it will actually make much difference and I'm pretty skeptical that it's a big enough difference that it could cause circling. Still, I'd be very happy to be wrong as the circling with AC 3.0 is a real problem!
If you have any other suggestions on this topic including things I've missed I'd love to hear them.
Dear Randy! I am a little bit ashamed, because acually the constant is not the real problem but the magnetic model of the earth i use and the declination. From what i understand the declination corrects the magnetic north to the navigational north wich we relate to using gps coords. Turning the copter (motors off) in one spot and projecting a path following the "copternose" (according to mag) to lat/lon to google earth shows me, that i would need different mag declinations / correction factors for different headings. I guess the error is something +-10 degrees!! When summing up acc values (no matter what reference bodyfr or earth/mag frame) and correcting them sooner or later by gps there must be an error of non orthogonality. That must lead to a more or less circeling. The more precise and faster in calculation we get, the more the problem must occure. I am really clueless how to overcome that the easy way. I think a better, and more complex earth magnetic model (that the arducopter probably has) is one piece of the solution. The other thing is to "somehow" reference/align the mag heading to the gps heading so the datasources are synchronized the best possible way. I don't know at wich speed the gps heading is useable. Another idea - just for testing out - could be to shift around the mag heading quickly in flight on purpose, let's say +-3degree, perhaps a quick changing, artificial error could reduce the circeling, and the shiftingspeed could be an anti-circeling factor?
Greets Rob
Von: Randy Mackay [email protected] An: diydrones/ardupilot [email protected] CC: Crashpilot1000 [email protected] Gesendet: 7:36 Sonntag, 5.Mai 2013 Betreff: Re: [ardupilot] Minor issue: Earthconstants are inconsistent throughout the code (#203)
Thanks for this. I've replaced the AP_INERTIALNAV_LATLON_TO_CM with the Location.cpp's equivalent. c20eac7 Similarly switched to use AP_Math's longitude_scale function: 30faf87 ..and removed the unused radius_of_earth constant: ae2ad8e I agree that our conversions from lat/lon to meters or cm is not perfectly accurate because it assumes the earth is spherical when actually it bulges in the middle but I'm not sure that it will actually make much difference and I'm pretty skeptical that it's a big enough difference that it could cause circling. Still, I'd be very happy to be wrong as the circling with AC 3.0 is a real problem! If you have any other suggestions on this topic including things I've missed I'd love to hear them. — Reply to this email directly or view it on GitHub.
Little update: Hi! I worked a little bit on my code and i think i found something interesting. All the calculations/sensor read outs/slew rate produce a phaseshift of the output. By just phaseshifting the mag when resulting lat/lon - angles are put back into the bodyframe - i can reverse the circeling direction with -15deg for example, it circles CCW, or stop the circeling with a phaseshift of +10Deg. That will depend on many factors in the code but overall it is probably one thing to try out. I paste code here from my mwii/bf codechanges just for demonstration of what i mean. [CODE]
if (cfg.gps_phase == 0) { // Do Phaseshift, if wanted
CosYawxPhase = cos_yaw_x;
SinYawyPhase = sin_yaw_y;
} else {
TmpPhase = heading + (float)cfg.gps_phase; // add Phase
if (TmpPhase > 180.0f) TmpPhase = TmpPhase - 360.0f; // Wrap to -180 0 +180 Degree
else if (TmpPhase < -180.0f) TmpPhase = TmpPhase + 360.0f;
TmpPhase = TmpPhase * RADX; // Degree to RAD
CosYawxPhase = cosf(TmpPhase);
SinYawyPhase = sinf(TmpPhase);
}
if (cfg.nav_slew_rate != 0 ) {
nav_rated[LON] += constrain(wrap_18000(nav[LON] - nav_rated[LON]), -cfg.nav_slew_rate, cfg.nav_slew_rate); // TODO check this on uint8
nav_rated[LAT] += constrain(wrap_18000(nav[LAT] - nav_rated[LAT]), -cfg.nav_slew_rate, cfg.nav_slew_rate);
GPS_angle[ROLL] = (nav_rated[LON] * CosYawxPhase - nav_rated[LAT] * SinYawyPhase) / 10;
GPS_angle[PITCH] = (nav_rated[LON] * SinYawyPhase + nav_rated[LAT] * CosYawxPhase) / 10;
} else {
GPS_angle[ROLL] = (nav[LON] * CosYawxPhase - nav[LAT] * SinYawyPhase) / 10;
GPS_angle[PITCH] = (nav[LON] * SinYawyPhase + nav[LAT] * CosYawxPhase) / 10;
}
[/CODE]
Cheers Rob
P.s.: The formating of the code went crazy during paste.....
Rob, I think your compass offsets are not good. If you do the "live" calibration of the compass with the mission planner then you should be able to find a single declination value that gives you an accurate heading no matter which way you point the copter. I haven't actually verified this but it should be the case. Although the declination is different in different locations, if you stay at a single location you don't get different declinations based upon which way you face.
I think we've dealt with the majority of items raised in this issue so I'll close it. If I've missed something feel free to raise a new issue with just the missed item. thanks!