would this code work to help keep the robot from swerving?(uses tank style control with pwm_01 and pwm_02 on one side and pwm_03 and pwm_04 on the other side of the robot) It should. also let me know if there are any errors in it.
Code:
signed char distance = p1_y - p2_y;
if (distance < 0)
distance = -(distance); //the absolute value of distance
else if (distance <= 14)
{
p1_y = p2_y = (p1_y + p2_y)/2;
}
pwm01 = pwm02 = p1_y;
pwm03 = pwm04 = p2_y;
the only possible problem I can see is how it converts (but doesn't really convert) a signed char to an unsigned char (the pwm values). is this a problem?