-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbrakeactuator.m
243 lines (228 loc) · 8.38 KB
/
brakeactuator.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% filename: brakeactuator.m
% author: dr. briefs
% last updated: 2017/8/10
%
% purpose: generates brake gap position based on brake actuator response dynamics
%
% input: initial brake gap (mm), target brake gap (mm), time passed since t=0
% output: brake gap position (mm), settling time (s)
%
% notes:
% response dynamics assumes...
% -no load conditions
% -constant max velocity of 6mm/s
% -constant acceleration of 4mm/s^2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% s
function [b,ts] = brakeactuator(b0,bset,t)
deltab = bset - b0;
bddotmax = 15.0;
bdotmax = 9.735;
% If required brakegap travel is greater than distance needed to accelerate and decelerate to/from max velocity:
if abs(deltab) > bdotmax^2/bddotmax
% Calculate theoretical time & distance required to accelerate to max speed
deltab_accel = 0.5*bdotmax^2/bddotmax;
deltat_accel = bdotmax/bddotmax;
% Assume distance traveled during acceleration equals distance traveled during deceleration
deltab_decel = deltab_accel;
% Calculate required coast distance & time
deltab_coast = abs(deltab) - deltab_accel - deltab_decel;
deltat_coast = deltab_coast/bdotmax;
% Calculate theoretical settling time
ts = deltat_coast + 2*deltat_accel;
% Calculate position given time
if t <= deltat_accel % Calculate theoretical position if t is in acceleration phase
b = b0 + 0.5*bddotmax*t^2;
if deltab < 0
b = b0 - 0.5*bddotmax*t^2;
end
elseif t > deltat_accel && t < deltat_accel + deltat_coast % Calculate theoretical position if t is in coasting phase
b1 = b0 + 0.5*bddotmax*deltat_accel^2;
b = b1 + bdotmax*(t - deltat_accel);
if deltab < 0
b1 = b0 - 0.5*bddotmax*deltat_accel^2;
b = b1 - bdotmax*(t - deltat_accel);
end
elseif t > deltat_accel && t < ts % Calculate theoretical position if t is in deceleration phase
b1 = b0 + 0.5*bddotmax*deltat_accel^2;
b2 = b1 + bdotmax*deltat_coast;
b = b2 + bdotmax*(t - deltat_accel - deltat_coast) - 0.5*bddotmax*(t - deltat_accel - deltat_coast)^2;
if deltab < 0
b1 = b0 - 0.5*bddotmax*deltat_accel^2;
b2 = b1 - bdotmax*deltat_coast;
b = b2 - bdotmax*(t - deltat_accel - deltat_coast) + 0.5*bddotmax*(t - deltat_accel - deltat_coast)^2;
end
else % If theoretical settling time exceeded, hold brakegap value at bset
b = bset;
end
%% Travel distance too short to accelerate to max speed
else
% Calculate theoretical distance required to accelerate to max speed
deltab_accel = abs(deltab)/2;
% Calculate new max speed
bdotmax = sqrt(2*bddotmax*deltab_accel);
% Calculate theoretical time required to accelerate to max speed
deltat_accel = bdotmax/bddotmax;
% Calculate theoretical settling time
ts = 2*deltat_accel;
% Calculate position given time
if t <= deltat_accel % Calculate theoretical position if t is in acceleration phase
b = b0 + 0.5*bddotmax*t^2;
if deltab < 0
b = b0 - 0.5*bddotmax*t^2;
end
elseif t > deltat_accel && t < ts % Calculate theoretical position if t is in deceleration phase
b1 = b0 + 0.5*bddotmax*deltat_accel^2;
b = b1 + bdotmax*(t - deltat_accel) - 0.5*bddotmax*(t - deltat_accel)^2;
if deltab < 0
b1 = b0 - 0.5*bddotmax*deltat_accel^2;
b = b1 - bdotmax*(t - deltat_accel) + 0.5*bddotmax*(t - deltat_accel)^2;
end
else % If theoretical settling time exceeded, hold brake gap value at bset
b = bset;
end
end
end
%% Discrete time calc based curve generator - don't use
% function [t,b] = brakeactuator(b0,bset,dt)
% deltab = bset - b0;
% bddotmax = 4.0;
% bdotmax = 6.0;
%
% n = 1;
% b = [b0];
% bdot = [0];
% t = [0];
%
% % If required brakegap travel is greater than time needed to accelerate and decelerate to/from max velocity:
% if abs(deltab) > bdotmax^2/bddotmax
% %% Generate acceleration phase
% % while bdotmax^2/(2*bddotmax) - abs(b(n)) > 0.001
% while abs(bdotmax - bdot(n)) > 0
%
% n = n + 1;
% % Calculate speed
% bdot(n) = bdot(n-1) + bddotmax*dt;
%
% if abs(bdot(n)) > abs(bdotmax)
% bdot(n) = bdotmax;
% end
%
% % Calculate position
% b(n) = b(n-1) + bdot(n-1)*dt + 0.5*bddotmax*dt^2;
% if deltab < 0
% b(n) = b(n-1) - bdot(n-1)*dt - 0.5*bddotmax*dt^2;
% end
%
% t(n) = t(n-1) + dt;
%
% end
%
% % Create timestamp
% n1 = n;
% b1 = b(n);
% bdot1 = bdot(end);
% t1 = t(end);
%
% %% Calculate required coast period
% deltab_coast = abs(deltab) - 2*abs(b(end) - b(1));
%
% %% Generate coast phase
% while deltab_coast - abs(b(n) - b1) > 0.001*deltab_coast
% n = n + 1;
%
% % Calculate speed
% bdot(n) = bdot(n-1);
%
% % Calculate position
% b(n) = b(n-1) + bdot(n-1)*dt;
% if deltab < 0
% b(n) = b(n-1) - bdot(n-1)*dt;
% end
%
% t(n) = t(n-1) + dt;
%
% end
%
% % Create timestamp
% b2 = b(end);
% t2 = t(end);
%
% %% Generate deceleration phase
% while t(n) - t2 < t1
% n = n + 1;
%
% % Calculate speed
% bdot(n) = bdot(n-1) - bddotmax*dt;
% if bdot(n) < 0
% bdot(n) = 0;
% end
%
% % Calculate position
% b(n) = b(n-1) + bdot(n-1)*dt + 0.5*bddotmax*dt^2;
% if deltab < 0
% b(n) = b(n-1) - bdot(n-1)*dt - 0.5*bddotmax*dt^2;
% end
%
% t(n) = t(n-1) + dt;
% end
% b(end) = bset; % Overwrite last brakegap value with bSet (to account for undershoot in code)
%
% %% Travel distance too short to accelerate to max speed
% else
% %% Generate acceleration phase
% % Compute new max speed based on required travel distance
% bdotmax = sqrt(abs(deltab)*bddotmax);
% %% Generate acceleration phase
% while bdotmax - abs(bdot(n)) > 0.001* abs(bdotmax)
%
% n = n + 1;
% % Calculate speed
% bdot(n) = bdot(n-1) + bddotmax*dt;
%
% if abs(bdot(n)) > abs(bdotmax)
% bdot(n) = bdotmax;
% end
%
% % Compute time-step
% t(n) = t(n-1) + dt;
%
% % Calculate position
% b(n) = b(n-1) + bdot(n-1)*dt + 0.5*bddotmax*dt^2;
% if deltab < 0
% b(n) = b(n-1) - bdot(n-1)*dt - 0.5*bddotmax*dt^2;
% end
% % if half target distance is overshot, break acceleration phase
% if abs(b(n) - b(1)) >= abs(deltab)/2
% break
% end
% end
% t1= t(end);
% %% Generate deceleration phase
% while t(n) < 2*t1
% n = n + 1;
%
% % Calculate speed
% bdot(n) = bdot(n-1) - bddotmax*dt;
% if bdot(n) < 0
% bdot(n) = 0;
% end
%
% % Compute time-step
% t(n) = t(n-1) + dt;
%
% % Calculate position
% b(n) = b(n-1) + bdot(n-1)*dt + 0.5*bddotmax*dt^2;
% if deltab < 0
% b(n) = b(n-1) - bdot(n-1)*dt - 0.5*bddotmax*dt^2;
% end
% % if target distance is overshot, break deceleration phase
% if abs(b(n) - b(1)) >= abs(deltab)
% break
% end
% end
% b(end) = bset; % Overwrite last brakegap value with bSet (to account for undershoot in code)
% end
% end