Formula for calculating turn indicator (deviation from coordination)
I am stuck calculating the deviation from a coordinated curve indicator, usually the small ball in the turn indicator.


The "small ball in the turn indicator" (which pilots use to determine what they need to do with the rudder pedals in order to stay in coordinated flight) is just an inclinometer. It's literally just a heavy ball in a curved tube filled with oil.

If you want to replicate the way that the inclinometer works, then look at the lateral acceleration and vertical acceleration and use the arctan2 function to determine the apparent tilt.

By "lateral acceleration," I mean the proper acceleration in the direction of the aircraft's lateral axis, since that's what matters here and that's what you're able to sense. Likewise, by "vertical acceleration," I mean proper acceleration in the direction of the vertical axis.

The oil in the tube functions as a low-pass filter with a time constant of maybe about a second.

All that said, I don't think there's actually any reason to use the vertical acceleration. You can just take the lateral acceleration, low-pass filter it, and display the result.