NOTE: I am relatively unfamiliar with Robot C, I have one season of coaching BEST worth of experience with it. Please check that my assumptions are correct. The first bit might not actually be an issue…

There may be a bug hiding in this line:

float ratio = ((joyVal * joyVal) / (16129));

If Robot C handles casting like C does, the actual math will be done in integer math, and then cast to a float at the end. Follow it through the parenthesis to find this:

- float ratio = ((joyVal * joyVal) / (16129));
- float ratio = float ((int * int) / (const int));
- float ratio = float (int / const int);
- float ratio = float (int);

In the 3rd step, dividing an int by a const int will truncate to an int. When it is cast to a float in the 4th step, the information is already lost. It is likely that this doesn’t really matter, but it makes for a confusing read.

I’d recommend replacing the line with

float ratio = ((joyVal * joyVal) / (16129.0));

Now you are dividing an int by a const float, which will be done in floating point math.

Do you want to rescale the sticks so that full forward on the stick is 60%, and everything in between is rescaled? Or, do you just want to chop off the top of the sticks so that anything above 60 is limited to 60?

Rescale:

The key to rescaling is to find center of your range, pull it to zero, do your scaling, and then push it back to the real center. Then, shuffle your math around until it looks good for a computer.

For example, lets rescale around 127:

recentered = input - 127;

scaled = recentered * ratio;

output = scaled + 127;

Put it all on one line:

output = (input-127) * ratio + 127;

If ratio is a floating point number between 0 and 1, you are done. If you want to rephrase it as your new maximum value, write it like this:

output = (input-127) * max_value / 127.0 + 127;

You can likely leave off the “.0” from “127.0”. Just be sure you follow the golden rule of integer division: Multiply, then divide. Going the other way around kills your accuracy.

PS/EDIT: I’m confused as to your goal still. Could you please draw a graph of what you want to do, with “input from the joystick” on the x axis and “output to the motors” on the y axis? You can sketch it in mspaint or whatever, just label a few key spots.