LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

implementing State machine

Hi,

I am trying to implement a state machine for my application. I have an initialize state where I initialize the input variable. I am trying to index the array elements one by one, for example index the element 0 and pass the value to the sensor, wait for 1s, then record or store the value to another array. But I was not able to index the array elements one by one, kindly suggest me some way in which I can do that.

0 Kudos
Message 1 of 3
(332 Views)

As a first step, I recommend to clean up the code a little bit.

 

  • There is no need to maximize the diagram to the screen.
  • Having controls (e.g. your two buttons) without labels, especially if they are assigned to events is very poor. If you don't want to see the label on the front panel, you can hide it (right-click...visible items), setting the label to an empty string is really, really bad!
  • Having a 100ms wait inside a timeout case it just silly.
  • Your while loop in the "index" state is misguided. The shift register needs to be anchored on the outer loop.
  • Your for loop in the "record" state can be replaced by a simple "build array".
  • "Numeric" is a poor choice for a control label.
  • Give all controls reasonable default values. For example, an empty "array" (poor choice of label!) is not a reasonable default value.
  • What should happen if the array runs out of elements?
  • Everything seems very convoluted.

 

 

Start with writing down all possible states, what should happen in them and what should cause state transitions as a function of time and user interactions. For testing I would eliminate the hardware interactions and replace the lower loop with a simple simulation instead. Makes testing much easier! I even doubt that you really need two parallel loops.

Message 2 of 3
(312 Views)

Thanks

0 Kudos
Message 3 of 3
(237 Views)