From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reaction Time Test

Solved!
Go to solution

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

0 Kudos
Message 1 of 11
(5,896 Views)

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.

Message 2 of 11
(5,889 Views)

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.

0 Kudos
Message 3 of 11
(5,866 Views)

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.

0 Kudos
Message 4 of 11
(5,847 Views)

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?

 

 

0 Kudos
Message 5 of 11
(5,825 Views)

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

0 Kudos
Message 6 of 11
(5,801 Views)

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.

0 Kudos
Message 7 of 11
(5,798 Views)
Solution
Accepted by topic author jarucan

You can just ignore button reads until the time is right.

 

Here's a simple rewrite, see if it makes sense.

 

Notes:

  • Make sure that all controls have labels. You can hide the label on the front panel, but don't make it an empty string. It makes assigning event, etc. nearly impossible. All controls need a label for code readability.
  • Don't maximize the diagram to the screene. That's very annoying.
  • Don't trap event structures insude case structures.
  • Don't use right-to-left wiring (e.g. for the status)
  • Mind your representations. Look at all your red coercion dots. The numbers should be Integers of the same type.
  • Watch out for mechanical actions. Your start button is "switch until released" (like a car horn!), making detecting a press hit and miss, epsecially in the presence of long waits.
Message 8 of 11
(5,797 Views)

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?

0 Kudos
Message 9 of 11
(5,773 Views)

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.

0 Kudos
Message 10 of 11
(5,764 Views)