The focus lately has been on improving the flight model of the Cessna 150... But I also worked a bit on some refactoring in the flight model like setting individual autopilot settings for each aircraft, making the flight model editor a bit easier to use...
Tonight, I played a bit with the autopilot and I wondered if I could use this system to make a fully automated landing system... This would be kinda cool to watch the airplane land on its own... I have all the peices in place to maintain a constant speed, a rate of descent and a heading or bank angle, which are the 3 components needed for an automated landing...
I started with the basics. Figure out what the aircraft position is with regards to the glide slope and localizer. (vertical and horizontal planes on which the aircraft has to be aligned when on a proper path to landing).
I had to use a bit of simple math for that to get the console to output the correct values.
There were several steps involved:
First one was to calculate the vector that would be the ideal glide path to the runway. Having a complete internal database of the currently loaded airports, this was pretty easy. I just had to substract the positions of the runway ends to get a vector coming from the approach end of the runway and pointing away from the it at a slight angle (5 degrees).
Then, the autopilot needed the angle compared to localizer.
This was done by calculating the dot product of the glide slope vector and another vector that comes from a substraction of the aircraft position and the runway threshold.
Then, to figure out if the angle is negative or positive, the trick is to compute the cross product of the same two vectors and then the dot product the resulting vector and another reference vector (the Up vector in this case). The sign of this dot product tells us if the calculated angle is positive of negative.
Of course, the two first vectors needed to be flattened to the ground (y = 0) so that the initial dot product only returned the angle on the horizontal plane...
Once this angle was computed, the next step was to compute the same but for the altitude difference between the ideal glide path and the current glide path of the airplane...
This one was a little trickier... Like the first one, I needed to "flatten" the vectors so that the angle would be accurately calculated and only the vertical difference in the vectors would be calculated by the dot product. The tricky part is that for this one, since the glidepath vector can have any direction I couldn't just set one of the components to 0.
The solution was to project the aircraft position on a vertical plane formed by the glide slope. Once projected this point could be used to compute the dot product between the glide path and the vector from the runway threshold to the "flattened" aircraft position. Same trick of the additional cross/dot is used to figure out the sign of the angle.
So these vector maths gave me 2 values. The localizer angle difference and the glide slope angle difference...
The next step was to plug in a couple of those PID Controllers I mentionned in a previous blog post. The autopilot had the following PID Controllers available at the time:
The two new ones I added are:
The first controller takes care of the vertical control. Its job is to adjust the rate of descent by feeding the ClimbRateController the appropriate values.
The second controller is in charge of the horizontal alignement with the runway by controlling how much bank angle should be applied on the airplane. It does this by feeding resulting values to the BankAngleController.
For this approach mode, I enabled an additional controller, the Speed Controller so I could leave the controls and let the aircraft fly on its own :)
Tweaking the controllers took a bit of flying to figure out the appropriate constants. I included the KML of the tweaking session so you can whitness the difference between the first sketchy approaches and the almost "perfect" ones:)
Two things I'm unsure about the current system:
-
I'm not certain the current angle based difference is good for the localizer. Perhaps a distance based would be better. (distance from the aircraft's position to its projected position on the glide plane)
-
I need to figure out a way to get closer to the runway with the autopilot on. In the video, I disconnected the AP just before reaching the pond on final as the airplane was starting to overcorrect violently. This is expected as when the aircraft gets closer to the runway, slight corrections of trajectory result in much bigger angle differences. This is why, at least for the localizer part as I mentionned above, a distance based technique might be better as oppposed to an angle based approach. When close to the runway threshold, the distance from the localizer path will vary much less than the angle...
I'll try that tomorrow...
Meanwhile, here are the videos/screenshots:
This one shows the Cessna 150 on the approach path. The autopilot is triggered just a few seconds after the video starts. Here is the KML file of this video with annotations. Controls are clearly visible in this video. They are a bit jittery... I'll try to fix this... But it shows that the controller actually controls the aircraft surfaces.
Here's another one with a practice landing as dusk... This video includes a great cockpit view with instruments and moving yoke/rudder pedals...
One last, completely unrelated... a Cessna 150 taking off :)
Notice in these following screenshots that I have added the possibility to load my GPS Tracker paths for playback in FSP.