We got rid of some things that were being used, switched to not using the table, and and made all the variables ints.
Updated code-
Code:
void Mechanum(void)
{
signed int prepwm01, prepwm02, prepwm03, prepwm04, wFL, wFR, wRL, wRR, velocity, rotation, strafe, wMax;
static char pwm01_1, pwm02_1, pwm03_1, pwm04_1; //will be used eventually
velocity = (p1_y - 127);
rotation = (p1_x - 127);
strafe = (p2_x - 127);
printf("Velocity: %d Rotation: %d Strafe: %d \r \n", velocity, rotation, strafe);
wFL = velocity - rotation - strafe;
wFR = velocity + rotation + strafe;
wRL = velocity - rotation + strafe;
wRR = velocity + rotation - strafe;
printf("Wheels before wMax- FL: %d FR: %d RL: %d RR: %d \r \n", wFL, wFR, wRL, wRR);
wMax = intMax(127, intABS(wFL));
wMax = intMax(wMax, intABS(wFR));
wMax = intMax(wMax, intABS(wRL));
wMax = intMax(wMax, intABS(wRR));
wFL = (wFL / wMax);
wFR = (wFR * 127 / wMax);
wRL = (wRL / wMax);
wRR = (wRR * 127 / wMax);
if (-127 > wFL || wFL > 127 || -127 > wFR || wFR > 127 || -127 > wRL || wRL > 127 || -127 > wRR || wRR > 127)
{
printf("Received an unexpected number FL: %d FR: %d RL: %d RR: %d /n", wFL, wFR, wRL, wRR);
}
else
{
prepwm01 = wFL + 127;
prepwm02 = 127 - wFR;
prepwm03 = wRL + 127;
prepwm04 = 127 - wRR;
pwm01 = prepwm01;
pwm02 = prepwm02;
pwm03 = prepwm03;
pwm04 = prepwm04;
printf("PWMS- pwm01: %d , pwm02: %d , pwm03: %d , pwm04: %d \r \n", pwm01, pwm02, pwm03, pwm04);
}
}
None of the other functions have changed.
We are currently receiving not quite so crappy numbers, but still aren't getting the desired results (COM window attached).
We've found the problem to lie in-
Code:
velocity = (p1_y - 127);
rotation = (p1_x - 127);
strafe = (p2_x - 127);
We've put some printf statements before and after these 3 lines, but the p1 and p2 variables are correct. For some reason the code is adding 129 to p1_x and p2_y and storing that into rotation and strafe instead of subtracting 127.
We can't figure out where this is coming from. Any ideas?
Sorry we couldn't try the last poster's suggestion today- our lab lost its internet connection, and we forgot what it was. We'll try that tomorrow.