The next next question would be:
- Are you over-engineering this?
(i.e. Are you making this more complicated than it needs to be?)
The reason I ask is that this is something I do too. For example:
When working on my New Remote Camera Robot project, I needed to calculate the ratio of the wheel speeds when making a turn. Obviously, the further the joystick is moved to the right or left, the sharper the turn will be. So I decided to trot out some trig to determine the magnitude of the vectors and use the magnitude of these vectors and their sign to determine the wheel rotational velocity in either direction, for both the inside and outside wheels.
Not only did I have to deal with left and right, but also forward and backward motion while making the turn.
And what happens when the joystick crosses the “X” axis in either direction? I need to be careful there because if I am commanding full speed in one direction and suddenly change it to full speed in the other, I can damage the motors or burn up the “H”-bridge that drives them - so I have to compensate for that too.
I spent hours and hours, becoming days and days, working on refining the calculations to make them quick and easy, substituting addition and subtraction for multiplication and division - and using quick-and-dirty tricks to calculate sine, cosine and tangent, (along with the corresponding arc-functions). I even enlisted the help of my brother who has a PhD in math to critique my techniques.
It was beautiful! It was a mathematical dream come true! And I still had this nagging feeling that I was missing something. . . . I kept hearing this little voice: “Inside every large program there is a small program struggling to get out.”
So, I looked again at the axis values - I even drew a circle-chart and plotted the X-Y magnitudes for various joystick positions - and then the light-bulb went on: The best and fastest optimization for complex trig is no trig at all - in fact the fastest optimization is no math at all! (Well, a tiny bit of math.)
I discovered that I could use the absolute position of the x and y axes to determine direction, velocity, and wheel ratio with the most trivial math possible. My biggest challenges were calculating percentages and rounding to the correct precision.
I showed this to my brother and he responded with a face-palm too.
======================
Maybe you need to step back and try to find a stupidly simple way to do what you want, even if it doesn’t have the decimal precision you desire?
What say ye?