LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Looping move absolute position method - Thorlabs MLJ050 Motorized Lab Jack - Activex

I want to be able to specify an absolute position for the motor to go to and the number of steps to take, i.e. move a total of 20 mm in 2 steps, so the motor should move 10 mm, wait some amount of time, and move the last 10 mm. The user would specify the distance to move and the steps to take and then press a 'go' button. 

 

I am utilizing Thorlabs APT software (with LabVIEW 2016) with activeX methods: SetMoveAbsPos which sends a command to the MoveAbs method. However, I can't get the SetMoveAbsPos command to loop with the number of steps. With the attached VI, the behavior I am getting is that the position input from the user is updated every time the VI loops. For example, if the user inputs a position of 20 mm and do it in 2 steps (cycles control in the VI), it will go to 10 mm, then moves to 5 mm, and then to 2.5 mm, etc. I have tried different positions (inside vs outside the for loop) for the SetMoveAbsPos command and I have tried to initialize the position control outside the loop but I don't get the results I want: either the motor moves to position/steps and doesn't loop or I get erratic behavior. 

 

Is there anyway to somehow loop the SetMoveAbsPos method for the number of steps I want without it updating the user input position value?

Download All
0 Kudos
Message 1 of 7
(3,367 Views)

Perhaps the reason why it's being updated every time the VI loops is because you are writing to a position local variable which will then update the position to a new value with each iteration. Try running the code in highlight execution to examine if this is the case.

0 Kudos
Message 2 of 7
(3,249 Views)

That's exactly what happens. However, if I remove that local variable, then the for loop doesn't loop at all after the initial iteration. I think this is because the SetAbsMovePos commands the motor to move to a position of input position/cycles. In the next iteration, the motor gets the same command but won't move because it is already at a position of input position/cycles. Is there a way to overcome this? Or any way to tell the motor to move a certain distance instead of to a certain position - I know this is limited by my use of activex methods but I don't have any other way to communicate with this motor. 

0 Kudos
Message 3 of 7
(3,241 Views)

I'm assuming there is only an absolute position option on that invoke node and no relative position option. If so, what if you multiplied by 2*cycles before storing to the local variable? So if you want to move to 20 in two steps, the first iteration would be 20/2= position of 10, and then this value would multiply by 2*2= 40, and then this would divide by 2 on the next iteration to give 20 as the final position. The for loop should only iterate twice for two cycles. This would only work for position/cycles that = whole numbers. But perhaps you can implement some similar logic for all cases.

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

This is on the right track and the closest I've gotten to the behavior that I want, but it only seems to work if the number of cycles=2. Otherwise the motor overshoots the final position or writes a position input that is larger than the maximum range of the motor. I've tested with multiple values of position and cycles and it works perfectly if position/cycles is a whole number (like you said) and if cycles=2. Even a position of 9 and cycles=3 does not work. 

0 Kudos
Message 5 of 7
(3,224 Views)

You're right, any cycle number greater than 2 will cause an overshoot. A position of 9 and cycles of 3 would cause an overshoot to 12 on the third step. There must be some sort of algorithm you can implement to handle any number of cycles. It would probably take doing some algebra. 

0 Kudos
Message 6 of 7
(3,215 Views)

Turns out activex has another method where I can specify a relative distance instead of an absolute position. If I don't write the position from the SetRelativeMoveDistance method to the local position variable, any combination of steps and distances work. Thanks so much for your help!

0 Kudos
Message 7 of 7
(3,197 Views)