LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Start the time calculation at zero

Hi,
 
I am trying to generate signals from the attached VI. I've got a Matlab script inside my VI that changes the angle 'theta' depending on the time 't'. However, my problem is; inside the Matlab script, I don't know how I can make the value of 't' to be zero for the first time the loop executes. The first statement I have is 't = t+dt' which therefore makes it non-zero. However, if I define an input into the script that sets t = 0 initially then this value is used for every calculation and my time does not increment as it should.
 
Does anyone know how I could implement t=0 for the first time this VI loops?
 
Thanks.
0 Kudos
Message 1 of 7
(3,168 Views)

imperial-aero,

Here are three different options I can think of to increment the value of 't', starting at zero:

1. Create another script node that executes before the While loop starts.  The node can simply contain 't=0;', and no inputs or outputs should be needed.  Make sure to wire the error cluster so that it is guaranteed to execute before the loop starts.

2. Wire the First Call? node to the current script node (you'll need to convert the boolean to a double), and add a case in the node to check if it is the first iteration.

3. This is the solution I would go with:  Eliminate the script node altogether, and compute the 'theta' values in LabVIEW.  These are very simple calculations, and there is really no reason to send data back and forth between LabVIEW and another program for something like this, unless you ultimately decide to do something far more complicated in the script node in the future.

Chris M.

Message 2 of 7
(3,157 Views)
Here's another solution that would be much simpler than the first two options I listed above:  Wire the iteration terminal of the While loop to an input on the script node titled 'i'.  Then you can replace the first line with 't=dt*i;'.  Note that I still think it would be most effective to replace the script node with native LabVIEW code Smiley Happy
 
Chris M.
Message 3 of 7
(3,149 Views)

Cheers for the reply Chris.

You're right. The last option is probably the best as this is all I am trying to achieve using this VI. However, I've only got basic LabVIEW knowledge and can't actually figure out how I would achieve this. I am guessing I need to have another While Loop inside my main While Loop that does the time incrementing, since the main While Loop increments at every second as it is set up like it is.

Any pointers on how to actually achieve this will be much appreciated.

0 Kudos
Message 4 of 7
(3,144 Views)

imperial-aero,

Here's how I would implement this in LabVIEW (there are many ways to do this).  I removed the DAQ code and made some simplifications to make it easier to read.  No extra while loops are necessary because the script node code is not iterative.  Note the use of the shift register to keep the old value of 't' at each iteration.

Chris M.

Download All
Message 5 of 7
(3,132 Views)
Cheers Chris. That has really made my life a lot easier.
0 Kudos
Message 6 of 7
(3,122 Views)
Hi,
 
I'm having some difficulties with this VI again (attached). The problem is; when I connect the sampling info to my Function Generator the rate at which the waveform changes is different to that of my my original VI with the Matlab script.
 
Do you reckon I need to put the calculations within a While Loop inside my VI? This is because right now it is incrementing the time 't' at each instant the main loop executes (i.e. every second). This makes the time 't' of my calculations to be different to that of the Function Generator.
 
Thanks. 


Message Edited by imperial-aero on 05-01-2008 04:43 AM
0 Kudos
Message 7 of 7
(3,097 Views)