|
Re: tank drive
Another way to think of this is to convert the IFI joystick values into signed values (e.g. -127 to 127) then simple math to mix, then simple math to limit and finally simple math to convert back to 0-255 for the Victor. The IFI example code was lifted right out of the Pbasic code from last year. Pbasic didn't understand negative numbers (it was truely wretched...) hence the bizzare mixing code.
-------
char limit(int val)
{
if (val > 127) return 127;
if (val < -127) return -127;
return val;
}
void user_routine(void)
{
int Left = p1_y - 127; // Convert to signed #
int Right = p1_x - 127;
pwm01 = limit (Left + Right) + 127;
pwm02 = limit(Left - Right) + 127;
etc.
}
|