2.1 AI Tuning - BrettRyland/BDArmory GitHub Wiki

AI tuning is one of the most challenging, and one of the most important aspects of BDA. How well you configure the AI will determine how well it performs. That said, a perfectly tuned AI is limited by the airframe it is mounted on. While a poor AI on a good plane may do better than a good AI on a poor plane, at the end of the day the best performing AI is one that is tuned to match the capabilities of the craft it is mounted on. While the default AI is functional, and designed to be able to fly pretty much anything, as a universal 'jack-of-all-trades' tune, it probably won't fly any particular vessel well, but it will at least fly it adequately. Getting the most out a craft will require tuning the AI.

The AI can be tuned in one of two ways, either by right-clicking on the AI part and setting the values directly in the Part Action Window, or by hitting the AI GUI hotkey, [by default, Keypad /], which brings up the AU GUI. If enabled, you can also click the BDA AI button on the toolbar to also open the AI GUI. Both the PAW and GUI contain the same information and settings, but the GUI does have a larger window, and integrated help options, which can be accessed by clicking the [?] button (to bring up context tips for the various sliders and settings) or the [i] button, which opens up an attached info codex with brief explanations of what each setting does.

The AI GUI, with info link enabled

The AI is divided up into 8 subsections:

[PID Control]

PID, or Proportional Integral Derivative, is the Motor Cortex of the AI's 'brain', so to speak; it controls how well the AI steers and aims the craft, using a standard PID controller, for which tutorials and instructional videos on how PIDs work can be found around the internet for an in-depth look. A basic overview is the PID looks at the difference between where the craft is currently pointing, and where it needs to point, and applies corrections and damps to the control input to ensure the craft starts to point in the desired direction. Tuning involves adjsuting all three values until desired results are achieved.

Animated PID demo, source: wikipedia

The First is P, or Steer Power. This sets the magnitude of control input the AI will try to use, basically how aggressively the AI is steering. A low setting will have the AI will be gentle, using less that the full control authority available to the craft. A high setting will see the AI sharply jerk the craft towards a hew heading; the end effect of this is a craft that will undershoot its destination, and need to spend more time applying input to arrive to where it wants to be, or overshoot, and need to spend time compensating to bring the craft back on target. An ideal P is one where the AI smoothly arrives at the desired input with the minimum of excess input. The second value is I, or Steer Correction. This is the error correction applied to fix accumulated error from the P and D settings. Too little, and the AI will undershoot the desired heading, too much, and the AI will have much greater control oscillations to damp out. Lastly, D, or Steer Damp. This sets how much damping the PID will apply to the craft's steering. As I increases, the amount of Damping required generally also increases, but again, it is a balancing act. A low Damping score will apply much less damping to any oscillations induced by P and I, increasing the time it takes for the AI to fully come on target. A high value will quickly damp out oscillations, but at the cost of overall sluggishness in control, as the damping will be slowing how much control input is ultimately being applied.

The basic PID sliders provide 3-axis control for Pitch/Yaw/Roll, in a linear fashion. Enabling the [Dynamic Damping] will have the AI dynamically adjust Damping, from the min damping value to the max damping value, based on angle to target. The lower the value, the more linear the dynamic damping value as target angle changes, the higher the value, the more damping will be reduced when pointing away from a target, and increased when pointing near a target. This applies to all three control axes. For individual control Axis damping, enable the relevant Pitch/Roll/Yaw Dynamic Damping.

[Altitudes]

The Altitude settings control and constrain the desired flight envelope of the craft. Default Altitude is the altitude the AI will seek to reach and maintain during non-combat cruising. Minimum Altitude sets the minimum combat altitude. Below this, and the AI will begin checking terrain distance to see if it needs to break of what it is doing and [Gain Altitude] instead to prevent crashing into the ground - it will not be friends with you. The [Max Altitude(AGL)] button will enable setting a maximum altitude. If enabled, Maximum Altitude sets the max altitude the AI will attempt to respect. Do note, this is not a hard clamp that the AI will never exceed; the AI will merely attempt to stay below it, but some circumstances - e.g. a vertical climb to chase or close distance with a target - may cause the AI to overshoot the Max Altitude.

[Speeds]

Speed settings control how fast the AI should seek to go, under various conditions. Max Speed is the maximum speed, in meters/sec, the AI will attempt to reach, and if exceeded, the AI will brake to bring craft velocity to less than or equal to this value. Take-Off Speed is how fast the vessel needs to be moving before the AI will begin pitching up to takeoff, if landed. Min Combat Speed is the lowest airspeed that the AI will execute combat maneuvers. Below this speed, the AI will break off and extend until craft velocity is equal to ore greater than this value. Strafing Speed is used for attacking ground targets, and will tell the AI to fly at a speed equal to Strafing Speed + ground target velocity when conducting an attack run. Idle Speed is non-cruising speed the AI will maintain when not in combat.

[Control]

Control settings allow setting limits on control inputs by the AI to the craft. Low-Speed Limiter and high-Speed Limiter are settings that multiply the level of control input the craft will use. A value of 1 will grant full input, a value of 0.5 will clamp control inputs of 50% of full deflection, etc. The low Limiter Speed and High Limiter Speed set the speeds at which the above limits are applied to the craft. Below the Low speed limit, the Low Speed Limiter will clamp inputs. Above the Low Speed limit, but below the High Speed Limit, control limit will linearly interpolate from the Low Limit to the High Limit. Above the High-Speed Limit, the High-Speed Limit is applied. The bank Angle Limit limits the extent the AI will attempt to Roll the craft during maneuvers. A setting on 180 will apply no limit, and the AI is free to continuously Aileron Roll to its heart's content. Max G will reduce control input to bring G-Forces exerted on the craft by maneuvers below the limit. Max AoA will attempt to prevent the AI from pitching the craft beyond the set Angle of Attack.

[Evasion/Energy]

Evasion/Avoidance (in the PAW) or Energy (in the GUI) controls how the AI responds to incoming fire, incoming craft, and when to extend. The first four settings control when and how the AI will attempt to dodge incoming fire. Min Evasion Time is how long, in seconds, the AI will perform evasive maneuvers to dodge enemy fire once Evasion is triggered. Evasion Distance is how close, in meters, the incoming fire has to get to the craft before the AI will regard the craft as in danger and under fire. Evasion Threshold is how long the AI needs to be under fire before it begins evasion. lastly, the [Don't Evade my Target] button toggles if the AI will attempt to evade fire coming from its target or not, which can be used to allow not breaking prematurely during closing jousts, but otherwise attempt to avoid enemy fire.

The next trio of settings control how the AI reacts to incoming craft to avoid collision. Craft Avoid Range sets the threshold distance, in meters, for oncoming craft. Craft Avoid Look-Ahead sets how often, in seconds, the AI should 'look ahead' to predict oncoming collisions. If another craft is predicted to enter the Avoid Range radius in the next Look Ahead period, then the AI will attempt to evade out of the way. Craft Avoid Strength sets how aggressively the AI will try to change vector to dodge the other craft.

Standoff Distance sets how close or how far, in meters, the AI should try to stay away from the craft it is targeting. Setting it to 0 will cause the AI to ignore how close it gets to an enemy craft while engaging; setting it above zero will cause the AI to try and stay on the target craft's tail at the set distance.

Extend Multiplier modifies the Extend range the AI will fly while extending, if Extending is enabled, from the AI's default range of 300m. The three Target... settings control when the AI should attempt to extend based on the position of another craft and the AI's maneuverability. To Extend, the AI first projects a detection cone of a set length and width, and then looks it see if the target craft is outside this cone, and moving at the indicated velocity. The Default settings of 78 deg, 400m, and vel factor of 0.8 mean that the AI will attempt to extend if its target is outside this 78 degree detection cone, is closer than 400m, and moving less than 0.8x the AI's current velocity Target Velocity Factor tells the AI at what point it should consider extending, based on the relative velocities of the AI and the target. A value below one indicates a craft moving slower than the AI, greater than one, faster. Target Angle sets how widely ahead the AI should look ahead, as sort of an inverse Field-of-View, and should be set based on craft turn radius. The better the turn radius, the higher this value can be, as a more agile craft can turn to engage targets further off-prograde than a less agile one Target Distance sets how close a target must be, in meters, before the AI will break off and extend to get a better angle instead of getting locked in a turnfight. Finally, the [Extend] Toggle toggles whether or not the AI should seek to extend under appropriate circumstances.

[Terrain Avoidance]

The Terrain Avoidance values are important, if easily overlooked, settings. These settings control when and how the AI will break off all other maneuvers to pull up if the AI is too low and needs to avoid crashing into terrain. While this behavior is also controlled to some extent via the Min Altitude setting, Terrain Avoidance takes into account the vessel's current turning radius, orientation and control surface deployment time. Terrain Avoidance Tuning Min sets the modifier to pulling up based on the craft being level with the ground. Terrain Avoidance Tuning Max is the multiplier the AI applies based on the craft being inverted; how long it takes for the AI to roll from an upside-down orientation before pitching up. Inverted Terrain Avoidance Critical Angle is the craft's roll angle relative to the terrain normal beyond which the craft will try to avoid terrain while inverted. (E.g., a craft that pitches down poorly, or can roll upright in the blink of an eye, would set this close to 180°, while a plane that pitches up or down equally well might set this closer to 90°.) Control Surface Deploy Time is an estimate of the time taken for control surfaces to go from one extreme to the other, during which the craft has travelled forward without turning significantly. The AI looks at these values when approaching terrain, to know when it should start terrain avoidance behavior to avoid crashing. An explanation of how the various factors affect the terrain avoidance threat distance can be seen in this diagram: Terrain Threat Distance explained Waypoint Terrain Avoidance affects the range and strength of adjustments to the fly-to direction of craft running waypoints due to terrain being between the craft and the current waypoint.

[Ramming]

If all else fails, if the craft has lost all its weapons or run out of ammunition, it will, if enabled, attempt to ram other craft as a last-ditch attack. If disabled, the craft will instead revert to [Orbiting], and cruise in a circle around the battlespace. The Control Surface Lag setting adjusts how much of a lag the AI applies to adjust for control surfaces not possessing instantaneous deflection, when calculating an intercept to ram another craft.

The Misc. Button in the GUI holds the Orbit Direction And Standby Mode settings. Orbit Direction controls what direction the craft orbits while waiting for a competition to begin, when disarmed and Ramming is disabled, or there are no enemy targets within the AI's detection radius. Standby Mode sets if the AI should be active and immediately take off, or if the AI should wait until a craft on a different team enters its detection radius to start engines and takeoff.

The [Clamped] button sets toggles the maximum values for most of the AI values from default (clamped) to much higher, unclamped values.

Finally, the [Save] button in the upper Left on the GUI, or near the bottom of the PAW, will save the current AI settings and tune for the craft, allowing a user to tune a craft in flight, save, then revert to the SPH/VAB. There, the [Save] button will be joined by a [Restore] button to load the saved values, allowing them to be saved with the craft.