Yesterday, I made an experiment on FSP... I let it run the entire day while I was away in San Francisco for Fleet Week (cool event!, loved the low pass of the Blue Angels!). When I came back, the app had eaten around a gig of memory... (for 8 hours). Not good... It's leaking memory somewhere... even though the airplane was standing still and not doing anything (no terrain tile loading/generation).
Then I occurred to me... I needed a way to make the airplane fly on autopilot to check that the simulator can run for long periods of time, especially with the terrain system in action.
It's been almost a year since I worked on the aircraft systems in FSP.
Last time was about implementing an autopilot. I took some time trying to implement it and I got side tracked somehow... But now that I need it, I decided to look into it a little more seriously. Went back to wikipedia on the PID Controller page, and during this year time, contributors made a lot of additions to the page, including graphs and pseudo code.
I remember last year getting freaked by the formulas, and not remembering much of integrals and derivatives from school. Then after setting the problem down in terms of pseudo code, it all made sense... The pseudo code that is now on the page is similar to the one I did last year, which is pretty cool :)
Makes me think though... I remember at school being so lousy in math and wondering what the hell these derivatives and integrals could even be used for...
Perhaps:
- 1: I really sucked to begin with
- 2: It was not properly explained and lacked real world application...
If it was explained properly with real world applications, then I don't understand why I didn't get it...
There's probably a bit of both ;) BUT, I don't remember ONE single exercise that actually pointed to a REAL life example of where integrals and derivatives could be used... It was all "Exercise 1.1: calculate this. Exercise 1.2: calculate that..."
I even recall once where I asked a genuine question to my professor:
"So, what is this used for in real life? Do you have an example of something that actually uses this?".
I think thought I was being sarcastic and got all upset about it! Perhaps he didn't know any real application? Who knows...
Anyway, this is a message for everyone out there who is scared of integrals, derivatives and other signs in formulas... try to lay down the problem and remove the "I'm smart at math, check out at my formulas!" feel by typing the pseudo code and breaking the problem into smaller pieces.
Anyway, back to FSP... I integrated a small PID controller class. It works well now, but will need some tuning of Kp, Ki and Kd to function even better...
The first thing I wanted to test this with was an autopilot HDG (heading) mode to fly a certain heading and maintain it... I quickly realized that to do this, I need 2 PID's. One that will control the other one...
PID1 will be the controller that will monitor the heading and make corrections to it by controlling...
...PID2 which will be responsible for maintaining a bank angle.
It's the same for other axes:
Altitude mode, will maintain the altitude by setting another PID that will control a rate of climb.
That's going to be fun stuff! Last night, I implemented the bank angle system. Works pretty well, and useful when the plane gets out of control.
What it does is take the input values, angle, time, and calculates the output which is fed to the control axes system. So it acts like a real autopilot by moving the ailerons!
It's really fun to put the plane in unusual situations and watch the autopilot move the ailerons automatically to recover!
Tonight, I'll try to chain this to the heading controller, and my heading Autopilot will be done! :)