No BSD License  

Highlights from
Stepper Motor ToolBox for MatLab v1.0

from Stepper Motor ToolBox for MatLab v1.0 by Sergio Alejandro González
Stepper Motor ToolBox for MatLab v1.0

Demo4.m
%
%Demo 4
% esto es para repara lo del Paper Modelo

% General definitions
%
SR = 100;			% Step-rate, maximun speed for the profiles
g  = 0;				% [pps] : minimun speed
k  = g/SR; 			% normalized minimun speed
Q = 8;				% Quantization level
step = 1/(SR*Q);		% [s]: the simulation step.
				% 1 de cada 8 unidades de velocidad maxima
% Profile definitions
%
to = 0;				% [s]: Simulation starting time
Kv = 1;				% normalized max speed of profile
Tn = 0.05;			% Tn = null time
Ta = 0.45;			% Ta = ascending time
Ts = 0.10;			% Ts = slew time
Td = 0.45;			% Ta = descending time
tf = 2*Tn+Ta+Ts+Td;		% [s]: Simulation ending time
pts = fix(tf/step);
% Profiles generation
% profiles(pts,to,tf,f,step,Kv,Ta,Tn,Ts,Td,k,'triangular');
[prof] = profiles(fix(tf/step),to,tf,0,step,SR,Ta,Tn,Ts,Td,k,'trapezoidal');
t_orig = [tf/length(prof):tf/length(prof):tf];
plot(t_orig, prof), grid on;


% Voltage definitions
%
Vh = 5;
Vl = 0;

% Step-rate generation
%
Ti = 120e-6;			% [s]: the procesing time.
[fo, velpro] = srgenerator(prof,fix(tf/step),SR,step,Vl,Vh,Ti,to,tf,Tn);

% Velocity Profiles analysis:
% 
figure;
tiempo = [tf/length(velpro):tf/length(velpro):tf];
t_orig = [tf/length(prof):tf/length(prof):tf];
title(['Perfil de velocidad, V_{mx} = ', num2str(SR),' p/s, V_{mn} = ', num2str(g),'p/s, T_{i} = ', num2str(Ti), ' s.']);
hold on
plot(tiempo, velpro, t_orig, SR*prof), grid on;
axis([to tf+.02*tf -.05*max(SR*prof) 1.05*max(SR*prof)]), ylabel('Pasos/s'), xlabel('Tiempo, [s]');
hold off

% ----------------------------------------------------------------------------------------------

% Definitions
%
W  = 5;			% [A] : in this case, current mode output.
Tvs  = 1;		% [s] : minimun step size

% Power generation 
%
[Wa, Wb] = powerwaves(fo,Vh,Vl,Tvs,W);


figure;
plot(tiempo, Wa), grid on;

% ----------------------------------------------------------------------------------------------




%figure(2);
%plot([0:step:tf-step], velpro,'g-', [0:step:tf-step], SR*prof,'r-');
%plot([0:Ti:tf-Ti], velpro,'g-', [0:Ti:tf-Ti], SR*prof,'r-');

% Analisis of velocity profiles :
% 
tiempo = [tf/length(velpro):tf/length(velpro):tf];
t_orig = [tf/length(prof):tf/length(prof):tf];
title(['Perfil de velocidad, V_{mx} = ', num2str(SR),' p/s, V_{mn} = ', num2str(g),'p/s, T_{i} = ', num2str(Ti), ' s.']);
hold on
figure('DefaultAxesColorOrder', [0 0 0], 'DefaultAxesLineStyleOrder', '-|:|--|-.');
plot(tiempo, velpro, t_orig, SR*prof), grid on;
axis([to tf+.02*tf -.05*max(SR*prof) 1.05*max(SR*prof)]), ylabel('Pasos/s'), xlabel('Tiempo, [s]');
hold off
% Analisis of motion profiles :
% 
pos = cumsum(velpro);						% CUMSUM = Cumulative sum
plot(tiempo, Ti*pos, '--'), grid on;
hold
% Analisis of profiles derivatives:
% 
derive(SR*prof,to,tf,SR,step);
derivadas(velpro,to,tf,SR,Ti);


%
% Stepper motor constants :
%

%km=.38; % km/c = d.c. gain.
%D= .90; % parameter related to the rotational inertia and viscous
         % breaking coeficcinet.
%J= 10;  % magnetic and electric constant.

%L=1.11*10^(-3);        
 
%r=1.5;

% Coeficientes con que entro en la funcion Stepper
% p,n,Flux,lambda
%

%p=1;
%n=20;
%Flux=0.18;
%lambda=1.12;

% 
% Simulacion:
% New Code
%	2*pi/(4*p)
p = 200;		% numero de pasos del moot
%t 			= [0:step:tf-step];			% time vector
%t 			= [0:step:tf-2*step];			% time vector
tol 		= 1e-4;
t 			= [0:Ti:tf-2*Ti];			% time vector
t 			= [0:Ti:tf-Ti];			% time vector
%tol 		= 1e-2;
minstep 	= step;
maxstep 	= step;
Timespan = [to tf];
x  = [t' Va' Vb'];           % Vector de variables de entrada
%y  = [th' w' ia' ib'];
x0 = [0 0];          % se definen las condiciones iniciales:
Options = SIMSET('MaxOrder', 5,'RelTol',tol,'AbsTol', tol,...
   'MaxStep', maxstep,'InitialStep',step, 'InitialState', x0);
[t,x,y] = sim('stepperi', Timespan, Options);
%save stepper

plot(t,th*4*p/(2*pi), '-'), grid on;
hold
title(['Posicin. V_{mx} = ', num2str(SR),' sps. T_{i} = ', num2str(Ti), ' s.']);
ylabel('Pasos'), xlabel('Tiempo, [s]');

% resamplear para la resta
% thetha([1:1:length(tiempo)]) = th([1:(length(t)/length(tiempo)):length(t)])*4*p/(2*pi);
% resta([1:1:length(tiempo)]) = Ti*pos([1:1:length(tiempo)]) - thetha([1:1:length(tiempo)])'; 
thetemp = resamcon(th,t,length(tiempo)/(2*pi*110*length(th)));				% Resampleo
thetha([1:1:length(tiempo)]) = thetemp([1:(length(thetemp)/length(tiempo)):length(thetemp)])*4*p/(2*pi);
resta = Ti*pos - thetha;
plot(tiempo, resta, '-.'), grid on;


% Pruebas con Ti = 20 us
Ti = 20e-6;
[fo, velpro] = srgenerator(prof,pts+1,SR,step,Vl,Vh,Ti,to,tf,Tn);
% Analisis of motion profiles :
% 
tiempo = [tf/length(velpro):tf/length(velpro):tf];
title(['Perfil de velocidad, V_{mx} = ', num2str(SR),' p/s, V_{mn} = ', num2str(g),'p/s, T_{i} = ', num2str(Ti), ' s.']);
hold on
figure('DefaultAxesColorOrder', [0 0 0], 'DefaultAxesLineStyleOrder', '-|:|--|-.');
axis([to tf+.02*tf -.05*max(SR*prof) 1.05*max(SR*prof)]), ylabel('Pasos/s'), xlabel('Tiempo, [s]');
hold off
% Analisis of motion profiles :
% 
pos = cumsum(velpro);						% CUMSUM = Cumulative sum
plot(tiempo, Ti*pos, '--'), grid on;
hold
% Analisis of profiles derivatives:
% 
derivadas(SR*prof,to,tf,SR,step);
derivadas(velpro,to,tf,SR,step);


% ----------------------------------------------------------------------------------------------

%
% Stepper motor constants :
%

M = 0.20;					% mutual inductance
n = 40;                 % nwinding turns
p = 200;                % number of steps per rev.
km = 0.157;				% motor constant: km = p*n*Flux.
d  = (8e-4)*5;			% viscous damping coefficient (8e-4)*5 ok es todo lo que
							% se hizo previamente d=8e-4 y J=1.6 (2'26'')							%d  = 5*(3.4e-4);					% viscous damping coefficient (8e-4)*5 ok
L = 1.1e-3;
r = 1.5;
jota = 1.7e-5;			% damped respone 29-1-99
i = 1;
param =  [ p, d, M, L, r, km, jota, n, i];
% 
% Simulation:
% These code uses Matlab v5 sintaxis
%
%t 	 = [0:Ti:tf-2*Ti];			% time vector
t	 = [0:tf/length(Wa):tf-tf/length(Wa)];
tol 	 = 1e-4;
minstep  = step;
maxstep  = step;
Timespan = [to tf];
x  = [t' Wa' Wb'];           % Vector de variables de entrada
x0 = [ 0 0 ];          % se definen las condiciones iniciales:
%x0 = [0 0 0 0 ];          % se definen las condiciones iniciales:
Options = SIMSET('MaxOrder', 5,'RelTol',tol,'AbsTol', tol,...
   'MaxStep', maxstep,'InitialStep',step, 'InitialState', x0);
[t,x,y] = sim('stepper', Timespan, Options);
save stepper

plot(t, th*4*p/(2*pi)), grid on;
hold
title(['Posicin. V_{mx} = ', num2str(SR),' sps. ']);
ylabel('Pasos'), xlabel('Tiempo, [s]');

% ----------------------------------------------------------------------------------------------

plot(t,th*4*p/(2*pi), '-'), grid on;
hold
title(['Posicin. V_{mx} = ', num2str(SR),' sps. T_{i} = ', num2str(Ti), ' s.']);
ylabel('Pasos'), xlabel('Tiempo, [s]');

% resamplear para la resta
thetha	= zeros(1, length(tiempo));
resta	= zeros(1, length(tiempo));
%thetha([1:1:length(tiempo)]) = th([1:(length(t)/length(tiempo)):length(t)])*4*p/(2*pi);
%resta([1:1:length(tiempo)]) = Ti*pos([1:1:length(tiempo)]) - thetha([1:1:length(tiempo)])'; 
thetemp = resamcon(th,t,length(tiempo)/(2*pi*110*length(th)));				% Resampleo
thetha([1:1:length(tiempo)-1]) = thetemp([1:(length(thetemp)/length(tiempo)):length(thetemp)])*4*p/(2*pi);
resta = Ti*pos - thetha;
plot(tiempo, resta, '-.'), grid on;
plot(resta, '-.'), grid on;

% fin del paper

Contact us at files@mathworks.com