LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't control sampling rate - ThorLabs Motor ActiveX Control

Hi all,

 

I am trying to use ActiveX control to collect displacement values from a ThorLabs Z-Motor at a rate of 5 Hz. The controller I am using is a KDC101. I will performing cyclic tension tests by moving the motor up and down, and I have written a bit of code that I have attached to do this.

 

The way my code is structured is I have an event that performs one test, outputs the displacement vs. time graphs, and eventually I want to save the displacements to a file (which I will add at a later time).

 

I can run this code fine without putting a sampling rate and letting the motor go on its own, but as soon as I change the rate to <10 Hz, the motor does not move back down and the event never stops. The waveform also keeps going and the motor does not attempt to move back down, and basically the program is no good. 

 

I am wondering if there is a different way to enforce this 5 Hz I need, and if anyone else has experienced similar issues? 

 

I have attached my VI that I am using to move the motor up and down once.

 

0 Kudos
Message 1 of 7
(939 Views)

Hi,

 

I took a look at your code.  I don't have your hardware, so I can't know for sure what's going on, but here are a few tips.  I highly suspect that your code is getting stuck in the first while loop ... the stop condition probably isn't being met.  Currently you have it as: "exit the loop when the position delta is less than or equal to 0.01..."  I would use probes to debug the VI in real-time, to see what values are in the wires.  Because the 1st loop isn't exited, therefore the motor doesn't come back down, the event doesn't stop, etc.

 

BR

John


Add motion to LabVIEW in 30min or less - TENET EMotion

Finding it hard to source NI hardware? Try NI Trading Post

 

0 Kudos
Message 2 of 7
(898 Views)

I've used Thorlabs motion control before.  Instead of checking to see if the motor position is close to the destination to decide to finish your loop, you should use the MoveComplete event.

 

Thorlabs has a guide on this, with Events being in chapter 7:

https://www.thorlabs.com/images/TabImages/GuideToLabVIEWandAPT.pdf

 

You just need to replace the dialog box that says "Move complete on channel" with a signal to stop the While loop.

Message 3 of 7
(862 Views)

Thank you very much! This makes sense, and I was wondering if this might have anything to do with the code. 

 

I just have one more question. I have developed the sub-VI for this code, but how did you go about replacing the "Move complete on channel " with a signal? I guess I am just wondering how to turn this into a boolean, and reference in the main VI. I've attached my subVI that I created with the ThorLabs user guide.

 

Many thanks again!

0 Kudos
Message 4 of 7
(848 Views)

The simplest way would be to use a Boolean Global variable, but Globals can end up causing big problems the larger your program gets.  You can find tons of people in LabVIEW or any other programming language telling you not to use them.

 

LabVIEW has a number of other messaging options you could look into if you want to do this more properly:

  • Channel wires
  • Notifiers
  • Functional global variables
Message 5 of 7
(844 Views)

Hi all,

 

I'm sorry to say that using the Move Complete Event did not change anything regarding my original question about the sampling rate. When I change the rate to 5 Hz, my waveform is extremely slow, and the motor does not move back up as commanded in the VI I posted above.

 

When you used ThorLabs motion control, was there a way you controlled the amount of data points you obtained? The weird part is, whenever I don't enforce a frequency, the motor does just fine and outputs ~66 Hz naturally, but has trouble sampling anywhere below 10 Hz. I felt like it should have been the opposite, but I might be missing something here?

 

My current code is the same as above, I just have the Move Complete event stopping the while loop.

 

Thanks in advance for your help! 

0 Kudos
Message 6 of 7
(785 Views)

Have you considered just using decimation?  Sample at 50 Hz and discard every 9 out of 10 samples, or some other multiple of 5 and just discard the unneeded ones.

0 Kudos
Message 7 of 7
(777 Views)