LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

using an event structure in a state machine for shimmer accelerometers

Hi,

 

New post here. I have modified the multi accelerometer subvi created by Shimmer and have attempted to put it into a state machine using an event structure. I was hoping this would allow a user to do multiple trials of streaming and saving, where in between trials the qeues are emptied and started fresh.

 

I have been able to get my machine to connect properly and have it rest in the configuration state waiting for the user to press start. My problem is when start is pressed, the action command does not make it into the Shimmer Sensing VI. In this VI, the action command tells the Shimmers to start streaming. I am not sure if it is how my timeout is set up or if there is another issue. Subvi I am working on can be found as such:

 

"C:\......\ShimmerSensing\Multi Shimmer Template_stream_Anton_v2 Folder\Public\Examples\Multi Shimmer Template_stream_Anton_v2.vi"

 

Any advice or help would be greatly appreciated.

 

Anton

0 Kudos
Message 1 of 21
(3,633 Views)

Holy Canole! This code is no fun.

 

Where to start. Ok, so usually when you want an event based state machine, you have a large case structure around the outside of the even structure and the event structure itself is in the "Idle" state. The code you've supplied has multiple small case structures based on the state AND the action string (multiple state selectors is weird) within another case structure. This can easily lock up if the wrong buttons are pressed in the wrong order. What happens when it's like the way you have it is that the requested state isn't triggered immediately, it has to wait for that timeout (50ms?) before the state actually triggers and then you have a state and an action to decipher still within that state. I think you're trying to scale the original code when the original code wasn't written to be easily scaled.

 

Do you need all of the functionality in the demo code? If not, you should look in to starting from scratch using a normal state machine architecture and copying the relevent code form the example given. The Simple State Machine architecture ships as a template with LV 2013 and newer.

 

It's really hard for me to figure out what's going on here and why you wouldn't see the Start making it's way through. I wouldn't suggest Highlight Execution because that would take a looong time. Have you tried probing around in the "Start" state to see what data is getting passed?

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 21
(3,626 Views)
Thanks for the quick reply James!

I would like to retain most of the functionality as we do intend on collecting from the other sensors. I figured a state machine would be ideal because of the user interaction. Some of the added functions are so that the user can view the live stream, and save te data automatically when they press stop.

Would you suggest putting the event structure within a case structure instead of how I have set up currently. In this case, what would my states be aside from idle?

Thanks,

Anton
0 Kudos
Message 3 of 21
(3,580 Views)
Sorry - when I probe to see what happens when start is pressed, the action command "start" is sent into the main shimmer vi but nothing comes out.
0 Kudos
Message 4 of 21
(3,577 Views)

You would have the same states you have now along with the Idle state, Initialize, and Exit. You could add a Timeout state, so that you can handle the timeouts the same way they are currently handled. Rearranging this way would take some significant work, but would be helpful in the future if you make additions.

 


@atrinh wrote:
Sorry - when I probe to see what happens when start is pressed, the action command "start" is sent into the main shimmer vi but nothing comes out.

What do you mean nothing comes out? Does the application freeze? If I were you, I would open both your new version and the old version of the application and probe both to see what differences there are when you run parts of the code.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 21
(3,561 Views)
  • Yes, your layout is "inside out". Not good!
  • How long does it take for the current state cases to complete?
  • Wy are none of your controls/indicators wired up? Exclusively using local variables and value property nodes is not the correct way.
  • How are you dealing with race conditions? For example you seem to be writing to the same indicators (via value proerty nodes) in parallel from multiple locations.
  • Many of your cases share a lot of duplicate code that can be shared. No need to have it in duplicate locations. What if you need to make a minor change? You would need to do the same change in N different places, exponentially increasing the probability of mistakes.
0 Kudos
Message 6 of 21
(3,555 Views)

The original VI would spit out "streaming" from the Shimmer VI which begins the live collection. My VI does not send anything out of the Shimmer VI and disconnects the BT accelerometers and I am not entirely sure why. This is what I am trying to figure out.

 

The connection/configuration event takes 5-10 seconds and then it sits their waiting until another user event. This parallels the original VI.

 

Regarding the value nodes, I am not sure why Shimmer went with that setup. My level of skill and experience using LabVIEW is pretty basic so I assumed the original VI was optimized and did not want to alter it significantly. Speaking generally, I do know that a state machine set up would be ideal for this program.

 

I have duplicated some of the cases because some of the subvi's that feed into the main shimmer VI will depend on the action command.

 

 

 

 

0 Kudos
Message 7 of 21
(3,512 Views)

If I were to change the state machine so that the case structure surrounds the event structure (instead of vice versa), would I still have my "events" triggered by a button press or would I change that to an auto event? I would guess that the button press is what triggers the change in state but I am unsure what to do to make the event execute.

 

 

0 Kudos
Message 8 of 21
(3,470 Views)

Here's how the code functions with a state machine:

  1. VI is sitting in the Idle state
  2. User presses Button1
  3. Event structure is now told that there is an event to handle called Button1 Value Change
  4. Event structure activates the code within Button1 Value Change event
  5. This code does whatever it is coded to do and also outputs that state value of "Button1State"
  6. The While loop is now finished with that iteration
  7. Next iteration is begun and the shift register for the state sees a value of "Button1State", so it activates the code in the case "Button1State"
  8. Button1State case does whatever it wants and outputs the next state of "Idle"
  9. While loop is now finished with this iteration
  10. Next iteration, the state comes in as "Idle" so it goes to the idle case and waits at the event structure for another event

If you wanted to trigger any of these buttons or events without the user, you can do that using a property node and "Value (signaling)" property. You can also do custom user events and dynamic events, but we'll leave those for another time.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 9 of 21
(3,458 Views)

When the button press triggers a change to the next state, do I have the next state's entire code within an event structure? For example:

1) Press Connect

2) Value change of Connect is registered by event structure in Idle state

3) Triggers change to connect state

4) BT accelerometers connect then automatically goes to configure state

5) configures accelerometers and then waits here until user action

 

Or would I put a similar event structure in the configure state to register the next event and use the wait (ms) to tell it to wait in that state indefinitely until a new user event is registered?

 

I really appreciate the help and the prompt replies.

 

Thanks again,

 

Anton

0 Kudos
Message 10 of 21
(3,440 Views)