LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI Setup & Architecture Help

I'm definitely not an experienced labview user by the way so please excuse any dumb questions I ask...and thanks in advance for your help!

 

I'm under significant time pressure at work to complete what I thought would be a somewhat simple VI but in practice I'm  struggling with it.

 

The hardware I'm using is a cDAQ 9189 chassis with a 9264 analog output card as well as a 9202 analog input card.  The VI will be used to test a very fast two-axis steering mirror (for a lidar application).  I'm also using labview v19 (the "full" version).

 

This super fast steering mirror comes with a controller that inputs an analog voltage signal for each axis and outputs an analog voltage signal for the position and "error" of each axis (so 2 pairs of wires go from the 9264 AO card to the mirror controller to command the X and Y position of the mirror and 4 pairs run from the mirror controller to the 9202 AI card to tell me the absolute position of the mirror in each axis as well as what the controller thinks the position error is for each axis).

 

I need the VI to input a csv file (that's generated from matlab) that contains two columns of data with each column representing the command voltage "profile" for each axis of the steering mirror.  The delta time between the points in these files will always be constant in the file but may change from file to file (i.e. profile to profile).  Note that the dt can range from 1khz to 5khz and the total length of these tests will range from 5 to 30 seconds...so these input files could have anywhere from 5,000 to 150,000 data points in them.

 

Once the VI inputs this file I need to generate a waveform from the input data (I think) and then pass the first column of data to the analog output driving the X-axis of the mirror and the second column of data to the analog output driving the Y-axis of the mirror.

 

When the profile is run (notionally when the user presses a "run" button after the profile is loaded) I need to start reading/recording analog input data at 5hkz for the duration of the test (i.e. from when the profile starts to when the profile ends).  As far as data output, I was thinking a csv file that has a time column (starting at 0 seconds and has a new row of data every 0.0002 seconds...i.e. at 5khz) as well as columns for the voltage command to each axis and the 4 feedback channels (so 7 columns in total --> time, x-command-voltage, y-command-voltage, x-feedback-voltage, y-feedback-voltage, x-error-voltage, and y-error-voltage).

 

I have been messing with this for days and while I can get various pieces of this to work (like read the analog inputs at 5khz while not doing anything with the analog outputs) I can't figure out how to manage both the analog output and input at the same time at different rates (analog out might be commanding at 1khz for one test and 3khz for another but the analog in needs to record at 5khz all the time). I'm also struggling with how to generate the data file.

 

I've attached an example input file for reference.

 

I've definitely done a lot of googling to try to find examples of this but I honestly haven't been able to find examples that have been helpful.  Any thoughts or guidance on where to find examples or help with the core code would be extremely appreciated! Thank you!

 

0 Kudos
Message 1 of 6
(2,137 Views)

Attaching the pieced together VI I'm trying to get to work...it's currently missing code to write the data to file because I'm struggling to understand how to manipulate waveforms.

0 Kudos
Message 2 of 6
(2,116 Views)

@needhelp2378 wrote:

I can't figure out how to manage both the analog output and input at the same time at different rates (analog out might be commanding at 1khz for one test and 3khz for another but the analog in needs to record at 5khz all the time).


You just need another control for the Analog Input data rate and wire that up to the AI DAQmx Timing VI.

 


@needhelp2378 wrote:

I'm also struggling with how to generate the data file.


By far, the simplest method is to use the DAQmx Configure Logging VI on your AI task before starting it.  That will configure DAQmx to stream the read data straight into a TDMS file.  If you have the extension installed (should come with LabVIEW), then you can still open the file in Excel.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 6
(2,039 Views)

Thank you crossrulz!

 

The latest VI is attached.  I think I may have figured a few things out (or at least I think I'm getting closer!) but can you (or anyone else) help me with the following?

  1. As soon as I run the VI it prompts me for the input file.  This is ok for now but I was hoping to have the VI constantly running, have a button to "load profile" and then have a separate button to "execute profile"...and have the VI keep running to the user can rinse/repeat.  How would I break the attached up to do this?
  2. Now that I figured out how to create a unique filename automatically the write loop starts running as soon as the profile is loaded.  This makes sense but for some reason there's a multi-second delay (something like 3 - 3.5 seconds) in the data it's displaying (screenshot attached).  The timer I added to the VI also never displays exactly 30 seconds (it's always slightly over 30 seconds) and this is also consistent in the data file it writes (example also attached).  What the heck am I doing wrong here?
  3. I can't seem to grasp fundamental chart concepts in labview despite playing with them over and over.  What I was hoping to have here was a chart that showed the 30 seconds the test should run (in this example) and then plot the data as the test goes along.  I tried zeroing out the timestamp but that doesn't seem to fix the problem.
  4. How do I get the time written to the data file to be written in fractional seconds and not some obscure time code (currently it shows up as "12/31/1903 4:00:01 PM" - example screenshot attached)?  Since I need to collect data up to 5khz I need something like 4 or 5 digits of precision and what I'm looking for is the first row of the data file to start at 0 seconds and then the next row at 0.001 sec, and then 0.002 sec, etc. (for 1kz and increments of 0.0002 for 5khz).
  5. Related to the above, if I subtract two timestamps in the data file from each other I get something like 0.000000011574 (units?).  Since the data in this example is being written at 1khz what the heck does this represent?

Thanks in advance for the help!

0 Kudos
Message 4 of 6
(2,018 Views)

New VI is attached:

  • I think I figured out the time discrepancy by putting everything in a stacked sequence (the ~3.5 seconds was the time it was taking to run the program up to the loop)
  • I changed my logging around to write to spreadsheet file instead of waveform and that seems to have fixed the timestamp issue.  With that said, there are a number of negative times at the beginning of the file that don't make sense to me (example attached) and it's recording more than 30 seconds of data...from start to finish it's recording 30.199 seconds (from -0.011628417 sec to 30.187371583 seconds) which also corresponds to 30,200 data points. Can someone help me understand what's going on here?
  • I could still use guidance on how I should break this up to implement the "button press" features so the VI stays running indefinitely and loads/runs the profile with button clicks.
0 Kudos
Message 5 of 6
(2,005 Views)

@needhelp2378 wrote:
  1. As soon as I run the VI it prompts me for the input file.  This is ok for now but I was hoping to have the VI constantly running, have a button to "load profile" and then have a separate button to "execute profile"...and have the VI keep running to the user can rinse/repeat.  How would I break the attached up to do this?

Make another VI that calls this VI.  The higher level VI could pass in the profile to run and keep looping until the user decides to stop.  A simple While Loop with an Event Structure would do the job.

 


@needhelp2378 wrote

2. Now that I figured out how to create a unique filename automatically the write loop starts running as soon as the profile is loaded.  This makes sense but for some reason there's a multi-second delay (something like 3 - 3.5 seconds) in the data it's displaying (screenshot attached).  The timer I added to the VI also never displays exactly 30 seconds (it's always slightly over 30 seconds) and this is also consistent in the data file it writes (example also attached).  What the heck am I doing wrong here?


Well, you do have a lot of setting up happening: read the file, set up the Analog Input, set up the Analog Output, load the Analog Output data, start the Analog Input task, Start the Analog Output task.  So the 3 seconds seems mostly reasonable to me, depending on the device you are using.

 

The over 30 seconds is just purely due to the fact that the Analog Input is not associated with the Analog Output.  The Input starts before the Output and it waits until the Output is done.  So if the output is exactly 30 seconds, the Input will definitely be more than 30 seconds.  This is not an issue.

 


@needhelp2378 wrote:

3.  I can't seem to grasp fundamental chart concepts in labview despite playing with them over and over.  What I was hoping to have here was a chart that showed the 30 seconds the test should run (in this example) and then plot the data as the test goes along.  I tried zeroing out the timestamp but that doesn't seem to fix the problem.


It is best to not mess with the timestamp from the waveform.  My recommendation would be to just wire the Read Chart directly to the output of the DAQmx Read.  You can change the format of the X-Axis to be "Relative Time".

 


@needhelp2378 wrote:
4. How do I get the time written to the data file to be written in fractional seconds and not some obscure time code (currently it shows up as "12/31/1903 4:00:01 PM" - example screenshot attached)?  Since I need to collect data up to 5khz I need something like 4 or 5 digits of precision and what I'm looking for is the first row of the data file to start at 0 seconds and then the next row at 0.001 sec, and then 0.002 sec, etc. (for 1kz and increments of 0.0002 for 5khz).

 

5. Related to the above, if I subtract two timestamps in the data file from each other I get something like 0.000000011574 (units?). Since the data in this example is being written at 1khz what the heck does this represent?


You are subtracting time stamps from 2 different sources.  Use the first read's T0 as your basis and subtract that value.  Then you can format the data however you need.

 

Other notes:

- You do NOT need the sequence structure.  Chain up your error clusters and that will serialize the steps (Data Flow).

- Your way of creating your log file name is way too complicated.  It can be greatly simplified by using a couple of tricks (the Build Path knows how to handle ".." as part of a relative path and you can do all of the string manipulation with the Format Date/Time String).

- You really should be considering breaking up this code into subVIs.  There is a lot that could be cleaned up that way and make it easier to understand.  Of course, use a project to organize your code as well.

 

I took a quick shot as cleaning up your code.  It is far from what I would release into the wild, but hopefully enough to get you going.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 6
(1,970 Views)