Thread: Joystick Wheels
View Single Post
  #2   Spotlight this post!  
Unread 13-02-2003, 09:34
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Unlike the buttons, the wheels are analog controls that will have a value between 0 and 254, with 127 being the middle. Based on the fact that you are going to be controlling relays with them, you only need to know whether the wheel is greater than 127 or less than it. The following code will accomplish this:

relayX_fwd = p1_wheel / 127
relayX_rev = 1 - relayX_fwd

This works because of the way integer math rounds things off. (ie 200/127=1 and 50/127 = 0). The second line is there to make sure that the relay is either in forward or reverse, but not both. If you are using the big Festo single solenoid, you can (and should) get rid of the second line.

With this code, whenever the wheel is at or above the middle, the cylinder will go one way. When it is below, it will go the other. Let me know if you were looking for something different.


--Rob
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php