From ea8acd664fad4d561a7ea744b3a24a1c68b6e942 Mon Sep 17 00:00:00 2001 From: jasonshort Date: Sun, 6 Feb 2011 07:02:51 +0000 Subject: [PATCH] fixed inverted cos error git-svn-id: https://arducopter.googlecode.com/svn/trunk@1597 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- ArduCopterMega/navigation.pde | 37 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/ArduCopterMega/navigation.pde b/ArduCopterMega/navigation.pde index 52b912ccee..1af23e1bf1 100644 --- a/ArduCopterMega/navigation.pde +++ b/ArduCopterMega/navigation.pde @@ -41,9 +41,12 @@ void navigate() update_navigation(); } -#define DIST_ERROR_MAX 3000 +#define DIST_ERROR_MAX 1800 void calc_nav() { + Vector2f yawvector; + long long_error, lat_error; + /* Becuase we are using lat and lon to do our distance errors here's a quick chart: 100 = 1m @@ -51,25 +54,33 @@ void calc_nav() 3000 = 33m 10000 = 111m pitch_max = 22° (2200) - */ - - Vector2f yawvector; - Matrix3f temp = dcm.get_dcm_matrix(); + */ - yawvector.x = temp.a.x; - yawvector.y = temp.b.x; + Matrix3f temp = dcm.get_dcm_matrix(); + yawvector.x = temp.a.x; // sin + yawvector.y = temp.b.x; // cos yawvector.normalize(); + yawvector.y = -yawvector.y; + //cos = + long_error = (float)(next_WP.lng - current_loc.lng) * scaleLongDown; + lat_error = next_WP.lat - current_loc.lat; + + long_error = constrain(long_error, -DIST_ERROR_MAX, DIST_ERROR_MAX); // +- 20m max error + lat_error = constrain(lat_error, -DIST_ERROR_MAX, DIST_ERROR_MAX); // +- 20m max error + // ROLL - nav_lon = pid_nav_lon.get_pid((long)((float)(next_WP.lng - GPS.longitude) * scaleLongDown), dTnav, 1.0); - nav_lon = constrain(nav_lon, -DIST_ERROR_MAX, DIST_ERROR_MAX); // Limit max command + nav_lon = long_error * pid_nav_lon.kP(); + //nav_lon = pid_nav_lon.get_pid(long_error, dTnav2, 1.0); + //nav_lon = constrain(nav_lon, -DIST_ERROR_MAX, DIST_ERROR_MAX); // Limit max command // PITCH - nav_lat = pid_nav_lat.get_pid(next_WP.lat - GPS.latitude, dTnav, 1.0); - nav_lat = constrain(nav_lat, -DIST_ERROR_MAX, DIST_ERROR_MAX); // Limit max command + //nav_lat = pid_nav_lat.get_pid(lat_error, dTnav2, 1.0); + nav_lat = lat_error * pid_nav_lat.kP(); + //nav_lat = constrain(nav_lat, -DIST_ERROR_MAX, DIST_ERROR_MAX); // Limit max command - // rotate the vector - nav_roll = (float)nav_lon * yawvector.x + (float)nav_lat * yawvector.y; + // rotate the vector + nav_roll = (float)nav_lon * yawvector.x - (float)nav_lat * yawvector.y; nav_pitch = (float)nav_lat * yawvector.x + (float)nav_lon * yawvector.y; //Serial.printf("vx %4.4f,vy %4.4f ", yawvector.x, yawvector.y);