LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner question re: case structures

Solved!
Go to solution

Hi,

 

I apologize if this post is in the wrong place. I am a student learning Labview as part of my pursuit of an EET degree. I have to design a soda machine as a project for my Labview class. I am researching how to start the prgramming (I am overwhelmed) and am trying to learn about case, and event structures. My professor gave us the task of designing the machine, with no further instructions or guidance. I have been scouring the internet for examples of code, but really haven't found anything I can use to understand how to prgram this machine.

 

My question is, when using a case structure, does it always have to be initialized? Can I write the structure to just wait for the user to start entering money, as you would in the real world? All of the tutorials I am watching show an initialize case as part of the prgramming. If I use event structures, inside of a while loop, will this more realistically model a mchine found in the real world?

 

I have been trying to get started on this project for a couple of weeks, and am really confused, so I appreciate any and all help / advice.

 

Thanks very much,

 

George

0 Kudos
Message 1 of 37
(4,047 Views)

Hey George,

 

Along with looking through the basic labview tutorials, a lot of it is can be learned by trying and failing. In this case though, you're looking for a state machine where it initializes to a "default" state, which there is an example of here: http://www.ni.com/tutorial/7595/en/

 

Hope this is helpful in explaining your task,

 

Anthony

Message 2 of 37
(4,041 Views)

Hi Anthony,

 

Thanks very much for your reply. The page you linked is very helpful. I am still confused as to whether I should be using this version of the state machine, as oppsed to using event structures, which I understand use less CPU, and is a more streamlined way of programming the machine.

 

I will go through that page very carefully, and see if I can implement the techniques to get the outcome I am looking for.

 

Thanks for your time.

 

George

0 Kudos
Message 3 of 37
(4,034 Views)

Here is a skeleton example of an architecture that I often find useful.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 37
(4,006 Views)

Thank you Paul for including that file. It looks like Greek to me, but maybe I can make some sense of it! 🙂

 

George

0 Kudos
Message 5 of 37
(4,003 Views)

Look under the section "Looking for Free Training" for some basics tutorials which may help you get started.

 

https://decibel.ni.com/content/docs/DOC-40451

0 Kudos
Message 6 of 37
(3,982 Views)

 

I am still confused as to whether I should be using this version of the state machine, as oppsed to using event structures, which I understand use less CPU, and is a more streamlined way of programming the machine.

Quite frankly as a new programmer I would suggest you avoid event structures, as event based programming breaks the "data flow" paradigm LabVIEW is based on.  You know I have been programming LabVIEW for well over a decade and can count the number of times I have used event structures on one hand. 

 

A state machine is one of the most versatile architectures there is and I use it probably 95% of the time in my programs. Next useful is probably the Producer/Consumer architecture, and you will probably notice the Producer/Consumer is often also a State Machine.

 

Also you might want to take a look at this: https://decibel.ni.com/content/docs/DOC-2145

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 37
(3,977 Views)

Thanks very much OEM_Dev!

 

George

0 Kudos
Message 8 of 37
(3,969 Views)

Hi RTSLVU,

 

Thanks for the advice. I will steer clear of the event structure for now.

 

Thanks again!

 

George

0 Kudos
Message 9 of 37
(3,967 Views)

@gsrokmix wrote:

I have been scouring the internet for examples of code, but really haven't found anything I can use to understand how to prgram this machine.

 

 

George


Smiley Surprised  That's very suprising considering it's probably the most popular way to make a tutorial about state machines.  I just searched "Labview soda machine" and came up with pages of tutorials, example code and videos.  The Soda Vending Machine was even a CLD test if I remember right.  Don't be tempted to just copy the first example code you find and turn it in though.  Some of them are deceptively simple looking but really pack in a lot to learn about state engines.  This knowledge is critical to advancement in LabVIEW so don't gloss over it too quick.  Look at many tutorials and play around and modify them so you can code a state machine without looking at any references.

 

You can get the benefits of a state machine and the efficiency of the event structure together by simply putting the event structure in an idle (waiting for user input) state or putting it in a separate loop and communicating through queues.  Once you get the basics down, advanced techniques likt that will seem obvious.  Just take it a step (state? Smiley Happy) at a time...

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 10 of 37
(3,962 Views)