Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. % Bike Suspension Model - Project 1
  2. % Coded by: Kevin Abrahamson, Calvin Delbrueck, Trent Pearson
  3.  
  4. clear; clc
  5.  
  6. m = 90; % Slugs (accounts for both wheels)
  7. I = 10000; % THIS NEEDS TO BE CHANGED
  8. k = 352; % Spring rate constant lbf/ft
  9. c = sqrt(k*m); % Spring damper constant lbf/ft
  10. D = 29/12; % Diameter of wheel inches/12 (ft)
  11. d = 0.50; % shock distance from com (m)
  12. g = 9.8; % m/s^2
  13. track = @(x) 0.15*sin(x); % Bike track
  14.  
  15. % Domain Size
  16. Lt=100; % Length of track
  17. h=0.01; % Step-size
  18.  
  19. % Number of steps
  20. N=round(Lt/h); % Number of times to go through loop
  21.  
  22. % Preallocate arrays
  23. t=zeros(1,N);
  24. x=zeros(1,N); % position of COm on x direction
  25. Vx=zeros(1,N); % shock length accel
  26. y=zeros(1,N); % position of com in y dierction
  27. Vy=zeros(1,N); % shock length accel
  28. th=zeros(1,N); % angular position
  29. Vth=zeros(1,N); % angular accel
  30.  
  31. % Initial Conditions
  32. t(1) = 0; % Start at time 0
  33. SLx(1) = 0; % Shock length in x-direction
  34. SLy(1) = 1; % Shock length in y-direction
  35. xF(1) = 1;
  36. xR(1) = 0;
  37. yR(1) = 0;
  38. yF(1) = 0;
  39. th(1) = 0;
  40. x(1) = 0;
  41. Vx(1) = 2;
  42. y(1) = 0;
  43. Vy(1) = 0;
  44. th(1) = 0;
  45. Vth(1) = 0;
  46.  
  47. %Loop over track
  48. for i=1:N
  49. % Update time
  50. t(i+1)=t(i)+h;
  51.  
  52. % Update shock length
  53.  
  54. % Shock length of front shock in the x-direction, min function keeps SL within bounds
  55. slxf(i+1)= min(SLx(1),sin(th(i))* shock_length(xF(i),yF(i),th(i),track,D));
  56.  
  57. % Shock length of front shock in the y-direction, min function keeps SL within bounds
  58. slyf(i+1)= min(SLy(1),cos(th(i))* shock_length(xF(i),yF(i),th(i),track,D));
  59.  
  60. % Shock length of rear shock in the y-direction, min function keeps SL within bounds
  61. slxr(i+1)= min(SLx(1), sin(th(i))* shock_length(xR(i),yR(i),th(i),track,D)); % shock_length(xo,yo,th,T,D)
  62.  
  63. % Shock length of rear shock in the y-direction, min function keeps SL within bounds
  64. slyr(i+1)= min(SLy(1), cos(th(i))* shock_length(xR(i),yR(i),th(i),track,D));
  65.  
  66. % dL/dt for front and rear shocks in x and y-directions
  67. vxf=(slxf(i+1)-slxf(i))/h;
  68. vxr=(slxr(i+1)-slxr(i))/h;
  69. vyf=(slyf(i+1)-slyf(i))/h;
  70. vyr=(slyr(i+1)-slyr(i))/h;
  71.  
  72. % Update x-direction equations
  73. x(i+1)=x(i)+h*Vx(i);
  74. Vx(i+1)=Vx(i)+h*[-k/m*slxf(i)-c/m*vxf + -k/m*slxr(i)-c/m*vxr];
  75.  
  76. % Update y-direction equations
  77. y(i+1)=y(i)+h*Vy(i);
  78. Vy(i+1)=Vy(i)+h*[-k/m*slyr(i)-c/m*vyf + -k/m*slyr(i)-c/m*vyr];
  79.  
  80. %update anguar
  81. th(i+1)=th(i)+h*Vth(i);
  82. Vth(i+1)=Vth(i)+h*([-k*slxf(i)-c*vxf + -k*slyf(i)-c*vyf]/I - [-k*slxr(i)-c*vxr + -k*slyr(i)-c*vyr]/I);
  83.  
  84. % Locations
  85.  
  86. % Front shock locations
  87. xF(i+1)= x(i)+d*sin(th(i));
  88. yF(i+1)= y(i)+d*cos(th(i));
  89.  
  90. % Rear shock locations
  91. xR(i+1)= x(i)-d*sin(th(i));
  92. yR(i+1)= y(i)-d*cos(th(i));
  93.  
  94. xF1(i+1)=x(i)+2;
  95. yR1(i+1)=yR(i)+0.25;
  96. xR1(i+1)=x(i)-2;
  97.  
  98. % Plot the solution
  99. if (rem(i,10)==0)
  100. figure(1); clf(1)
  101. plot(xR1(i),yR1(i),'o')
  102. hold on
  103. plot(xF1(i),yF(i),'o')
  104. hold on
  105. plot(x(i),y(i),'x')
  106. xtrack=linspace(-1,Lt,1001);
  107. plot(xtrack,track(xtrack))
  108. ylim([-3,3])
  109. xlim([-1,25])
  110. drawnow
  111.  
  112. end % End if statement
  113.  
  114. end % End for loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement