LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronization of motor and data acquisition

Hi,

 

In my project I have two main things I need to do:

1) data acquisition (analog input and analog output channel)

2) control the motor that I am working with.

At the beginning I got each of the assignment separatli so each has it's own VI, now I need to combine them and I need them to be able to run simultaneously.

 

I have tried to create a main vi which I know doesn't work because of the case structures. I have studied and did my online research and I thought about the producer/consumer with events (since there are input values from the user), but I don't understand if the queue function is only to save data. 

one important note: I don't need the 2 while loops (in the structure of the producer consumer) will transfer data between them (correct me if I am wrong but this is the most common use that this structure have), what I do need is to acquire the data and control the relevant parameters of the motor (by the GUI and allow the user set the values while the application continuous to acquire data).

 

I am quiet new with this software and this is my first program so I am having a really hard time to figure out what is the best way and how to apply what I need.

 

so please any idea or a thought will be more than welcome. 

thanks in advanced.

Download All
0 Kudos
Message 1 of 9
(3,427 Views)

please..... anyone? 

0 Kudos
Message 2 of 9
(3,376 Views)

Hey Naama,

 

Sorry nobody has gotten back to you yet. You're definitely doing pretty well so far based on these VIs. The producer/consumer structure is typically used with DAQ applications when you are expecting to read a lot of data very quickly and believe the time it will take to process the data will be greater than the time it takes to read the data. (e.g. reading 10 samples/sec but can only process 5 samples/sec). This data is acquired in the producer loop, placed into a queue, and is then removed from the queue by the consumer loop.

 

I had a little trouble understanding your application but if you are trying to read values through data acquisition, process those values and use them to control your motor, a producer/consumer architecture would be a good idea. I took a look at the VIs you posted and I guess I'm a little confused on what the specific problem is. What is not working in your application? The one thing I did notice is that there is no DAQmx Write function to the motors inside of your while loop. Since you are not writing from the analog output inside the loop, any changes you make to your motor settings will not actually be written to the motor.

Applications Engineering
National Instruments
0 Kudos
Message 3 of 9
(3,351 Views)

A couple comments:

Your event structure will only run once. Either to connect to the motor or to start. It will not run more than once. It get it to run more than once, you need to add a while loop around it and terminate the while loop when the start button is pressed.

Your filtering might not be doing what you want because you use the most recent samples, meaning that your waveform into the filter isn't continuous (you skip over older samples). I'm not 100% sure about that, but I think it's likely that it isn't working exactly as you want it to.

Regarding what you were saying in your post: The queue is used for communicating between different parts of your application that handle data at different rates, not specifically for saving data. This can be beneficial when developing a GUI because acquisition loops and processing loops are often slow. Having them sit in the same loop as the GUI will slow down the GUI as it waits for processing and acquisition to continue. Now, your acquisition and processing is very small. 10 samples is very small. So you won't notice with 10 samples. But that might not be very efficient either. So going toward moving your processing, GUI and acquisition into different loops can make the program easier to manage and run more smoothly. It's a bit of a hassle to set up queues for communication, but in the long run it makes your vis more manageable.

0 Kudos
Message 4 of 9
(3,339 Views)

Hi,

 

I am very sorry for my late response, I was on my exam period and I didn't come to the university to work on this application at all.

When I built those VI it was individually, but know I need to synchronise between them. I will elaborate- I need to do the data acquisition and at the same time I need to control the motor parameters. each of the programs works fine but since they both have a while loop I need them to work together and I honestly don't know how.

 

please if you have any idea...

thanks in advanced,

Naama 🙂

0 Kudos
Message 5 of 9
(3,267 Views)

Hi,

 

thank you for your response and I am sorry for the late response.

can you maybe elaborate or give an example?

 

thanks in advanced,

Naama 🙂

0 Kudos
Message 6 of 9
(3,266 Views)

just to add the trial of the main VI which combine both programs.

still having trouble to understand how to connect the while loops, let say using the producer consumer pattern.

changed the original stacked sequence to state machine (this part is initialization to the motor).

 

thank you all in advanced,

Naama 🙂

0 Kudos
Message 7 of 9
(3,259 Views)

A few notes:

 

Hopefully it doesn't make a difference, but again, to get a continuous waveform into your filters, you should be reading continuously. So your RelativeTo should be "Current Read Position". You currently read 10 samples per channel. It it is probably way more efficient to read all the currently available samples. That is available inside of the DAQmx Read Propery Node -> Status -> Available Samples.

 

You don't use your Task Is Done boolean output. Probably want to or it with your stop Acquisition.

 

You enforce proper order of the start tasks with a sequence structure, but normally you would just sequence them with their error terminals.

 

Regarding your question: In what way do you want to connect your while loops? What do you want to happen? There is a potential for producer consumer here. You could move your filtering out of the acquisition loop by passing the waveform out of the DAQmx Read into a queue. Then in another loop, the data could be processed by dequeing the waveform.

 

You could also move all your UI into its own loop (your UI control is currently broken up across many loops, though at the moment it isn't hurting you that much). You then would send commands from the UI loop to other parallel loops to get them to do things like initialize your motor, DAQ channels, start acquisition, stop acquisition, etc. The main benefit of this is that as your application grows, you always know where your UI events are being consumed instead of hunting around for them somewhere in your block diagram. It also decouples the actual UI element from your code (such as in your data acquisition loop), allowing you to put code in SubVis instead of your top level block diagram. From a software development point of view, you want to decouple dependencies as often as possible so your code can be modularized and reused.

0 Kudos
Message 8 of 9
(3,241 Views)

thank you for your response!

 

The main idea is while I acquire the data I can control the parameters of the motor, hence- controlling the motor. The application has two option:

1) normal

2) trigger it by changing the parameters of the motor. This is the reason we need to control the motors (or the parameter- it's basically the same) while we acquire the data.

At first I got each of the assignment individually, hence the individual VI's. Now I want to combine this VI into 1 "front panel" for the GUI.

 

I thought about the producer consumer but I don't need to transfer data between the loops, I need each loop to work independently to the other. What I do need to do is to control each of the loops. for example while the loop of the acquire data works I (meaning the user) would be able to change the parameters of the motor without disturbing the loop of the acquire data.

 

The vi:

1)      Connect to motor- the original program to "talk" with the motor using the Hiwin guide to use the labview to communicate with the motor.

2)      Acquire the data- generate and acquire the data simultaneously. 

3)      Trial of main- I have tried to change the stacked sequence with state machine and the while loop of the connect to motor with event structure. It doesn't work since know I have one "big" while loop and one "small" while loop. changed it a bit from the previous massage. 

4)      Trial of main 2- I have used the stacked sequence; I think this does work but then I don't have the option to let the user control everything (like creating a GUI). It just starts everything the minute I hit the run. that's not what I want.... I want to control when something happens, when I do connect to motor (initialization), when I acquire the data et cetera. 

 

please any help is huge for me... I have to finish this application asap

thanks in advanse!

Naama 🙂

Download All
0 Kudos
Message 9 of 9
(3,234 Views)