aboutsummaryrefslogtreecommitdiff
path: root/apps/systemlib/geo/geo.c
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2012-09-29 18:00:01 +0200
committerLorenz Meier <lm@inf.ethz.ch>2012-09-29 18:00:01 +0200
commit7949ac1ad83a7a1a9128cc8333e90e12d3ce6e43 (patch)
treea097bd45b6f36e0180b9847a314d9736028dc15d /apps/systemlib/geo/geo.c
parent1725069c188fddce7e22026ca77edd5ea980b54a (diff)
downloadpx4-firmware-7949ac1ad83a7a1a9128cc8333e90e12d3ce6e43.tar.gz
px4-firmware-7949ac1ad83a7a1a9128cc8333e90e12d3ce6e43.tar.bz2
px4-firmware-7949ac1ad83a7a1a9128cc8333e90e12d3ce6e43.zip
Fixed heading calculation, fixed heading controller
Diffstat (limited to 'apps/systemlib/geo/geo.c')
-rw-r--r--apps/systemlib/geo/geo.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/apps/systemlib/geo/geo.c b/apps/systemlib/geo/geo.c
index 42d8d9c15..ce46d01cc 100644
--- a/apps/systemlib/geo/geo.c
+++ b/apps/systemlib/geo/geo.c
@@ -79,9 +79,12 @@ __EXPORT float get_bearing_to_next_waypoint(double lat_now, double lon_now, doub
/* conscious mix of double and float trig function to maximize speed and efficiency */
float theta = atan2f(sin(d_lon) * cos(lat_next_rad) , cos(lat_now_rad) * sin(lat_next_rad) - sin(lat_now_rad) * cos(lat_next_rad) * cos(d_lon));
- // XXX wrapping check is incomplete
- if (theta < 0.0f) {
- theta = theta + 2.0f * M_PI_F;
+ if (theta < M_PI_F) {
+ theta += 2.0f * M_PI_F;
+ }
+
+ if (theta > M_PI_F) {
+ theta -= 2.0f * M_PI_F;
}
return theta;