The more I look into and think about this, the more I am losing hope of being able to do this well with XML. Mostly because of trim. Unless I really am missing something big here.
I have the oscillations under control to a great degree using Bjoern's code (thank you!) and it almost behaves well now. But the more I get into this autopilot development, the more I'm realizing "I can't do that with XML, etc. etc."
To try to keep things short with a simple discussion, the 747 has pitch damping, roll damping, and yaw damping values of -22, -0.4, and -0.24 respectively at low angles of attack. These numbers do not change very much with mach, and only roll damping changes very much with angle of attack. Source:
https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19730001300.pdf
The default flight simulator autopilot functions are built around airplanes that have extremely fudged numbers for these values, and as a result using the default autopilot with realistic numbers results in some heavy oscillations, especially in roll and yaw. For example, the default Boeing 737 in FS2004 has pitch damping, roll damping, and yaw damping values of -214, -4, and approx -0.83 (corrected for a bug in the FDE of FS2004). These values are 10.3, 10.0, and 2.9 times what my realistic values are for the 747, and they aren't going to change that much between one Boeing jet transport and the other. I suspect that it is these extremely fudged numbers that cause oscillations with the default autopilot if realistic numbers are used: the default autopilot is expecting these values to be much, much higher than they realistically are.
I have tested this by equipping my 747 with the default 737-400 autopilot, and adjusting the following scalars:
pitch_stability= 1.0
roll_stability= 1.0
yaw_stability= 1.0
If I set the roll and yaw scalars to as little as 3 - 5, the results are astonishing: the default autopilot almost functions without roll oscillations! The major problem then is pitch oscillation, but only at high altitude. Get this, I had to set this scalar to a whopping 9, that's right, 9! And as such, I had to adjust the aileron, elevator, and rudder effectiveness scalars to maintain controllability, but then I realized that this was also throwing off all of my other carefully tuned stability and control derivatives responsible for dihedral effect, stall and spin effects, etc. The whole thing became like flying on rails just to make the autopilot work. Unacceptable!
I tried setting the pitch and roll velocity and acceleration limits in the aircraft.cfg to many different combinations, some of which were entirely unrealistically slow to respond, but nothing I tried would make the oscillations stop, especially pitch at high altitude.
This is the reason I cannot use the default autopilot.
However, it would seem more and more that an XML autopilot will not suffice either. Just the idea of coming up with a way of setting the trim of the airplane accurately using XML and Key events sounds like a nightmare. With all of the different CGs, flap setting effects, mach effects, I just can't imagine how to do this properly, not to mention imposing the proper limits and schedules on each separate mode of the autopilot.
How well does C++ handle these sorts of things? Maybe it's time I picked up a new language...