From f4f784a5144169bbf2ec16c11c00dbb1630fe71f Mon Sep 17 00:00:00 2001
From: torsten <torsten>
Date: Wed, 10 Mar 2010 21:02:57 +0000
Subject: [PATCH] Added anti windup for the pi-simple-controller

---
 src/Autopilot/xmlauto.cxx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx
index 43ec22139..9875ba524 100644
--- a/src/Autopilot/xmlauto.cxx
+++ b/src/Autopilot/xmlauto.cxx
@@ -619,12 +619,15 @@ void FGPISimpleController::update( double dt ) {
         int_sum += error * Ki.get_value() * dt;
 
 
+        double output = prop_comp + int_sum;
+        double clamped_output = clamp( output );
+        if( output != clamped_output ) // anti-windup
+          int_sum = clamped_output - prop_comp;
+
         if ( debug ) cout << "prop_comp = " << prop_comp
                           << " int_sum = " << int_sum << endl;
 
-        double output = prop_comp + int_sum;
-        output = clamp( output );
-        set_output_value( output );
+        set_output_value( clamped_output );
         if ( debug ) cout << "output = " << output << endl;
     }
 }