06-02-2014 03:36 AM
Hi everybody.
I've been tearing my hair out trying to program a Reaction Time Test. I have been trying to search for topics that were like my program, but these programs were based on lights and on-off functions while mine is based on random number generator.
To explain a bit more in detail, I am creating a program that allows a test subject to choose 2 numbers to add or subtract (from 0-10). Then the program will randomly generate numbers between 0 and 10 and display it to the subject and the subject will need to react when the displayed number equals the answer in their head. On the programs side, when the number randomly generated equals the true answer the loop will start a timer and when the subject presses the button, the timer stops and displays the time.
Right now, I'm having a problem with the last sentence. I can't make heads or tails of how to get a timer started or getting it to properly output.
Any ideas?
Heres the most recent version of my vi
Solved! Go to Solution.
06-02-2014 03:48 AM - edited 06-02-2014 03:51 AM
Well, your entire code is inside out and way too convoluted for such an easy task.
First you need to learn he basics of dataflow. Your first inner loop will never stop, because the stop button is not inside the loop. It will only get read once before the inner loop starts and then never again, because the outer loop cannot proceed to the next iteration until everything in it has finished. Similarly, the "reaction time" indicator will only get updated after the main loop completes (which can never happen!), thus it will never show anything interesting.
Use a single outer while loop and make it a state machine. There are nice templates that ship with LabVIEW. Look at the shipping examples. Do some tutorials!
Also, if the two numbers are between 0..10, the result (sum or difference) can be between -10 and 20. If the result is outside 0..10, the result will never occur in your code.
06-02-2014 05:55 AM
I've started the State Machine, but now im wondering what to do next. I'm at the same problem where I was before, I don't know how to get the timing to work. This may seem like an easy problem for some but I can't see how to think of it.
Heres the new VI with the state machine added in. Im pretty sure i need a case structure, but thats where things get messed up. If you need the other .vis I can also send those.
06-02-2014 09:00 AM
You basically place a tick count into a shift register when the timer starts, and when the timer stops, you take another tick count and subtract the tick count from the shift register from it. The difference is the elapsed time in milliseconds.
There is also the "elapsed time" express VI that could be used.
Code still looks not ready.. Try to use an event structure.
06-02-2014 03:52 PM - edited 06-02-2014 03:52 PM
Okay, so I got everything working. Sort of. I feel like theres dataflow problems causing issues.
The first is the button is being triggered before the program shows the number. This basically means predict random numbers. I want the program to wait until the display function goes before the input is read.
Is there a way to delay the button read until after the number is shown?
06-02-2014 05:32 PM
The use of unlabeled controls makes it more difficult to understand what you want. Every control and indicator should have unique labels visible on the block diagram. You can make the labels invisible or use captions on the front panel to customize the appearance for the user.
How is a button triggered? Which button? What "triggers" it? Please describe what should happen when the Start button is pressed and what should happen when the OK button is pressed.
Lynn
06-02-2014 05:37 PM
Firstly might I suggest pressing the Clean Up Diagram button for the block diagram, this butto nis usually not too helpful for complex VIs but works well for making yours slightly more readable.
When you say making the button clickable after the display is updatable then there are a couple of ways to deal with this, the first way would be through dataflow by simply making the button be read after the display is updated, although depending on the type of button action you are using this may not help. The other option is to disable to the button until there is a value to be read but this is using property nodes and seems rather complex for this project.
Just as another comment, why do you have two stop buttons? I know that one says to stop the test and the other says to stop the whole program but they are both run straight to the stop button for the state machine loop so will cause the whole program to exit.
06-02-2014 05:37 PM
You can just ignore button reads until the time is right.
Here's a simple rewrite, see if it makes sense.
Notes:
06-02-2014 10:30 PM
Huh, I didnt think of doing a state machine like that.
Why use a value change rather than a mousedown? Aren't they the same?
Thanks for the help, I really appreciate it. Also, whats the practical application of using a case structure vs an event structure?
06-02-2014 11:12 PM - edited 06-02-2014 11:17 PM
A value change is more natural than a mouse down, If you have a boolean control that is "latch when released" you can press down, then mouse off it and it will not trigger. For numerics and strings, a mouse down is useless, because when the mouse down occurs, the new value is not even available.
"Mouse down" is more useful for other things, e.g. if you mouse-down on a graph and want to detect the xy position, or mouse down on an indicator, etc.
A value change is very simple. A mouse down is much more complicated because it needs to provide additional information, such as the mouse coordinates, etc. Something you typically don't need.
An event sutructure only operates when an event is triggerend or a timeout occurs. If you use a case structure instead, you need to constantly spin the loop to detect changes in controls. If you have long delays, as in your case, the program cannot proceed and reacts sluggishly. The event structure reacts immediately if needed, even if the timeout is very long. A simple wait cannot be broken early.