10-31-2011 04:59 PM
Hi,
I am working on a labview code for a reaction game, and I have stumbled into the problem. I am re-creating the drag racing start light sequence, and then measuring how long it takes the user to press a button after the lights turn green. The lights go though a process, turning yellow after certain intervals, and then finally going green. I also have it made so when the user clicks the button, a sound file plays. I have made my program so everything works how it should, using a state machine, but my problem comes with if the user clicks the button too early. I I was able to wire it so that the red "jump start" light turns on, but the sound won't play early.
When the light turns green, the program waits for the user to press the button before playing the sound and displaying their reaction time as it should, but sometimes people will press it too early. When the light does go green in this case, it will immediately play the sound file and signify that they clicked too soon. But let's say they clicked real early, like a couple seconds too soon, the sound file won't play till the lights turn green, which wouldn't be synced with their button pressing. Normally it's hardly noticeable, but it'd be nice if I could get it to work.
I have tried everything to make it work, but the problem comes from where I place the while loop measuring their reaction time. If I put it in the state machine as it is now, it can't recognize their button pressing till it gets to that state. If I put it outside the state machine, then the state machine won't change states because it's waiting for the while loop to finish (which is dependent on the user pressing the button).
I have attached my file for you to look at. I'm not sure if what I am trying to accomplish is possible, but I believe there must be some solution. But so far I haven't found it.
Thank you.
-Brian
10-31-2011 06:31 PM
Wow... that's a lot of wiring, and hard to follow. The nested loops, partially hidden case structures, and floating feedback node are not great LabVIEW style. The block diagram cleanup tool will help a bit, but my recommendation is that you group the booleans on each side into a cluster. This will make it much, much easier to keep the booleans in sync with each other (for each player), because you can wire the same cluster value to both of them.
I suspect the key to getting this to work the way you want is to accept that you can stay in the same state for multiple loop cycles. Instead of putting a Wait inside each case, keep track (in a shift register) of the time when you first entered a state, and when you reach a certain amount of time past that point, advance to the next state. That way you can check the button press value continuously, regardless of what state you're in, and not need to wait until the Wait times out. You'll still want a small Wait value in the loop (the top level of the loop is fine) so that your code doesn't spin as fast as possible (preventing the CPU from doing anything), but it can be on the order of 10s of ms.
10-31-2011 06:59 PM
You may want to consider some additional states to handle the early button press conditions. Another option might be to disable (but not gray out) the button until the green lights are on.
As nathand advised, the timing should be doen in a much finer=grained way so that the program does not spend several seconds waiting to respond to something.
Also, look into the event structure. It is intended to allow rapid response to front panel events.
Lynn