Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Team 17
- % Lance Marttinen, Jordan Horan, Kyle Tolman
- % Simulation Code
- % November 5, 2014
- clear
- clc
- % Ask user which data to use
- df=1;%input('Which rider would you like? ');
- front_area=.53;%input('Frontal Area of normal mountain bike: ');%----.53
- vfront_area=.67;%input('Frontal Area of FSHPV: ');%----.67
- while df<1||df>10
- clear;
- clc;
- df=input('Please try again with a number between 1 and 10: ');
- end
- % Load data, set to vectors
- [lat,lon,elev,dist,hr,vel,mass]=course_vector(df);
- vmass=mass+(51.4/2.2);
- % Set vec_size to be size of data
- vec_size=size(lon,1);
- % Difference in distance
- for i=1:vec_size-1;
- dif_dist(i,1)=(dist(i+1)-dist(i));
- end
- % Find average velocity
- for i=1:vec_size-1;
- VA(i,1)=(vel(i+1)+vel(i))/2;
- if VA(i)<=0
- VA(i)=.1;
- end
- end
- for i=1:vec_size-1;
- dV(i,1)=(vel(i+1)-vel(i));
- end
- % Find dt
- for i=1:vec_size-1;
- dt(i,1)=dif_dist(i)/VA(i);
- if dt(i)<=0
- dt(i)=.1;
- end
- end
- % Find acceleration
- for i=1:vec_size-1;
- accel(i,1)=dV(i)/dt(i);
- end
- % Find elevation difference
- for i=1:vec_size-1;
- de(i,1)=(elev(i+1)-elev(i));
- end
- % Find total distance
- tot_dist=dist(vec_size);
- % Set total elevation gain variable
- tot_elev_gain=0;
- pos_count=0; %--------------------------------Is this needed?
- % Find elevation gain
- for i=1:vec_size-1;
- if de(i)>0;
- tot_elev_gain=tot_elev_gain+de(i);
- pos_count=pos_count+1;
- end
- end
- % Slope vector
- for i=1:vec_size-1;
- if dif_dist(i)<=0;
- dif_dist(i)=1;
- end
- slope_vec(i,1)=atand(de(i)/dif_dist(i));
- end
- % Plot longitude, latitude, and elevation
- %plot3(lon,lat,elev);%-----------------------------Re-add this
- %xlabel('longitude');
- %ylabel('latitude');
- %zlabel('elevation');
- %title('figure 1');
- %figure;
- %plot(dt,VA);
- %xlabel('Velocity');
- %ylabel('Distance');
- %title('figure 2');
- % Average up angle
- avg_up_ang=atand(tot_elev_gain/tot_dist);
- % Print distance and elevation to user
- fprintf('\nThe total distance is %6.2f m and the total elevation is %6.2f m\n\n',tot_dist,tot_elev_gain)
- % Set gravity variable
- g=9.81;
- % Slope resistance
- for i=1:vec_size-1;
- f_slope(i,1)=mass*g*sind(slope_vec(i));
- end
- %Set coefficient of rolling friction variable
- c_f=.008;
- % Rolling Resistance
- for i=1:vec_size-1;
- f_roll(i,1)=c_f*mass*g*cosd(slope_vec(i));
- end
- % Set bump power loss variable
- p_b=100;
- % Bump resistance
- for i=1:vec_size-1;
- f_bump(i,1)=p_b/VA(i);
- end
- % Set drag force variables
- air_density=1.256;
- drag=1;
- % Air Resistance
- for i=1:vec_size-1;
- f_air(i,1)=.5*air_density*front_area*drag*(VA(i))^2;
- end
- % Force of rider
- for i=1:vec_size-1;
- f_rider(i,1)=mass*accel(i)+f_air(i)+f_roll(i)+f_bump(i)+f_slope(i);
- end
- % Power of rider
- for i=1:vec_size-1;
- p_rider(i,1)=f_rider(i)*VA(i);
- end
- %---------------------------------------------------------In class exercise
- over6=0;
- over9=0;
- under4=0;
- for i=1:vec_size;
- if vel(i)>6;
- over6=over6+1;
- if vel(i)>9;
- over9=over9+1;
- end
- elseif vel(i)<4;
- under4=under4+1;
- end
- end
- %--------------------------------------------------End of in class exercise
- tot_time=sum(dt)/60;
- fprintf('It took the rider %6.2f minutes to complete the course. \n',tot_time);
- for i=1:vec_size-1;
- if p_rider(i)>=0
- pos_prider(i,1)=p_rider(i);
- end
- if p_rider(i)<0
- pos_prider(i,1)=0;
- end
- end
- over0=0;
- for i=1:vec_size-1;
- if pos_prider(i)>0
- over0=over0+1;
- end
- end
- PPA=(sum(pos_prider))/(over0);
- VPR=PPA+1;
- loopcounter=0;
- while VPR>=PPA
- loopcounter=loopcounter+1;
- for i=1:vec_size-1;
- dt(i,1)=dt(i)*1.02;
- end
- % Find acceleration
- for i=1:vec_size-1;
- accel(i,1)=dV(i)/dt(i);
- end
- % Slope resistance
- for i=1:vec_size-1;
- vf_slope(i,1)=vmass*g*sind(slope_vec(i));
- end
- % Rolling Resistance
- for i=1:vec_size-1;
- vf_roll(i,1)=c_f*vmass*g*cosd(slope_vec(i));
- end
- % Air Resistance
- for i=1:vec_size-1;
- vf_air(i,1)=.5*air_density*vfront_area*drag*(VA(i))^2;
- end
- % Force of DRIVER
- for i=1:vec_size-1;
- f_driver(i,1)=vmass*accel(i)+vf_air(i)+vf_roll(i)+f_bump(i)+vf_slope(i);
- end
- % Power of DRIVER
- for i=1:vec_size-1;
- p_driver(i,1)=f_driver(i)*VA(i);
- end
- % Pos power of DRIVER
- for i=1:vec_size-1;
- if p_driver(i)>=0
- pos_pdriver(i,1)=p_driver(i);
- end
- if p_driver(i)<0
- pos_pdriver(i,1)=0;
- end
- end
- vover0=0;
- for i=1:vec_size-1;
- if pos_pdriver(i)>0
- vover0=vover0+1;
- end
- end
- VPR=(sum(pos_pdriver))/(vover0);
- end
- loopcounter
- %GEARING%
- %
- %cadcalc(v,cad_trg)=function(findx,rindx);
- r_gear=[11 13 15 17 20 23 26 30 34];
- f_gear=[48 34 24];
- for i=1:length(v)
- temp_diff=1000;
- w_rpm=1;
- for j=1:3
- for k=1:9
- c_rpm=r_gear(k)/f_gear(j)*w_rpm;
- cad_dif=abs(c_rpm-cad_trg);
- if cad_dif<temp_diff
- findx(i)=1;
- rindx(i)=1;
- temp_diff=1;
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement