View Single Post
  #8   Spotlight this post!  
Unread 13-10-2010, 10:59
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Off season Questions **Need Help Asap/Code Check**

Quote:
Originally Posted by dShad View Post
A) The purpose of the code: When button 6 is true the motor goes forward (aka lifting the lifting device). When False the speed is set to 0. When button 7 is activated, the lifting device is lowered.
As Mark pointed out, your code gives an indeterminate result when either or both buttons are pressed. Both case blocks will try to set the motor at the same time, and which one actually succeeds is not predictable. To fix this, don't put the blocks in parallel. Put them in series. Instead of actually setting the motor speed inside the blocks, set it after them both. Here's how I suggest you do it:


Wire a constant 0 into the first block, connect Button 6 to its select input, and in its false case just pass the input through to an output. In its true case, connect a constant 0.5 to the output instead.

Wire the output of the first block into the second block, connect Button 7 to its select input, and in its false case just pass the input through to an output. In its true case, connect a constant -0.5 to the output instead.

Feed the output of the second block into the Set Motor vi. Done! This makes the "down" button take priority over the "up" button. Change the order of the case blocks if you want the "up" to override the "down" instead.



For this kind of thing I would actually use select functions instead of case blocks, but that's not a big deal.
Reply With Quote