W1 =
'%calculates the result of a 1km drag race for
%a user define vehicle powered by an electric
%motor
%Porsche Taycan Sport Turismo (Y1A) Turbo S 93.4 kWh (761 Hp)
clear
cD=0.22; %car dragcoefficient%https://en.wikipedia.org/wiki/Porsche_Taycan#:~:text=panel's%20power%20threshold.-,Aerodynamics,of%20any%20current%20Porsche%20model.
aF=2.66; %Cr frontal area %https://zeperfs.com/en/fiche8119-porsche-taycan-turbo-s.htm
CarOnlyMass=2295;%mass of car without driver kg%https://zeperfs.com/en/fiche8119-porsche-taycan-turbo-s.htm
DriverMass=80;%kg
rolResCoeff=0.012; %rolling resistance coefficient
BattPowerRating=58; %Battery maximum operating power (kW);
BattEnergyCapacity=83.7; %Battery Energy Capcity (kWh)
FinalDriveRatio=7.9377; %the gear ratio of the gear that steps down motor speed to wheel speed
SpeedTorque=[0 1050 %https://zeperfs.com/en/fiche8119-porsche-taycan-turbo-s.htm#Specs
1500 1050
4000 1050
5000 971
5750 929
6500 855
7000 763
7750 689
13750 388
15500 362
10000 0]; %[rpm nm]
maxEngineRPM=15500;
%https://zeperfs.com/en/fiche8119-porsche-taycan-turbo-s.htm
%% CALCULATION SECTION: You do not need to alter anything here
SpeedEfficiency=[0 0.86
1000 0.87
2000 0.90
3000 0.93
4000 0.94
5000 0.95
6000 0.95
7000 0.95
8000 0.91
9000 0.88
10000 0.87
10500 0.86];
% Adjust torque for situations in which the battery is not powerful enough to provide torque at a given RPM
for i=1:size(SpeedTorque,1)
if (SpeedTorque(i,1)*SpeedTorque(i,2))/9565 > BattPowerRating
SpeedTorque(i,2)=(BattPowerRating*SpeedEfficiency(i,2))*9565/SpeedTorque(i,1);
SpeedPowerCurve(i,1)=SpeedTorque(i,1);
SpeedPowerCurve(i,2)=BattPowerRating;
else
SpeedPowerCurve(i,1)=SpeedTorque(i,1);
SpeedPowerCurve(i,2)=(SpeedTorque(i,1)*SpeedTorque(i,2))/9565;
end
end
WheelRadius=0.32;%m
idleRPM=0; %Electric vehicles can start from zero motor speed, so idle RPM=0
CarMass=CarOnlyMass+DriverMass;
CarLinearVelocity=0;
CarDisplacement=0;
RemainingEnergy=BattEnergyCapacity;
for i=1:100
drag=cD*aF*0.5*1.225*(CarLinearVelocity^2);
rollingResistance=rolResCoeff*CarMass*9.81;
WheelCircumference=pi()*2*WheelRadius;
CarWheelRPM=60*(CarLinearVelocity/WheelCircumference); %RPM of car wheel
CarEngineRPM=max(CarWheelRPM*FinalDriveRatio,idleRPM);
if or(CarEngineRPM>maxEngineRPM,0>=RemainingEnergy) %if calcs suggest that engine would have to rotate faster than it is permitted to in order to maintain the cars speed at the given gear...
CarEngineTorque=0;
TotalWheelTorque=0; %no or negative torque, as engine slows car down
CarEngineEfficiency=interp1(SpeedEfficiency(:,1)',SpeedEfficiency(:,2)',maxEngineRPM); %engine efficiency based on max RPM;
else
CarEngineTorque=interp1(SpeedTorque(:,1)',SpeedTorque(:,2)',CarEngineRPM); %engine provides torque based on its actual RPM
TotalWheelTorque=(CarEngineTorque*FinalDriveRatio); %Nm
CarEngineEfficiency=interp1(SpeedEfficiency(:,1)',SpeedEfficiency(:,2)',CarEngineRPM);%engine efficiency based on its actual RPM;
end
%Assign the engine efficiency associated with the chosen gear
EffLog(i,1)=CarEngineEfficiency;
%Determine fuel consumption of the car
CarEnginekWh=(CarEngineTorque*CarEngineRPM)/(9565*3600);%determine kWh of energy actually used for propulsion during the timestep, 3600 factor converts hourly value to seconds
BatterykWh=CarEnginekWh/CarEngineEfficiency;%divide by engine efficiency to get kWh of fuel required
if isnan(BatterykWh)
TotalkWh(i,1)=0;
else
TotalkWh(i,1)=BatterykWh;
end
%Determine actual propulsive force at the wheels
WheelForce=TotalWheelTorque/WheelRadius;
%calculate new acceleration (at the start of the 1 second timestep),and car
%velocity and car displacement (at the end of the timestep)
CarAcceleration=(WheelForce-drag-rollingResistance)/CarMass;
CarLinearVelocity=CarLinearVelocity+CarAcceleration;
CarDisplacement=CarDisplacement+CarLinearVelocity;
RemainingEnergy=max(RemainingEnergy-BatterykWh,0);
AccelLog(i,1)=CarAcceleration;
VelLog(i,1)=CarLinearVelocity;
DispLog(i,1)=CarDisplacement;
RemainLog(i,1)=RemainingEnergy;
end
FinishLine = size(DispLog( 1:find( DispLog > 1000, 1 ) ),1);
kWhTotal=sum(TotalkWh(1:FinishLine,1));
if FinishLine>0
x1=sprintf('\nYour car crosses the finish line after %i seconds.\nThis requires %d kWh of battery energy.', FinishLine, kWhTotal);
disp(x1)
else
x1=sprintf('\nYour car fails to cross the finish line within the alloted time!');
disp(x1)
end
subplot(3,2,1)
plot(DispLog)
xlabel('Time (s)')
ylabel('Car Displacement (m)')
subplot(3,2,2)
plot(VelLog)
xlabel('Time (s)')
ylabel('Car Velocity (m/s)')
subplot(3,2,3)
plot(AccelLog)
xlabel('Time (s)')
ylabel('Car Acceleration (m/s^2)')
subplot(3,2,4)
plot(TotalkWh)
xlabel('Time (s)')
ylabel({'Battery Energy Reqired','per second (kWh/s)'})
subplot(3,2,5)
plot(EffLog)
xlabel('Time (s)')
ylabel('Engine Efficiency')
subplot(3,2,6)
plot(RemainLog)
xlabel('Time (s)')
ylabel('Remaining Battery Energy')
clear CarAcceleration CarLinearVelocity CE CR CT CT2 drag FinalDriveRatio FinishLine FuelTotal WheelForce TotalWheelTorueq FuelkWh i maxIndex o rollingResistance rolResCoeff WheelRadius WheelCircumference x1 idleRPM maxEngineRPM SpeedEfficiency CarDisplacement CarEngineEfficiency CarEngineRPM CarEngineTorque CarEnginekWh SpeedTorque TotalWheelTorque cD aF CarOnlyMass CarWheelRPM DriverMass FuelLowerHeatingVal gearRatios CarMass
'