Let’s see, the joystick is +/- 127.
127^3 is 2,048,383
-127^3 is -2,048,383
2,048,383 / 2,048,383 = 1
-2,048,383 / 2,048,383 = -1
ANYTHING LESS THAN FULL STICK would result in…
2,048,382 / 2,048,383 = 0.99999951181005 which will round down to 0
-2,048,382 / 2,048,383 = -0.99999951181005 which will round down to 0
A.k.a less than 1 which will immediately be rounded down to 0 because this is a non-floating type.
Tabor is wrong, OK mostly wrong. You are dividing by the wrong number, fix that and you’re good regardless of any miniscule casting errors.
I believe 16,129 (2,048,382 / 127) is the number you want.
127^3 is 2,048,383
-127^3 is -2,048,383
2,048,383 / 16129 = 127
-2,048,383 / 16129 = -127
Here’s some untested but pretty code that should work, or at least be really close to working…
// 127^3 is not enough to overflow an int, no need for long
int mapped2, mapped3;
// Badly implemented pow function, probably several ways to do this faster
int pow(int value, unsigned char power) {
// Init result to value
int result = value;
// Loop for power - 1 many times
for(; power > 1; --power) result *= value;
return result;
}
while (true) {
int pot = analogRead(8);
printf("%d\r\n", pot);
mapped2 = pow(joystickGetAnalog(1, 2), 3) / 16129;
mapped3 = pow(joystickGetAnalog(1, 3), 3) / 16129;
printf("%d\r\n", mapped2);
printf("%d\r\n", mapped3);
// drive functions
motorSet(motor1, mapped2); // right drive back
motorSet(motor2, mapped2); // right drive front
motorSet(motor10, mapped3); // left drive back
motorSet(motor9, mapped3); // left drive front
}
Note that PROS doesn’t define true properly or something so I have these lines in a header file I tend to include everywhere…
#define true 1
#define yes 1
#define false 0
#define no 0
typedef short boolean;
Also Tabor, the correct way to fix a cast issue is to write a … cast, so…
int foo = 43, bar = 785;
double baz;
baz = foo * 1.0 / bar; // Going to coin this a Tabor-cast
baz = (double) foo / bar; // How the rest of the known world does a cast