Quote:
|
Originally Posted by billbo911
With Tom's permission, could you possibly post the section of code that makes the magic work? PLEASE!!!!
|
Well credit needs to be given where it's deserved. I got the equations for my kiwi code from the living genious, Joel Johnson.
Anyway, here's what you need to do to make it work:
PHP Code:
//Make sure variables are unsigned ints... rollovers WILL occur with signed ints
unsigned int trans_x, trans_y, rot;
//Grab inputs (x,y coords in rectangular coordinates and rotation rate)
trans_x = 254 - PWM_in1;
trans_y = 254 - PWM_in2;
rot = 254 - PWM_in4;
//Limit vector length to 127
trans_x = (unsigned int)(37+(254*trans_x)/359);
trans_y = (unsigned int)(37+(254*trans_y)/359);
//Assign and limit wheel outputs
wheel_1 = (unsigned char)limit( (((2*trans_x) + rot) / 3), 0, 254);
wheel_2 = (unsigned char)limit( ((601 + rot - trans_x - (168*trans_y/97)) / 3), 0, 254);
wheel_3 = (unsigned char)limit( ((161 + rot - trans_x + (168*trans_y/97)) / 3) , 0, 254);
This assumes you have a limit function, which limits an input value to upper and lower bounds.
PHP Code:
signed int limit(signed int value, signed int min, signed int max)
{
if (value < min)
{
value = min;
} else if (value > max)
{
value = max;
}
return value;
}
That should be all you need, and it
should work. (It took me about 2 hours to figure out the variables needed to be unsigned.

)