How to read positions in Matlab

449 views
Skip to first unread message

Nancy

unread,
Jan 29, 2013, 7:42:15 AM1/29/13
to velmex-...@googlegroups.com
Hi I am using model PK266-03A-P1 right now, what is the advance per step? Is it 0.0025 mm? What command should I use if I want to change this value? Is this model UniSlide or XSlide?

I am using Matlab to control the linear stage now and I can read out the every positions of the linear stage as it moves. The problem is that I need to wait some time after each linear stage movement if I want to read the positions correctly. The waiting time is proportional to the acceleration, speed and step-lengths. So it takes quite a long time to finish a for loop. Do you have Matlab codes that are very efficient to read the position values?

VelmexControls

unread,
Jan 29, 2013, 8:45:14 AM1/29/13
to velmex-...@googlegroups.com
Hi Nancy,
The step size would depend on the model of the slide (there should be a sticker on the slide itself saying what it is)

I do not really work with Matlab but the back of my mind says that Matlab default timeout for the serial port is (ridiculous value in my mind) of 10 seconds.
Some googling and I did find this link saying the same thing that I was thinking of.
Matlab Serial Port Timeout

I have not found any documentation to the point but I think what you want to do is
s = serial('COM1');
set(s,'Timeout',10);
fopen(s)

Be aware the value of 10 might already be mean 10 seconds as I am unaware what units are used? (Seconds? MilliSeconds?)

Using the driver its a breeze cause it is optimized to return as soon as it has finished getting the position

Nancy

unread,
Jan 30, 2013, 4:02:10 AM1/30/13
to velmex-...@googlegroups.com

Hi Thanks for your help.
I do find out the motor is Bslide and speed is 1.8degree/step. What does 1.8degree/step mean? And I also want to ask how can i force velmex to stop in Matlab for loop? I used fclose(), but it didn't work.

VelmexControls

unread,
Jan 30, 2013, 8:30:07 AM1/30/13
to velmex-...@googlegroups.com
1.8 degrees per step is 1.8 degrees per step of the motor (However the VXM is a "Half-Stepper" so consider the motor as 0.9 degrees per step)
You can determine the linear step size from the BiSlide model number (see Users Manual) and look up the advance per turn in the VXM manual P.11
                    Pitch     Adv/Rev     Adv/Step                Desired travel
For Instance: E04       0.4 inch     0.0010000 inch       1inch = 1000 steps


If you send a capital "K" that will kill the currently running program.


Nancy

unread,
Jan 30, 2013, 9:44:09 AM1/30/13
to velmex-...@googlegroups.com
Hi Sorry I didn't specify my question clearly.
I am curious about how much in mm/step does 1.8degree/step correspond to.
I tried command K before, but unfortunately it didn't work.
Thanks.

VelmexControls

unread,
Jan 30, 2013, 10:27:33 AM1/30/13
to velmex-...@googlegroups.com
Nancy, Part of the BiSlide Model would be one of the models below

From VXM Users Manual P.11

BiSlide**         Advance per turn         Advance per step
E25                0.025 inch                  0.0000625 inch
E50                0.05 inch                    0.0001250 inch
E01                0.1 inch                      0.0002500 inch
E02                0.2 inch                     0.0005000 inch

E04                0.4 inch                     0.0010000 inch
M01               1 mm                         0.0025 mm
M02               2 mm                         0.0050 mm

To convert from "real" units to steps, divide the distance desired to move by the Advance per step.
(Distance ÷ Adv per step = Steps)

For instance 1mm  / 0.0025 mm = 400 steps

Also, sending the "K" only kills the currently running VXM program, not your loop. You have to write some kind of conditional statement to break out of your loop.

Nancy

unread,
Jan 31, 2013, 7:19:34 AM1/31/13
to velmex-...@googlegroups.com
Hi Thank you for the reply. I didn't find the exact model of my BiSlide motor stepper, only have this information:PK266-03A-P1. Is it M01 or M02? I measured 1000 steps today and the absolute moving distance is 6mm, so each advance per step is 0.006mm, does it mean the model of this machine is M02(which have advance per step 0.005mm)?
Another question is, yesterday I moved the motor stepper by 3000 step, today I also moved it by 3000 step, every conditions I used is the same, and the absolute moving distance of the 3000 steps yesterday is quite different from the absolute moving distance of the 3000 steps today. Does it mean the advance per step can be changed? (which is very strange, because I didn't change anything).


Regards
Nancy

VelmexControls

unread,
Jan 31, 2013, 8:56:02 AM1/31/13
to velmex-...@googlegroups.com
Nancy,
Numbers starting with "PK" found on the motor are the model of the motor, not the slide.
Numbers starting with "MN" found on the side of the slide are the model of the slide
As seen in the attached picture taken from the BiSlide Users Manual P.2

Step size does not change in the VXM (a step is a step), If you give the correct number of steps you will travel the correct distance

If you look at the label on the side of the slide you will see 2 numbers (one will start with "CO" and the other will start with "MN")
If you post those 2 numbers I can tell you exactly what you have.
Bislide Model Numbers.png

Nancy

unread,
Feb 2, 2013, 4:19:26 PM2/2/13
to velmex-...@googlegroups.com
On Tuesday, January 29, 2013 2:45:14 PM UTC+1, VelmexControls wrote:

Hi Thank you for the information. I searched internet but didn't find anything useful. I tried to read the position in Matlab, but it take a waiting time for me to get the correct position. The waiting time is related to the speed, acceleration and step length. I wonder if a waiting time is also needed in Labview if I want to read correct position? My boss think the waiting time is too long and unacceptable. Do you have any thoughts to solve it?
/Nancy

Charles Emrick

unread,
Feb 2, 2013, 5:00:11 PM2/2/13
to velmex-...@googlegroups.com
Nancy,
I am unsure how this delay is proportional to speed and distance and accel? Unless you mean if the delay is 10 seconds and you move in 2 seconds, you have to wait for 8 seconds, but if the move is 5 seconds you only have to wait 5 seconds?

either way, its still really 10seconds of waiting (you just do not notice it cause something is happening during the first part of the time-slice

All languages have (or should have) a setting for timing out if an answer is not found. This is determined in some languages by seeing a particular character or characters indicating that it is the end of the transmission.

For example. Labview has a Line-Terminator (I think it is <CR><LF>) but also has a setting to ignore the timeout, or to change the timeout

Matlab I have not found docs to similar but they have to exist (REALLLY BADD PROGRAMMING if there is not one), but since most people do not question it then its hard to find an answer.

If you can post code to show what you are doing that would help tremendously in solving the problem

Nancy

unread,
Feb 3, 2013, 5:23:26 PM2/3/13
to velmex-...@googlegroups.com


Hi Charles, Thank you for your reply.
In the following matlab code what I did was to move the motor 1 for 2000 step and then read out the position value. There is a pause(t) inbetween, which is necessary if I want to read out position correctly.
fprintf(obj1,'C,I1M2000,R');
pause(t) % again pause is needed
fprintf(obj1,'X');

t(pause time) is related to speed,accerlaration and step length in a way just as what we did in high school physics.
For example, speed = 2000 step/s, accerlaration = 3 ( which is corresponding to a=12000 stpes/s^2 and initial speed = 190), step length = 2000, if we refer to Note#106 (a document on velmex homepage regarding accerlaration) we get t=0.405s. It is like we need to wait for the machine to stop and then we can readout the value. But in reality, the waiting time is obviously larger than 0.45s, it is like I have to wait about 5 seconds after the motor stopped for matlab to read out the position.

Matlab code for reading out pause (t)
v = 2000; % Velocity which we difined with S1M2000
a = 12000;
v_0 = 190;
d = 500; %length of each step, for simlicity we use the same value for all axis movement.
t1 = v/a;
d1 = v_0*t1+0.5*a*t1^2;
t_margin = 0.02;
if d1<d/2 %trapezoidal profile
t2 = (d-2*d1)/v;
t = 2*t1+t2+t_margin;
else %triangular profile
f = @(x)0.5*a*x^2+190*x-d/2;
t2 = fzero(f,0);
t = 2*t2+t_margin;
end

Just like you said, if Matlab has this timeout problem (10 second?) that's a lot. What can I do?


VelmexControls

unread,
Feb 4, 2013, 9:20:43 AM2/4/13
to velmex-...@googlegroups.com
This took me a lot of time to figure out since I have yet to find documentation to all the parameters available to be set using the serial port. However I have figured out how to change the timeout.

 System1 = serial('Com1','Baudrate',9600,'DataBits',8,'Parity','none','StopBits',1,'Terminator','','Timeout',0.1);     %Change timeout to 100ms
fopen(System1);
fwrite(System1,'X');
fread(System1,System1.BytesAvailable);
Position = fread(System1,System1.BytesAvailable);
fclose(System1);

I believe 10seconds is ridiculous value for a timeout, but can see its use

Let me know how it works out.

Nancy

unread,
Feb 4, 2013, 11:32:57 AM2/4/13
to velmex-...@googlegroups.com


Hi I found out the slide model is MN10-0500-E01-21. E01 means per 1000 step the advance will be 0.125inch(3.175mm). Is it right? Thanks!

VelmexControls

unread,
Feb 4, 2013, 11:40:11 AM2/4/13
to velmex-...@googlegroups.com
Nancy,
From your earlier post

Hi I found out the slide model is MN10-0500-E01-21. E01 means per 1000 step the advance will be 0.125inch(3.175mm). Is it right? Thanks!

The E01 part means 0.1 inch/Rev (0.00025 inch/step) meaning 1000 steps would move 0.25 inches

Nancy

unread,
Feb 5, 2013, 11:32:09 AM2/5/13
to velmex-...@googlegroups.com

Now I am confused. I looked up in the document 'table for advance per turn for VXM M motor' and found that E01 is corresponding to 0.125inch for 1000 step...

/Nancy

Nancy

unread,
Feb 5, 2013, 11:41:54 AM2/5/13
to velmex-...@googlegroups.com
Hi I tried, but it didn't work. Here is my code.


% Find a serial port object.
obj = serial('COM3', 'Baudrate',9600,'DataBits',8,'Parity','none','StopBits',1,'Terminator','','Timeout',0.1)
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj)
obj = serial('COM3');
else
fclose(obj);
obj = obj(1)
end

% Connect to instrument object, obj1.
fopen(obj);

fprintf(obj,'C,I1M100,R')

fwrite(obj,'X');
Position = fread(obj,'%s',14);

fclose(obj)



Nancy

unread,
Feb 5, 2013, 11:49:33 AM2/5/13
to velmex-...@googlegroups.com
On Monday, February 4, 2013 3:20:43 PM UTC+1, VelmexControls wrote:
I also tried the following matlab code. I have a vxm-1-1 to control the X,Z linear stage. I want to move the linear stage in X direction first and then in Z direction. But it only moves in X direction after I run the code. What is the problem in the code? Thanks.

% Find a serial port object.
obj = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');

% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj)
obj = serial('COM3');
else
fclose(obj);
obj = obj(1)
end

% Connect to instrument object, obj1.
fopen(obj);


fprintf(obj,'C,I1M1000,R')
fprintf(obj,'C,I3M-1000,R')

fclose(obj)





Charles Emrick

unread,
Feb 5, 2013, 1:26:04 PM2/5/13
to
Nancy your confusion above is that you are reading the wrong line, you read the E50 line and not the EO1 line like pointed out earlier

From VXM Users Manual P.11

BiSlide**         Advance per turn         Advance per step
E25                0.025 inch                  0.0000625 inch
E50                0.05 inch                    0.0001250 inch
E01                0.1 inch                      0.0002500 inch
E02                0.2 inch                     0.0005000 inch

E04                0.4 inch                     0.0010000 inch
M01               1 mm                         0.0025 mm
M02               2 mm                         0.0050 mm

 
Also the code posted above works fine because only 1 character is sent and being responded to before the timeout of the read.
System1 = Serial('Com1','Baudrate',9600,'DataBits',8,'Parity','none','StopBits',1,'Terminator','','Timeout',0.1);     %Change timeout to 100ms

fopen(System1);
fwrite(System1,'X');
fread(System1,System1.BytesAvailable);
Position = fread(System1,System1.BytesAvailable);     %Times out if no bytes available
fclose(System1);
 
Your code of:

% Find a serial port object.

obj = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
% Create the serial port object if it does not exist

% otherwise use the object that was found.
if isempty(obj)
    obj = serial('COM3');
else
    fclose(obj);
    obj = obj(1)
end
% Connect to instrument object, obj1.
fopen(obj);
fprintf(obj,'C,I1M1000,R')
%You are not waiting for the motion to end so this next line is tossed away
%By the control cause it is already moving a motor

fprintf(obj,'C,I3M-1000,R')
fclose(obj)

Moderator Edit to point out details

Nancy

unread,
Feb 5, 2013, 6:53:18 PM2/5/13
to
Post:           
      E01                0.1 inch                      0.0002500 inch

Response:    
     Yes, in the document your gave it is indeed 0.25inch/1000steps.
     I read another document, in which the advance per step is wrong written.


Post:
     (See code above)
 

Response:    
     Yes, I could possibly read out the position by using these code without movement.
     However, I wanted  to move the stage before reading out the position, which can't be done with these code.
     I will try again tomorrow to see how it works.


Post:(Example code for finding port)
Response:  
     Does it mean I need  to initiate the motor every time I use fprintf(obj,'C,ImMx,R') in Matlab?
     Thanks a lot for your help!

Nancy

unread,
Feb 6, 2013, 8:25:55 AM2/6/13
to velmex-...@googlegroups.com
Hi I have solved my problems. Thank you very much!!!

/Nancy
Reply all
Reply to author
Forward
Message has been deleted
0 new messages