-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccSim.m
176 lines (148 loc) · 5.31 KB
/
accSim.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
function [V,lapTime, maxLong, Energy, currentDrag, mpower] = accSim(pervV, len, vrev, param, action, consTime, En)
%Vehicle's data/parameters
amax = param(1);
rdyn =param(2);
ie = param(3);
mf = param(4);
g = param(5);
Cd = param(6);
eta = param(7);
fr = param(8);
rho = param(9);
A = param(10);
myu = param(11);
h = param(12);
Lwb = param(13);
wbr = param(14);
P = param(15);
Energy=En;
currentDrag=0;
mpower=0;
if(action=="Reverse")
t = zeros (1,len*10);
a = t;
V = t;
mtrans = t;
FL = t;
Fzex= t;
T=t;
%Assuming start of any track of to be a straight
mtrans(1) = ((amax)*h)/Lwb*mf;
FL(1) = ((wbr *mf)+mtrans(1))*g* myu;
a(1) = (mf * g *fr) + 0.5 *rho*Cd*A*(0) / mf;
V(1) = sqrt (pervV^2 + 2*a(1)*0.1);
for i =2:len*10
%Calculate traction limitation then adjust the new torque if
%exceeded the limit.
Fzex(i) = ( mf * g *fr) + 0.5 *rho*Cd* A*(V(i-1)^2);
mtrans(i) = ((a(i-1)/9.81)*h)/Lwb*mf;
FL(i)=(mtrans(i)*g +wbr *mf*g)* myu;
%Calculate the new acceleration.
a(i) = ( mf * g *fr) + 0.5 *rho*Cd* A*(V(i-1)^2)/ mf;
%Calculate the new velocity.
V(i) = sqrt(V(i-1)^2 + 2*a(i)*0.1);
end
maxLong = a;
end
if(action=="Forward" && consTime==false)
t = zeros (1,len*10);
a = t;
V = t;
mtrans = t;
FL = t;
Fzex= t;
T=t;
%Assuming start of any track of to be a straight
mtrans(1) = ((amax)*h)/Lwb*mf;
FL(1) = ((wbr *mf)+mtrans(1))*g* myu;
a(1) = min(amax,(mf * g *fr) + 0.5 *rho*Cd*A*(0) / mf);
V(1) = sqrt (pervV^2 + 2*a(1)*0.1);
for i =2:len*10
%Calculate traction limitation then adjust the new torque if
%exceeded the limit.
Fzex(i) = (T(i-1)*ie / rdyn) * eta -( mf * g *fr) - 0.5 *rho*Cd* A*(V(i-1)^2);
mtrans(i) = ((a(i-1)/9.81)*h)/Lwb*mf;
FL(i)=(mtrans(i)*g +wbr *mf*g)* myu;
if(Fzex(i)~=FL(i))
T(i-1)= (FL(i) + (mf*g*fr) + 0.5 *rho*Cd* A*(V(i-1)^2))*(rdyn/(ie*eta));
end
%Calculate power limitation then adjust the new torque if
%exceeded the limit.
if((T(i-1)/rdyn)*V(i-1)*ie >= P)
T(i)=(P*rdyn)/(V(i-1)*ie);
else
T(i)=T(i-1);
end
mpower = max(mpower,(V(i-1)*(60/2/pi/rdyn)*T(i)*ie/9550)*1000);
currentDrag=max(currentDrag, T(i));
%Calculate the new acceleration.
a(i) = ((T(i)*ie / rdyn) * eta -( mf * g *fr) - 0.5 *rho*Cd* A*(V(i-1)^2))/ mf;
%Calculate the new velocity.
V(i) = sqrt(V(i-1)^2 + 2*a(i)*0.1);
V(i) = min(V(i), vrev(i));
%Check if acceleration went to zero or not because of the step
%division.
if(a(i)<= 0)
a(i)=0;
end
end
maxLong = max(a);
end
if(action=="Forward" && consTime==true)
t = zeros (1,len*10);
a = t;
V = t;
mtrans = t;
FL = t;
Fzex= t;
T=t;
time=t;
%Assuming start of any track of to be a straight
mtrans(1) = ((amax)*h)/Lwb*mf;
FL(1) = ((wbr *mf)+mtrans(1))*g* myu;
a(1) = min(amax*g,(mf * g *myu) + 0.5 *rho*Cd*A*(0) / mf);
V(1) = min(sqrt (pervV^2 + 2*a(1)*0.1),vrev(1));
t(1) = (V(1)-pervV)/a(1);
for i =2:len*10
%Calculate traction limitation then adjust the new torque if
%exceeded the limit.
Fzex(i) = (T(i-1)*ie / rdyn) * eta -( mf * g *fr) - 0.5 *rho*Cd* A*(V(i-1)^2);
mtrans(i) = ((a(i-1)/g)*h)/Lwb*mf;
FL(i)=(mtrans(i)*g +wbr *mf*g)* myu;
if(Fzex(i)~=FL(i))
T(i-1)= (FL(i) + (mf*g*fr) + 0.5 *rho*Cd* A*(V(i-1)^2))*(rdyn/(ie*eta));
end
%Calculate power limitation then adjust the new torque if
%exceeded the limit.
if((T(i-1)/rdyn)*V(i-1)*ie >= P)
T(i)=(P*rdyn)/(V(i-1)*ie);
else
T(i)=T(i-1);
end
mpower = max(mpower,(V(i-1)*(60/2/pi/rdyn)*T(i)*ie/9550)*1000);
currentDrag=Fzex(i)*1.1*rdyn;
%Calculate the new acceleration.
a(i) = ((T(i)*ie / rdyn) * eta -( mf * g *fr) - 0.5 *rho*Cd* A*(V(i-1)^2))/ mf;
if(a(i)>11.855)
a(i)=11.85;
end
%Calculate the new velocity.
V(i) = sqrt(V(i-1)^2 + 2*a(i)*0.1);
V(i) = min(V(i), vrev(i));
%Check if acceleration went to zero or not because of the step
%division.
if(a(i) <= 0)
t(i) = 0.1 / V(i) ;
else
t(i) = (V(i) - V(i-1)) / a(i);
end
time(i)=time(i-1)+t(i);
Energy= Energy + Fzex(i)*0.1;
end
avg = sum(T)/length(T);
maxLong=max(a);
maxi=max(Fzex);
Tr = FL .* rdyn ;
maxtr = max(Tr);
end
lapTime = sum(t);