View Single Post
  #21   Spotlight this post!  
Unread 21-01-2007, 16:59
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Re: Potentiometer PID

Quote:
Originally Posted by Alan Anderson View Post
It makes sense if you're averse to using procedural programming and prefer functional programming. The logic behind your code gives the same result as the one using if statements, but the reason for doing it that way is obscure to anyone encountering it cold.

And it takes a lot more time to do it your way. A few comparisons and branches are faster than many multiplications and additions. Note that the original code never does more than three comparisons and one assignment. Yours always does six multiplications, thirteen additions, and one comparison. It would be instructive to compile both alternatives and compare the generated assembly language code in the listing file.

As an aside, wouldn't it work just as well to simplify the condition to this?
Code:
if ( ( Button1 + Button2 + Button3 ) == 1 )
hahaha
wow. this is what no sleep does to you.
thanks for that.
maybe I just think weird or something
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website