LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Structuring Code For Manual, Record, Play Mode

Solved!
Go to solution

Hi,

 

I have 3 Vi's, one for manual operation, one for record and one for playing back the recorded data. They take a 0-5V signal read by a Arduino Uno micro controller.

 

Manual - this just constantly reads the signal

Record - upon activation this records the signal from the Arduino ad writes the values into a file

Playback - this takes the data written into a file and plays it back.

 

I am unsure how to structure the code. I want the user to be able to chose between any of the modes, and randomly switch between them (i.e there is no defined sequence). I would also like the common features such as the output chart use the same plot, not use one plot for each mode.

 

I have attempted to do this using a case structure, however you can only switch between cases if you change the case, then stop the currently active state. Even this does not work for switching between some stated as they do not have a stop button to allow release from the active state to the new one.

 

I'm sure that there must be a convenient way of doing this, I'm just not sure what it is and am not sure what to be searching for on the forums. I have attached my present attempt. Any advice or example vi's of a similar type would be appreciated.

 

Eventually the code will be integrated into a system for manually operating a 3 axis table (stepper motors), with the ability to record operations, and play them back. I have the stepper motor control dealt with, I just need to understand how to switch between operation modes. The input will come from joystick and potentiometers measured by a microcontroler to form the input.

 

 

I'm using labview 2010.

0 Kudos
Message 1 of 14
(3,032 Views)

You may want to look into producer/consumer event structure if not using that (just be looking at the attachment).

There can be multiple consumers loops say one to read the data, another to record to file.Communcation between the producer/consumer can be done by using data queues.

More information on producer/consmer can be found here .

 

 

 

*************************************************
CLD
*************************************************
0 Kudos
Message 2 of 14
(3,019 Views)

Are you sure this is the best way? After reading the notes it seems like this might not be approproate for me. The producer/consumer system seems to be for processing data at different rates for different processes.

 

I have 3 modes to execute, but I only ever want to execute 1 mode at a given time, although 2 of them do both use the same data stream. The third (playback) does not collect any data, it just reads from a file and outputs it. 

 

Using the producer/consumer method would I do the following: Make data collection the producer and have 2 consumers, one as graphical display (manual mode) and one to record the data to a file (record mode). But then I do not understand how to intergrate the playback mode as it would either need a second producer (read file) with a consumer (display data) or be a stand alone feature which would again mean i have issues switching between the consumer/producer and the playback mode. The playback mode does not need the data from the producer.

 

 

Can any one clarify this for me or offer any advice?

 

 

 

 

0 Kudos
Message 3 of 14
(2,976 Views)

Hey Carlr,

 

Your application sounds like it would be best suited for a state machine.  Have you used this architecture before? If you click File > New... in LV then you can see what I mean from an example template --> select the Design Pattern for Standard State Machine. The way your code is written now will actually need to change a little, but it will be for the better, in my opinion. For example, Since you use the Init and Close VIs a few times, I'd probably have an "Init" and "Close" state.  Then, when the user selects Manual mode, you could process the states Init > Manual > Close.  If they selected Record mode, then it'd be Init > Record > Close, where Record waited for the user to click  "Start". And Playback might be something different altogether. I'm coding up a simple program now to show you what I mean.

 

The producer/consumer method could even be combined with a state machine to make a very robust UI, but I think this is probably a bit overkill for what you need. For the sake of discussion, though, if you wanted to try this out I would guess that your producer would catch UI events (such as Start Acquisition and Stop Acquisition buttons, etc.), and the consumer loop would be a state machine. One of the states would inevitably be "Wait for User" or "Process User Input", something like this.

 

Anyhoo, there are probably a lot of ways to do what you're looking for, but that's just my quick and dirty 2 cents. Example to come later today.

 

0 Kudos
Message 4 of 14
(2,951 Views)

@Roryriffic wrote:

Hey Carlr,

 

Your application sounds like it would be best suited for a state machine.  Have you used this architecture before? If you click File > New... in LV then you can see what I mean from an example template --> select the Design Pattern for Standard State Machine.

 



Or, even better. File>>Create Project

Capture.PNG

Clicking the More Information bold text should bring you HERE


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 14
(2,946 Views)

Hi Jeff,

 

Carl uses LV2010 and the links to "HERE" is located on your local harddisk...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 14
(2,941 Views)

Code attached. Hope this helps.

 

EDIT: I re-attached the Controller VI and added Batch Enable-Disable to make the UI more user friendly.  Why not, you know? 😉

 

Cheers,

Rory

Download All
0 Kudos
Message 7 of 14
(2,936 Views)

WHOOPS, thanks Gerd

HERE

is the online version


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 14
(2,924 Views)

... which gets me thinking Carl will need these VIs in 2010 as well...

0 Kudos
Message 9 of 14
(2,919 Views)

Thanks for the help above. However even after reading the documentation i can't say that I fully understand what i'm supposed to be doing.

 

I have had a go at implementing my code into the supplied structure as attached. When i execute this in manual i get the error 5003. The playback mode appears to work but i don't see the data on the chart. The aquire mode (which i've assumed is the same as record) does not work.

 

I'm also not sure that I've correctly wired the arduino initialization and close blocks correctly. Also in order to do everything in the waveform shift register I've had to modify the data types on some cases, I'm not sure that they will now work.

 

 

0 Kudos
Message 10 of 14
(2,901 Views)