Jump to content
Sign in to follow this  
bcs112

PID controller driving me crazy, any hints ?

Recommended Posts

Hi all,I've been using and abusing in many cases the FS autopilot system for years but with FSX the vertical stability of aircraft at low speed and in 25-30


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Did you try tuning it using any of the methods in their tuning tips section? If so, what problems did you encounter?People will be able to help you more if you tell us what you tried, and how it failed.

Share this post


Link to post
Share on other sites

Hi again,First question: does this PID controller equation actually work for anyone or is here a better formula ?According to the abovementionned website one should tweak the PID controller based on Kp, Td and Ti. This is my basic set-up for an IAS (FL CH in Boeing speak) function using the vertical speed mode of the FS autopilot. The alt_set_target value is fed into the FS autopilot vertical speed setting.double ac_vs = VERTICAL_SPEEDvar.var_value.n/256*60/0.305;if ( ias_exp && sim_pause == 0 ){ VSPDController->Kp = Kp_exp; VSPDController->beta = 1.0; VSPDController->alpha = 0.1; VSPDController->gamma = 0.0; VSPDController->Ti = Ti_exp; VSPDController->Td = Td_exp; VSPDController->u_min = -5000; VSPDController->u_max = 5000; VSPDController->TargetValue = ap_target_spd *-1; VSPDController->CurrentValue = AIRSPEEDvar.var_value.n *-1; VSPDController->PreviousOutputValue = ac_vs ; VSPDController->Update(1); alt_set_target = VSPDController->OutputValue;}I start by setting Kp to 1 and Ti to 15, this results in a very slow reacting controller fluctuating around the set value. I then start increasing Kp, which results in a more explicit reaction (bigger VSPD steps) and reducing Ti for a snappier response until I get something slow but usable to start.The biggest issue is that I always get overshoots from the set speed, and these don't decrease. So there is a lack of predictive value in the system. I then slowly increase Td but that doesn't seem to make the system more stable.So how do I increase the predictive value of the system ? Are there any trick to make the system more stable ? The reaction time of the pitch in my aircraft is relatively slow but this is like the real aircraft (Airbus 300) which is quite heavy. So the system should be able to handle a relatively large lag.Bj


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites

Hi Bjoern,I'd say the problem is that your controller is trying to control the aircraft indirectly through another controller (Microsoft's autopilot). So a) you're introducing extra latency into the system (in effect, you're "twice removed" from the variable you want to control) and :( you're pretty much at the mercy of how well that second controller (in this case, Microsoft's autopilot) is doing its job...So I would suggest that instead of letting your controller act on the vertical speed setting of the autopilot, you let it act directly on the elevator... that should make the behaviour of your controller more predictable.HTH,Martin

Share this post


Link to post
Share on other sites

Hi,As Martin stated, you can't use vertical speed as the controller, because it is in fact a result obtained from other physical inputs, and in consequence it's very imperfect, has lag noise, etc (surely you've heard the famous phrase "Don't try to chase the VS needle!")Instead, try to use two phases:Airspeed vs Pitch Attitude (AoA or similar)Pitch Attitude vs Elevator TrimThe goal is to obtain proper elevator trim values to maintain a target airspeed. In this case, use vertical speed bounds as a limiter variable.Tom

Share this post


Link to post
Share on other sites

Hi,Yes I agree using VSPD is not the best method, but I tried using elevator trim and elevator directly. I always get the same problems, the formula doesn't correct quicky enough when for instance the target speed is reached (derivate function).Hence my question if this is the best formula or if anyone knows of a better one. I will do some more tests though and hopefully find a better solution.Bj


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites

Bjoern,PID cotrollers are pretty much the standard method for building autopilots... so they should definitely be up to the job.Not that I have any practical experience with autopilots (I've been thinking of getting my hands wet for a while, though), but it sounds as if your gains need some tuning. Specifically, if the controller doesn't correct quickly enough when the target speed is reached, it sounds as if the gain for your "I" component is set too high relative to the "P" component. Also, to simplify things, you could try starting out with just a PI controller, then when you've got that working, add in the "D" component if needed for some fine-tuning.Martin

Share this post


Link to post
Share on other sites

Just a thought, but perhaps 18Hz is too slow an update rate?Maybe moving the code out of the panel callback and having a WinTimer trigger the PID at some faster rate, perhaps 60Hz might help?


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

A "short" update on my progress so far...Lost many hous of sleep on this one ;) But I seem to have been able to create a stable VSPD controller now, albeit that in moderate turbulence it doesn't work well. I know real life VSPD doesn't work well in turbulent situations but its not good enough.Anyway, what I have done to get a good result is:- Use the elevator trim (not the elevator itself since this is also not done in real life) to set the aircraft pitch- Use a first PID controller to set the vertical speed based on current vertical speed and set speed => as discussed before this results in a very unstable controller that is always overshooting the set speed- I created a second PID controller that uses set vertical speed as the target and projected vertical speed as the current value. ==> The projected vertical speed is the current vertical speed + the delta (change) in vertical speed since the last check. I check the vertical speed 3 times per second now (in fact every 300ms). I calculate the vertical speed in about 4 seconds and use that in the second PID algorithm.- If the sign (+ or -) of the PID output based on the current VSPD is the same as the sign of the PID controller using projected VSPD than I use the current PID output, if the sign of the projected VSPD controller is opposit than I use the output of the other PID controller. I think this is called "feed forward". The problem is off course that in very turbulent conditions the feed forward principle tends to disable the VSPD controller since the rapid fluctuations will trigger the second PID controller output... so I need to take a look at that.- Finally I add a third P-only-controller that takes the (change in) bank angle and the actual bankangle into consideration. If the bank angle increases the VSPD is increased proportionaly (hence P-controller), if the bank angle decreases than I do the opposit. I possibly need to use a third PID controller for this but at first sight the results using a simple proportionate controller seem to be sufficiant. More testing needs to be done though. Since the g-force is proportionate to the square of the angle I possibly will need to use that also somewhere, but FS is not the real world so I'm not sure if this is modelled correctly in FS to start with.Bj


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...