PID (General Purpose)

Health
 Armour Class
 Structural
 Weight
 Relative Buoyancy
 Size
 Material Cost | 40

The **General Purpose PID** (proportional integral derivative) controller can provide finer automation control than an Automated Control Block. The end result is dependent on how the PID is set **and** the way propulsion components are programmed to react to commands.

## Stats

* EMP susceptibility 60%. Protective drainage 10 damage units.

## Variables

PIDs control movement based on an input by sending out an output based on gain, integral, and derivative. While an AI PID will try to match the input, i.e. the vehicle's current state, to what it wants it to be, a general purpose PID will try to set it to 0 or whatever you program it for. This value is usually referred to as fake set point.

The actual output to movement will depend on the difference between the current state of the vehicle and the target.

**Gain:** this is a percentage of the difference between the current state and the target state of the vehicle. Higher numbers will cause the PID to react strongly to being off target.

**Integral:** this determines how quickly gain will scale if your vehicle is off target for a certain amount of time. The lower this is set, the quicker the gain will increase and decrease. 250 completely disables this function.

**Derivative:** this is a window of time during which the PID records everything happening to the vehicle on the selected axis. The PID will use this window to predict future changes and compensate for them ahead of time. If set to 0, the PID will have no way to predict changes and will be prone to overshoot and wobble. Typical values are between 0 and 1. Higher values can help compensate for regular disturbances such as recoil, but also creates a risk that the PID will try to compensate for errors that are not regular and cause more instability overall.

## Tuning

While general purpose PIDs can also be created in the breadboard, only physical copies will have a graphic interface showing you useful information for tuning. As such, it is recommended to use the physical block for tuning and moving to a breadboard PID later for best results.

First, you will need to set which input it will listen to. This should correspond to what output, i.e. which axis, you want the PID to control. For instance, for roll stability, the PID should be set to listen to roll and output to propulsion roll. An altitude PID may listen to different categories of altitude and output to propulsion vertical or hover. Then, you need to choose the fake set point. For stability, 0 is usually the target for roll and pitch, but altitude will often be something other than zero. Note that ACBs and breadboards allow you to change your fake set point to adapt to different environments, avoid terrain, or make your vehicle more evasive.

**Step one:** disable integral by setting it to 250.

**Step two:** lower gain to 0 and increase it slowly until your vehicle is able to maintain the target angle or reach target altitude (red and green line mostly overlap).

**Step three:** increase gain a bit more until there is a small amount of wobble (blue line jagged, going up and down) and then divide the gain by half.

**Step four:** make sure you have an appropriate derivative (between 0 and 1 unless you know what you are doing).

**Step five:** set integral to 0 and increase it until your vehicle is stable (red and green line mostly overlap).

This method is not a guarantee that you will get the desired result, but it is quite reliable.

Generally speaking, if you have a lot of extra thrust available, your gain should be relatively low and vice-versa. If your vehicle is at risk of having big instability issues due, for example, to high recoil or damaged thrust on flying vehicles, setting integral low will cause the PID to react quickly.

## Troubleshooting

Sometimes, PIDs will not yield the expected results. Here are some things to try if the vehicle is not behaving the way you expected:

1. Always make sure your propulsion is adequate, that you have enough engine power and fuel for those engines for propulsion to function, and that the AI is not fighting your outputs. You can disable an AI's control over an axis by going into the AI's menu, under the PID tab, and setting the relevant PID's type from "PID" to "none". This does not require a connected AI PID.

2. Try adding extra thrust to the axis you are trying to control to see if you have sufficient thrust. This likely your problem if the PID's graphic mentions "output saturated".

3. If all else fails, try using an integral of 250.