Advertisement
Guest User

team17code

a guest
Nov 20th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. % Team 17
  2. % Lance Marttinen, Jordan Horan, Kyle Tolman
  3. % Simulation Code
  4. % November 5, 2014
  5.  
  6.  
  7. clear
  8. clc
  9.  
  10. % Ask user which data to use
  11. df=1;%input('Which rider would you like? ');
  12. front_area=.53;%input('Frontal Area of ORV: ');%----.53
  13. vfront_area=.67;%input('Frontal Area of FSHPV: ');%----.67
  14. while df<1||df>10
  15. clear;
  16. clc;
  17. df=input('Please try again with a number between 1 and 10: ');
  18. end
  19. % Load data, set to vectors
  20. [lat,lon,elev,dist,hr,vel,mass]=course_vector(df);
  21.  
  22. vmass=mass+(51.4/2.2);
  23.  
  24. % Set vec_size to be size of data
  25. vec_size=size(lon,1);
  26.  
  27. % Difference in distance
  28. for i=1:vec_size-1;
  29. dif_dist(i,1)=(dist(i+1)-dist(i));
  30. end
  31.  
  32. % Find average velocity
  33. for i=1:vec_size-1;
  34. VA(i,1)=(vel(i+1)+vel(i))/2;
  35. if VA(i)<=0
  36. VA(i)=.1;
  37. end
  38. end
  39.  
  40. for i=1:vec_size-1;
  41. dV(i,1)=(vel(i+1)-vel(i));
  42. end
  43.  
  44. % Find dt
  45. for i=1:vec_size-1;
  46. dt(i,1)=dif_dist(i)/VA(i);
  47. if dt(i)<=0
  48. dt(i)=.1;
  49. end
  50. end
  51.  
  52. % Find acceleration
  53. for i=1:vec_size-1;
  54. accel(i,1)=dV(i)/dt(i);
  55. end
  56.  
  57. % Find elevation difference
  58. for i=1:vec_size-1;
  59. de(i,1)=(elev(i+1)-elev(i));
  60. end
  61.  
  62. % Find total distance
  63. tot_dist=dist(vec_size);
  64.  
  65. % Set total elevation gain variable
  66. tot_elev_gain=0;
  67. pos_count=0; %--------------------------------Is this needed?
  68. % Find elevation gain
  69. for i=1:vec_size-1;
  70. if de(i)>0;
  71. tot_elev_gain=tot_elev_gain+de(i);
  72. pos_count=pos_count+1;
  73. end
  74. end
  75.  
  76. % Slope vector
  77. for i=1:vec_size-1;
  78. if dif_dist(i)<=0;
  79. dif_dist(i)=1;
  80. end
  81. slope_vec(i,1)=atand(de(i)/dif_dist(i));
  82. end
  83.  
  84. % Plot longitude, latitude, and elevation
  85.  
  86. %plot3(lon,lat,elev);%-----------------------------Re-add this
  87. %xlabel('longitude');
  88. %ylabel('latitude');
  89. %zlabel('elevation');
  90. %title('figure 1');
  91.  
  92. %figure;
  93. %plot(dt,VA);
  94. %xlabel('Velocity');
  95. %ylabel('Distance');
  96. %title('figure 2');
  97.  
  98. % Average up angle
  99. avg_up_ang=atand(tot_elev_gain/tot_dist);
  100.  
  101. % Print distance and elevation to user
  102. fprintf('\nThe total distance is %6.2f m and the total elevation is %6.2f m\n\n',tot_dist,tot_elev_gain)
  103.  
  104. % Set gravity variable
  105. g=9.81;
  106.  
  107. % Slope resistance
  108. for i=1:vec_size-1;
  109. f_slope(i,1)=mass*g*sind(slope_vec(i));
  110. end
  111.  
  112. %Set coefficient of rolling friction variable
  113. c_f=.008;
  114.  
  115. % Rolling Resistance
  116. for i=1:vec_size-1;
  117. f_roll(i,1)=c_f*mass*g*cosd(slope_vec(i));
  118. end
  119.  
  120. % Set bump power loss variable
  121. p_b=100;
  122.  
  123. % Bump resistance
  124. for i=1:vec_size-1;
  125. f_bump(i,1)=p_b/VA(i);
  126. end
  127.  
  128. % Set drag force variables
  129. air_density=1.256;
  130. drag=1;
  131.  
  132. % Air Resistance
  133. for i=1:vec_size-1;
  134. f_air(i,1)=.5*air_density*front_area*drag*(VA(i))^2;
  135. end
  136.  
  137. % Force of rider
  138. for i=1:vec_size-1;
  139. f_rider(i,1)=mass*accel(i)+f_air(i)+f_roll(i)+f_bump(i)+f_slope(i);
  140. end
  141.  
  142. % Power of rider
  143. for i=1:vec_size-1;
  144. p_rider(i,1)=f_rider(i)*VA(i);
  145. end
  146.  
  147. %---------------------------------------------------------In class exercise
  148. over6=0;
  149. over9=0;
  150. under4=0;
  151.  
  152. for i=1:vec_size;
  153. if vel(i)>6;
  154. over6=over6+1;
  155. if vel(i)>9;
  156. over9=over9+1;
  157. end
  158. elseif vel(i)<4;
  159. under4=under4+1;
  160. end
  161. end
  162.  
  163. %--------------------------------------------------End of in class exercise
  164.  
  165. tot_time=sum(dt)/60;
  166. fprintf('It took the rider %6.2f minutes to complete the course. \n',tot_time);
  167.  
  168. for i=1:vec_size-1;
  169. if p_rider(i)>=0
  170. pos_prider(i,1)=p_rider(i);
  171. end
  172. if p_rider(i)<0
  173. pos_prider(i,1)=0;
  174. end
  175. end
  176.  
  177. over0=0;
  178.  
  179. for i=1:vec_size-1;
  180. if pos_prider(i)>0
  181. over0=over0+1;
  182. end
  183. end
  184.  
  185. PPA=(sum(pos_prider))/(over0);
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. VPR=PPA+1;
  202. loopcounter=0;
  203.  
  204.  
  205. while VPR>=PPA
  206.  
  207. loopcounter=loopcounter+1;
  208. vover0=0;
  209.  
  210. for i=1:vec_size-1;
  211. dt(i,1)=dt(i)*1.02;
  212. accel(i,1)=dV(i)/dt(i);
  213. vf_slope(i,1)=vmass*g*sind(slope_vec(i));
  214. vf_roll(i,1)=c_f*vmass*g*cosd(slope_vec(i));
  215. vf_air(i,1)=.5*air_density*vfront_area*drag*(VA(i))^2;
  216. f_driver(i,1)=vmass*accel(i)+vf_air(i)+vf_roll(i)+f_bump(i)+vf_slope(i);
  217. p_driver(i,1)=f_driver(i)*VA(i);
  218. if p_driver(i)>=0
  219. pos_pdriver(i,1)=p_driver(i);
  220. end
  221. if p_driver(i)<0
  222. pos_pdriver(i,1)=0;
  223. end
  224.  
  225.  
  226.  
  227. if pos_pdriver(i)>0
  228. vover0=vover0+1;
  229. end
  230. end
  231.  
  232. VPR=(sum(pos_pdriver))/(vover0);
  233.  
  234. end
  235.  
  236. loopcounter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement