Closed GoogleCodeExporter closed 8 years ago
Correct cos(62.762 degrees) should be about 0.45988
The corrected code above gives value 0.47, and this is same as cos(62 degrees)
How to change code to get correct values?
Original comment by alpo.has...@gmail.com
on 3 Jul 2011 at 4:18
One more typical route. Curves are in the same places.
Original comment by alpo.has...@gmail.com
on 3 Jul 2011 at 4:51
In the code line, is the abs really needed?
Cos in the 0 degrees (= equator) is 1, and then it reduces to both directions,
and is 0 in the poles. Cos is always positive between poles.
Also Arduino manual says:
Warning
Because of the way the abs() function is implemented, avoid using other
functions inside the brackets, it may lead to incorrect results.
abs(a++); // avoid this - yields incorrect results
a++; // use this instead -
abs(a); // keep other math outside the function
Is it wise to check all APM codes?
I tested the following simple line:
float rads = next_WP.lat / t7 * 0.0174532925;
Now the flight seems much better: the green line points correctly to next
waypoint. Today was 4-6 m/s wind from north-east, and going to that direction
is not yet very good. Now I must adjust those PIDs.
Original comment by alpo.has...@gmail.com
on 4 Jul 2011 at 5:08
alpo.has...
Thank you for the bug report. You correctly identified the location of the
bug. Your proposed fix would not work in the southern hemisphere... The root
cause was the use of the integer abs() function instead of the floating point
fabs() function.
Bug fix has been uploaded to both the trunk and the branch.
Original comment by dewei...@gmail.com
on 5 Jul 2011 at 7:45
Thank for the fix. It is now ok.
But I still don't agree that southern hemisphere :-)
I have code only for the latest version in Downloads section, 2.20
Local variable rads is used only in two lines.
If your latitude is for example -45.678, it is in radians -0.797, so
rads = -0.797
Then you calculate two global variables from that value. These are used in
other subroutines:
scaleLongDown = cos(-0.797) = 0.6988, so it is positive.
scaleLongUp = 1.0f/cos(-0.797) = 1.43, so it is also positive
Same variables in northern hemisphere:
rads = 0.797
scaleLongDown = cos(0.797) = 0.6988, so it is positive.
scaleLongUp = 1.0f/cos(0.797) = 1.43, so it is also positive
So both are positive in northern and southern hemisphere. Is fabs() really
needed? Of course it is not an error, it can be there.
And here is the log from todays flight. Now everything seems as it should be :-)
Original comment by alpo.has...@gmail.com
on 6 Jul 2011 at 7:04
Original issue reported on code.google.com by
alpo.has...@gmail.com
on 3 Jul 2011 at 2:41