Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- % Given:
- A=500; % acceleration mm/sec^2
- D=-500; % deceleration mm/sec^2
- F=100; % feedrate (velocity) mm/sec
- L=50; % travel length mm
- Ts=0.001; % sampling period sec
- T1=F/A; % from equation 2
- T3=-F/D; % from equation 3
- T2=L/F - (T1+T3)/2; % from equation 4
- if T1<0 || T2<0 || T3<0 % kinematic compatibility conditions
- disp('Error: acceleration, deceleration and travel length are not kinematically compatible.');
- else
- tau1=0:Ts:T1; % create row vector for time, initial time : step size : final time
- tau2=0:Ts:T2;
- tau3=0:Ts:T3;
- % preallocate array for speed
- s1=zeros(1,length(tau1)); sd1=zeros(1,length(tau1)); sdd1=zeros(1,length(tau1));
- s2=zeros(1,length(tau2)); sd2=zeros(1,length(tau2)); sdd2=zeros(1,length(tau2));
- s3=zeros(1,length(tau3)); sd3=zeros(1,length(tau3)); sdd3=zeros(1,length(tau3));
- % from equation 1
- for index=1:length(tau1)
- s1(index)=F*tau1(index)*tau1(index)/2/T1;
- end
- for index=1:length(tau2)
- s2(index)=F*tau2(index) + F*T1/2;
- end
- for index=1:length(tau3)
- s3(index)=-F*tau3(index)*tau3(index)/2/T3 + F*tau3(index) + L - F*T3/2;
- end
- end
- t1=tau1'; % change tau1 from a row vector to a column vector tau1'
- t2=tau2(2:end)' + T1; % shift bounds and drop first vector element
- t3=tau3(2:end)' + T1 + T2;
- t = [t1;t2;t3]; % concatenation of time vector
- s1=s1';
- s2=s2(2:end)';
- s3=s3(2:end)';
- s = [s1;s2;s3]; % concatenation of trajectory vector
- s_new = [s; 50 * ones(300,1); flipud(s); zeros(299,1)];
- t_new = [0:0.001:2]';
- simin = [t_new s_new];
- %
- figure(1)
- plot(t_new, s_new)
- %
- t=ScopeData.time;
- x=ScopeData.signals.values;
- u=ScopeData1.signals.values;
- xr=ScopeData2.signals.values;
- data=[t xr x u];
- save lab2_q3.txt -ASCII -double data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement