Quote:
Originally Posted by Alan Anderson
Joey probably has it right. The pwm values are unsigned char, and it's likely that the compiler isn't accounting for the possibility of underflow when subtracting 127. If your joystick puts out 125, the result wraps around to 254, which gets divided down to 127 and shifted back up to 254 by the final addition. Forward control on the joystick will work okay, but the slightest backward movement will cause the robot to go full speed forward. Using 1-stick control, barely moving the joystick to either side will make it circle madly in the opposite direction.
Adding the cast to (int) will force the compiler to deal properly with the signed values, and everything should be okay.
|
Thanks for the support. I seem to remember smashing a mentor into the tool cabinet a couple years back because any input value less than 127 would send the output to 0, and thus sent the robot into full reverse as soon as I touched the joystick. I'm pretty sure that was the quick-and-dirty way of fixing it. Good luck, brennerator.