Advertisement
Guest User

2

a guest
Oct 10th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.80 KB | None | 0 0
  1. clc;
  2. % Given:
  3. A=500; % acceleration mm/sec^2
  4. D=-500; % deceleration mm/sec^2
  5. F=100; % feedrate (velocity) mm/sec
  6. L=50; % travel length mm
  7. Ts=0.001; % sampling period sec
  8.  
  9. T1=F/A; % from equation 2
  10. T3=-F/D; % from equation 3
  11. T2=L/F - (T1+T3)/2; % from equation 4
  12.  
  13. if T1<0 || T2<0 || T3<0 % kinematic compatibility conditions
  14.     disp('Error: acceleration, deceleration and travel length are not kinematically compatible.');
  15. else
  16.     tau1=0:Ts:T1; % create row vector for time, initial time : step size : final time
  17.     tau2=0:Ts:T2;
  18.     tau3=0:Ts:T3;
  19.    
  20.     % preallocate array for speed
  21.     s1=zeros(1,length(tau1));    sd1=zeros(1,length(tau1));    sdd1=zeros(1,length(tau1));
  22.     s2=zeros(1,length(tau2));    sd2=zeros(1,length(tau2));    sdd2=zeros(1,length(tau2));
  23.     s3=zeros(1,length(tau3));    sd3=zeros(1,length(tau3));    sdd3=zeros(1,length(tau3));
  24.    
  25.    % from equation 1
  26.     for index=1:length(tau1)
  27.         s1(index)=F*tau1(index)*tau1(index)/2/T1;
  28.     end
  29.     for index=1:length(tau2)
  30.         s2(index)=F*tau2(index) + F*T1/2;
  31.     end
  32.     for index=1:length(tau3)
  33.         s3(index)=-F*tau3(index)*tau3(index)/2/T3 + F*tau3(index) + L - F*T3/2;
  34.     end
  35. end
  36.  
  37. t1=tau1'; % change tau1 from a row vector to a column vector tau1'
  38. t2=tau2(2:end)' + T1; % shift bounds and drop first vector element
  39. t3=tau3(2:end)' + T1 + T2;
  40. t = [t1;t2;t3]; % concatenation of time vector
  41.  
  42. s1=s1';
  43. s2=s2(2:end)';
  44. s3=s3(2:end)';
  45. s = [s1;s2;s3]; % concatenation of trajectory vector
  46.  
  47. s_new = [s; 50 * ones(300,1); flipud(s); zeros(299,1)];
  48. t_new = [0:0.001:2]';
  49. simin = [t_new s_new];
  50.  
  51. %
  52. figure(1)
  53. plot(t_new, s_new)
  54.  
  55. %
  56. t=ScopeData.time;
  57. x=ScopeData.signals.values;
  58. u=ScopeData1.signals.values;
  59. xr=ScopeData2.signals.values;
  60. data=[t xr x u];
  61. save lab2_q3.txt -ASCII -double data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement