How to Use the PID() Function Like an Engineer
You've built your first XML plane. You've installed a controller to hold 181 mph. Then you watch in horror as your PID system locks the plane at 400 mph. Why?
Because the PID controller is not a cockpit instrument. It's a calculation deep inside the XML physics engine, and that engine is lying to you about its units.
If you want your speed, altitude, or angle controllers to work perfectly, you need to master three things: The Hidden Unit Conversion, The Five Coefficients (Target,Current,P, I, D), and Micro-Tuning.
The Catastrophic Unit Conversion Conspiracy
This is the number one reason every pilot fails their first PID setup. Your cockpit shows MPH, LBS, and Gallons, but the XML only works in Metric: m/s and newton.
When you tell the PID function your target speed is 181, the XML doesn't see "181 mph"; it sees "181 m/s." And 181 m/s≈405 mph
This is why your plane overshot the target by over 200 mph! It was actually flying perfectly to hit the metric target you accidentally gave it.
The Fix: Convert Your Target to m/s
Before you put any speed target into the PID() function, you MUST convert it.
Target in m/s=Target in mph×0.447
Goal Speed (MPH) : 181 mph/300 mph/700 mph
XML Target (m/s) : 80.9/134/312
The Core Structure and the Three Pillars
The PID() function has five required arguments. Think of them as the five data points your controller needs to make a decision:
PID(Target,Current,P,I,D)
Proportional Gain (P)
Response to Error Size. How hard to push based on how far off you are.
Integral Gain (I)Response to Error Duration. How hard to push based on accumulated error over time.
Derivative Gain (D)
Response to Acceleration. How hard to push to dampen quick changes.
Tuning Like a Boss: Micro-Tuning for Light Planes
This is the second critical skill. For most SimplePlanes builds, especially light or overpowered ones, your initial guess at tuning coefficients will be way too high, leading to wild oscillation (the plane constantly overshooting and rocking back and forth).
The P-Term: The Error Pusher
Job: React to the size of the error.
The Problem: In a light, overpowered plane, if you set P to a standard value (like 0.1), the controller will instantly command 100% throttle or −100% throttle for even a small speed deviation. The plane reacts too fast and overshoots, starting the cycle of oscillation.
The Fix: Go Micro-Scale! For light planes, your P value should be in the thousandths or ten-thousandths range.
Example: P=0.005
The I-Term: Killing Steady-State Error
Job: Eliminate the final, frustrating gap between your actual speed and your target (e.g., stabilizing at 179 mph instead of 181 mph). This small difference is called steady-state error. A pure PD controller will always leave this gap.
The Fix: The I term slowly accumulates the error over time and forces the throttle to creep up until the error is eliminated. It must be tiny to prevent slow oscillation.
Example: I=0.00001
The D-Term: The Smooth Dampener
Job: Look at the rate of change (rate(GS) is the acceleration) and apply a counter-force. This is your stability measure.
The Fix: This value can usually be a little higher than I, but still very small. It prevents the system from overshooting by anticipating the momentum.
Example: D=0.005 (for light aircraft(
The Optimized, Engineered Formula
By using the correct metric target and micro-tuning the coefficients, your light plane will now hold 181 mph (or 81 m/s) perfectly:
clamp(PID(81, GS, 0.005, 0.00001, 0.005), -1, 1)
Slam this code in the P51 available by default and watch it fly at perfect speed(NOTE:You still need skill to keep pitch stable 💀)
You have successfully bypassed the unit conspiracy and tamed your overpowered machine. Now go build something terrifying! 🗿🔥
the d in pid stands for hell
in the spirit of wrong equations but correct answer, I did made the max value 0.1 and it's stable, so I don't know how I should feel
oh hot! this is nice information I didn't need but happy to have.. I think I might have did my PID wrong too lmfao