that is pure empirism.
the fact is: i noticed that, given the final value of the pid ("pid" in this case), driving the motors with it linearly was good for small values, but was to low for big values (that is, when the robot is very tilted).
So i tought about using an exponential function, that is using pid^2 instead of pid, so that it grew a lot more as the values gets bigger.
The problem is that i'm working with signed values, and the square of a value is always positive. So i multiply the square with the "sgn" function to restore the original sign.
Another problem was that the resulting value was too big, so i scaled down it with random values, ending up with a 18 that suited my needs. Your mileage WILL vary ![]()
I suggest you to skip the line and simply use the "pid" value (almost) directly for the first test, and then eventually play with it as i did.