Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. clear; clc
  2.  
  3. % Define the ODe
  4. m = 5.97/2; % Slugs (accounts for both wheels)
  5. I = 15; % THIS NEEDS TO BE CHANGED
  6. k = 325*12; % Spring rate constant lbf/ft
  7. c = sqrt(k*m); % Spring damper constant lbf/ft
  8. D = 29/12;% Diameter of wheel inches/12 (ft)
  9. d = 1.5; % shock distance from com
  10. g = 32.2; % ft/s^2
  11. SLxo = 0; % Initial length of shock in x-direction
  12. Slyo = 1; % Initial length of shock in y-direction feet
  13. track = @(x) .15*sin(x); % Bike track
  14. theta = deg2rad(0);
  15. % u]/I;
  16.  
  17.  
  18. % Domain Size (How long we want this to run for)
  19. Lt=20; % feet
  20. h=0.1;
  21.  
  22. % Number of steps
  23. N=round(Lt/h);
  24.  
  25. % Preallocate
  26. t=zeros(1,N);
  27. x=zeros(1,N); % position of COm on x direction
  28. v_x=zeros(1,N); % shock length accel
  29. y=zeros(1,N); % position of com in y dierction
  30. u_y=zeros(1,N); % shock length accel
  31. th=zeros(1,N); % angular position
  32. v_th=zeros(1,N); % angular accel
  33. slf=zeros(1,N);
  34. slr=zeros(1,N);
  35. xf=zeros(1,N);
  36. yf=zeros(1,N);
  37. xr=zeros(1,N);
  38. yr=zeros(1,N);
  39. % Initial Conditions
  40. t(1)=0;
  41. slx(1)=0;
  42. sly(1)=1;
  43.  
  44.  
  45. xf(1)=3; % initial positions of top of shocks in ft
  46. xr(1)=0;
  47. yr(1)=3;
  48. yf(1)=3;
  49. th(1)=0;
  50.  
  51. slfo=1; % initial shock length front
  52. slro=1; % Initial shock length rear
  53.  
  54. slf(1)=1;
  55. slr(1)=1;
  56.  
  57. x(1)=0;
  58. v_x(1)=0;
  59. y(1)=0;
  60. u_y(1)=0;
  61. th(1)=0;
  62. v_th(1)=0;
  63.  
  64. %Loop Over Time
  65. for i=1:N
  66. t(i+1)=t(i)+h;
  67.  
  68. % update shock length
  69. % slxf(i+1)= min(SLxo,sin(th(i))* shock_length(xf(i),yf(i),th(i),track,D));
  70. % slyf(i+1)= min(SLyo,cos(th(i))* shock_length(xf(i),yf(i),th(i),track,D));
  71. %
  72. % slxr(i+1)= min(SLxo, sin(th(i))* shock_length(xr(i),yr(i),th(i),track,D)); % shock_length(xo,yo,th,T,D)
  73. % slyr(i+1)= min(SLyo, cos(th(i))* shock_length(xr(i),yr(i),th(i),track,D));
  74. %
  75. slf(i+1)= shock_length(xf(i),yf(i),th(i),track,D);
  76. slr(i+1)= shock_length(xr(i),yr(i),th(i),track,D);
  77.  
  78.  
  79. % fron shock constraints
  80. if slf(i+1) > Slyo
  81. slf(i+1)= Slyo;
  82. end
  83.  
  84. if slf(i+1) < 0
  85. slf(i+1) = yf(i);
  86. end
  87. % rear shock constraints
  88. if slr(i+1) > Slyo
  89. slr(i+1)= Slyo;
  90. end
  91.  
  92. if slr(i+1) < 0
  93. slr(i+1) = yr(i);
  94. end
  95.  
  96.  
  97.  
  98.  
  99.  
  100. % change in shock length (v) in eq
  101.  
  102. vf=(slf(i+1)-slf(i))/h;
  103. vr=(slr(i+1)-slr(i))/h;
  104.  
  105. %update xdirection
  106. x(i+1)=x(i)+h*v_x(i);
  107. v_x(i+1)=v_x(i)+h*(-k/m*(slr(i)*sin(th(i))-slro*sin(th(i)))-c/m*(vr*sin(th(i)))-k/m*(slf(i)*sin(th(i))-slfo*sin(th(i)))-c/m*vf*sin(th(i)));
  108.  
  109. %update y direction
  110. y(i+1)=y(i)+h*u_y(i);
  111. u_y(i+1)=u_y(i)+h*(-k/m*(slr(i)*cos(th(i))-slro*cos(th(i)))-c/m*(vr*cos(th(i)))-k/m*(slf(i)*cos(th(i))-slfo*cos(th(i)))-c/m*vf*cos(th(i)));
  112.  
  113. %update anguar
  114. th(i+1)=th(i)+h*v_th(i);
  115. v_th(i+1)=v_th(i)+h*(((-k/m*(slr(i)*sin(th(i))-slro*sin(th(i)))-c/m*(vr*sin(th(i)))-k/m*(slr(i)*cos(th(i))-slro*cos(th(i)))-c/m*(vr*cos(th(i)))...
  116. +k/m*(slf(i)*sin(th(i))-slfo*sin(th(i)))+c/m*vf*sin(th(i)))+k/m*(slf(i)*cos(th(i))-slfo*cos(th(i)))+c/m*vf*cos(th(i))))/I;
  117.  
  118.  
  119.  
  120. % Locations of top of shocks
  121. xf(i+1)= x(i)+d*sin(th(i));
  122. yf(i+1)= y(i)+d*cos(th(i));
  123. xr(i+1)= x(i)-d*sin(th(i));
  124. yr(i+1)= y(i)-d*cos(th(i));
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. % %plot
  132. hold on
  133. plot([xr(i),yr(i)],[xf(i),yf(i)]) % bike frame line
  134. %
  135. %
  136. % % rear wheel
  137. % plot(xb(i),yb(i)-shock lenght(i),'ko')
  138. drawnow
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement