   Controlling physically based aircraft.
  Hi all,I'm trying to write an autopilot controller for a physically-based aircraft.  I'm having some success with simple correction mechanisms for roll, and some not so good results for pitch control (esp in turns).I'm using a simple PID controller (2nd order, as described in AI wisdom 2) as simple correction caused bad 'bounce'.My current passable pitch error metric is a weighted sum of vertical velocity and altitude difference:float error = (-0.1f * Velocity().y) + (mRequiredAltitude - WorldPos().y) * 0.15f;This works ok if you engage autopilot when quite level, but has extreme trouble with other initial conditions.There seems to be quite a large 'solution space' for the combined error metric and PID coefficients. I wondered if anyone has any experience of controlling physically based aircraft, maybe give a few pointers (or even a new approach ;))?cheers,Aph   
  I don't have much experience with PID controllers, but from what I understand considerable effort is spent in tuning each of the parameters. There are specific methods to tune the system to work out a trade-off between how fast to converge towards a steady-state, stability and minimising oscillations, and reducing the error. I'm sure someone has more documentations relating to those controllers, I remember seeing a few very good articles on the web. Wikipedia as some good stuff, and this too.   ;  Nice link ta Oli (2nd on Google, how did I miss that one?!)Looks like PID tuning is quite big business looking at the Google ads :o;  It's really important if you need help with a control type problem to give the model (or a reference to the model) that you're going to be using. Depending on how realistic you need the responses to be it's probably also mentioning what flight conditions you're operating through (velocities and angles of attack). If you get really stuck Timkin in the AI forum is a bit of a guru with this type of thing (he works on unmanned aircraft).   ;  Thanks Andrew.My model consists of a number of 'fluid samples' placed around the aircraft that create lift/drag etc (forces applied to a rigid body via a 3rd party physics engine).  The PID output is used to fake input to the aircraft (at this stage mouse up & down deltas) which in turn rotate the fluid sample orientation to affect pitch.Thinking about it I suppose another possibility is connecting the PID output directly to the surface rotation... increasing the solution space even more ;)   ;  In my glider sim I do the following:1. Work out where I want the plane to go - up, down, turn left/right etc.2. From these use a simple heuristic to calculate the desired roll/pitch angles - and clamp the values.3. Assign control surface inputs to make the plane reach the roll/pitch angles.The parameters set up for one aircraft seem to work surprisingly well even for aircraft that have very different properties.I used a similar method to create a helicopter controller for player control (would work for AI too) - based on the idea that if the player presses "w" (for conventional wasd control) then what they really want to do is go "forward". This then sets the desired speed, and that implies the desired heli pitch, and that implies the actual control surface parameters.You can look at my source code here. The relevant source code files will contain "robot" in the name, and there are "robot" parameter files too.Edit: The point of the above method is that it will prevent pitch/roll "overshoot" and thus instability so long as the aircraft hasn't got too much rotational "inertia" (either real moment of inertia, or lag in the controls etc).   ;  lol - what a coincidence... I remember someone here linking their glider sim page a while back but I couldn't remember who/when/where, and there it is!Ta muchly, I'll take a closer look :);  Having been asked to take a look at this thread, here are my thoughts...In designing a controller you need to consider the dynamics of the system you're trying to control. The principal role of any controller is to add sufficient damping to a system to ensure that it is stable about a given set-point (the target state) when subject to perturbations. In the case of an aircraft, this is a particular trim state, such as straight and level at constant velocity, a constant angular rate turn at constant altitude, an equilibrium climb at max/min power or max/min rate, etc. A change in set-point should result in a smooth transition with predictable performance to the new equilibrium point.If your autopilot is having trouble converging the state to the desired set-point, then it simply isn't a stable closed loop system. You might also be experiencing a phugoid motion in your pitch dynamics. You should read up on the main modes of aircraft dynamics (phugoid, short-period, dutch roll and spiral divergence) so that you understand what the natural motions are.An autopilot controller is most easily designed if you have access to either a state space model of the system or a transfer function representing the system dynamics (but by 'most easy', I don't mean trivially... autopilot design is a difficult task to get right). If you don't have either of these models, then data-driven design can be attempted, but you'll be in need of some decent software to assist in the process (such as Matlab). Even then, doing either of the former methods is best attempted with some good analysis software.Just a couple of questions...Are you simulating control surface deflections for generating moments, or just setting the angular rates directly from user inputs?Are you simulating side-slip effects on the fin?How many degrees of freedom in your flight model?Cheers,Timkin   ;  Thanks Timkin.  Some more things for me to read up on.Quick answers:Using surface deflections.I think side-slip is simulated (not sure on terminology).  There will be increased drag when going sideways.3 DoF.   