View Single Post
  #4   Spotlight this post!  
Unread 08-02-2004, 12:22
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Could someone look this over?

Quote:
Originally Posted by Joe Ross
Code:
        	if(currentPWM >= goalPWM + sensitivity)
        		return currentPWM - sensitivity;
        	if(currentPWM <= goalPWM - sensitivity)
        		return currentPWM + sensitivity;
Since everything is an unsigned char, then this code is a problem.
If goalPWM is 254 and sensitivity is 10 and CurrentPWM is 127, the result of (goalPWM + sensitivity) is 8 and so CurrentPWM is greater then 8 and you return 117 not 137 like you hope.
Yep, that will be the problem I'm sure. I'll just add a few extra tests for the extreme cases. (wanting to be at 0 and 254)

And the funny thing is, I had already paritially taken looping around into acount in the code.
__________________


Last edited by Ryan M. : 08-02-2004 at 12:27.