View Single Post
  #2   Spotlight this post!  
Unread 04-02-2011, 23:12
iblis432 iblis432 is offline
Co Captain/Chief Programmer
AKA: Bobby
FRC #2106 (Junkyard Dogs)
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Virginia
Posts: 146
iblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to beholdiblis432 is a splendid one to behold
turning a push button into a switch

I am trying to get the robot to switch a state based off the single press of a joystick button. I designed a system that i thought would work, but it began constantly switching the state back and forth without me pressing anything every (what I believe based off how i designed it) 10 ms.

I don't have the code with my right now, but in pseudo code this is what i did.

Code:
In periodic Tasks.vi

   10 ms loop
       If button pressed
               if global button data == true
                       set global button data = false
               if global button data == false
                       set global button data = true

In Teleop.vi

   If global button data == true
          set solenoid = forward
   else 
          set solenoid = reverse
So basically, I have two case structures inside each other in the periodic tasks loop thats constantly checking for if the button is pressed, and I THINK I have the state changing when the button is pressed. I put it in the 10 ms loop because i didn't want it switching every cycle just because we held the button for more than a nanosecond, but i didn't want a WAIT slowing down our teleop. Anyway, the state is sent to the Global Robot Data and called in teleop, where a single case structure determines the solenoids.

If anyone can tell me why it did what it did, how to fix it, or another approach altogether, I would very much appreciate it.

I will post the real code ASAP.
__________________
"Don't worry, programming can fix it"
Reply With Quote