View Single Post
  #9   Spotlight this post!  
Unread 03-12-2004, 22:07
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Lightbulb Re: pwm ouput limiting

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?

Last edited by stephenthe1 : 03-12-2004 at 22:10.