02-16-2016 08:14 AM
Hey Everyone,
I am encountering a particular problem regarding the logging of data after a certain trigger condition has been met.
My task is to log some data based upon a particular triggering condition, the data to be logged should be the data preceding (e.g. 1 sec prior) and all the proceeding (e.g. 1 sec after) the trigger point.
So far, I have browsed the forums and my current VI is based on the solution listed here: http://forums.ni.com/t5/LabVIEW/Log-data-before-and-after-occurance-of-a-Trigger-Condition/m-p/32095...
The above solution makes use of the 'Queue' function and I am unsure if I am utilising it in the correct fashion.
As it stands my problem is that, I can indeed log data when the trigger is met, but I am unsure as to how to continue this logging for a certain amount of time (e.g. 1 second) following the occurence of the trigger.
I would be be very greatful if anyone could provide assistance. I have provided a copy of my developed VI as reference 🙂
Solved! Go to Solution.
02-16-2016 09:26 AM
I think I would use a Producer Consumer architecture here.
Have you producer loop constantly acquiring data and a time stamp (t) to your Queue.
Then the Consumer loop will just wait until it is triggered (t).
When triggered the consumer loop will save the data from t-1 second through t+1 second to disk.
02-17-2016 03:21 AM - edited 02-17-2016 03:25 AM
Many thanks for your reply! 🙂
I have tried to implment the producer/consumer architecturte with my queue but am unsure of how to implement the timestamp functionaility you suggested...
Please find attached a copy of my producer/consumer VI.
02-17-2016 04:01 AM - edited 02-17-2016 04:04 AM
edit: you also connected the two loops simply with a Array wire, which is totally wrong. You will not get data passed between the two loops. Think of data flow principles! Use the Queue to broadcast data from the top loop to the bottom!
02-17-2016 04:44 AM - edited 02-17-2016 04:55 AM
This can give you some idea, but still work to do on it, good luck!
(this is a snippet, you can save it and drag and drop onto a block diagram)
Edit: After reading your full post, I see you wanna save data 1 sec before and 1sec after the trigger condition occured (trigger condition is when the difference between the actual Mean value and the previous one is larger than 0.1??).
I let you work on this part further. You need to work on the logic, and also store the 10 samples for t-1 in a shift register. When the condition is fulfilled, you save the 2 seconds of data (20 data samples) into the text file... Try it yourself, and if something looks bad, post your code here...
edit2: it also needs clarification, whether you wanna save data for t-1 and t0, or also for t+1? 🙂 In the second case you need to save 30 data samples in the file...
02-17-2016 09:25 AM
Many thanks for the reply Blokk! (2nd thread so far 🙂 )
Your highlighted points proved to be very useful and I learning how to 'attach' timestamps to the data was really enlightening.
I have looked into implementing your suggestion with the shift registers, but after undergoing numerous changes I am none the wiser.
Therefore, I tried to implement it through timers. I thought about using a delay or a relapsed time.
I have attached a copy of this timer version of the trigger logging as reference.
02-17-2016 09:34 AM
Does not look correct. You put the elapsed time Express VI there, but that consumer loop iterates once per second. So it does not make any sense in this way. Also you do not need to specify the maximum Queue size, delete the value 10 at the "Obtain Queue" function.
You need to use the shift register way, and create a logic when a trigger condition happens, you save the previous iteration, the actual iteration, and the next iteration data. Try to think about, how to do this...The elapsed time Express VI is not useful here!
02-17-2016 10:48 AM
Hi Blokk,
Your tips concerning the shift register proved to be really helpful and I have managed to finally implement a trigger that saves data from the past second as well (happy days!).
I will try implementing the t+1 data logging as well tommorow (in addition to making some corrections to the time stamps display).
For now, please find my current VI attached 🙂
P.s. please excuse the 2 different file saves. It was just a method in which I compared the data to see if my code was working as it should.
02-17-2016 11:20 AM
Just better avoiding that evil dynamic data in LabVIEW!
Here I show you a possible way how to save the three data blocks. Note that, this solution might create overlapping, when there are consecutive trigger conditions appear. But you can improve the example further. I also created a subVI for the data saving, more space this way (Save_data.vi)...
subVI:
Consumer loop:
02-17-2016 11:39 AM
I am not sure why you would need to use the shift registers.
All the data is already in the Queue, let is stay in the Queue until you need to save it, don't unload the Queue into shift registers then save the data from the shift registers. That seems rather redundant.
You have a time stamp and you know (or should know) the time then the save command is sent (t)
Once you get the save command start de-queing data from the Queue and just save the time span you want (t-1 through t+1) and then clear the queue for next time.