-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransmission.m
More file actions
524 lines (406 loc) · 23.9 KB
/
Transmission.m
File metadata and controls
524 lines (406 loc) · 23.9 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
classdef Transmission < matlab.System
properties
geometry = struct('type', 0, 'lead', 0, 'leadAngle', 0, 'inElemDia', 0, 'inElemEffDia', 0,...
'outElemDia', 0, 'outElemEffDia', 0, 'reductionRatio', 0, 'threadAngle', 0, 'pressureAngle', 0)
preload = struct('springForce', 0)
friction = struct('inSupBreak', 0, 'inSupVisc', 0, 'outSupBreak', 0, 'outSupVisc', 0,...
'kinFriction', 0, 'strbInf', 0, 'strbVelocity', 0, 'risingCst', 0, 'memoryCst', 0)
inertia = struct('inElemInertia', 0, 'mnOutElemInertia', 0, 'secOutElemInertia', 0)
actuation = struct('nominalTorque', 0, 'torqueCst', 0, 'encoderCounts', 0)
end
properties(Hidden, Constant)
zeroTolerance = 0.005;
end
properties(Access = private)
gamma0
gamma
psi0
end
methods(Static = true)
%%
function LSDgeometry = setLSDgeometry(lead, leadAngle, screwDiameter, reductionRatio)
% geometric equations:
% Eq.(1) tan(leadAngle) = lead/pi/screwDiameter
% Eq.(2) reductionRatio = 2*pi/lead ( = 1/(screwDiamaeter/2)/tan(leadAngle) )
eq1variables = [screwDiameter leadAngle lead];
eq2variables = [reductionRatio lead];
variables = [lead leadAngle screwDiameter reductionRatio];
if numel(variables(variables~=0)) < 2
error('Geometry error: inadequate data provided')
elseif all(variables ~= 0)
tolerance = 10^-9;
if abs(tan(leadAngle)-lead/pi/screwDiameter) > tolerance ...
|| abs(reductionRatio-2*pi/lead) > tolerance
error('Geometry error: inadequate data provided')
end
elseif numel(eq1variables(eq1variables~=0)) > 2 || numel(eq2variables(eq2variables~=0)) > 1 ...
|| numel(variables(variables~=0)) > 2
error('Geometry error: inadequate data provided')
% 1 restriction when 2 variables are provided
else % 4 choose 2 combinations minus 1 restriction (5 different cases)
if (lead && leadAngle) ~= 0
screwDiameter = lead/pi/tan(leadAngle);
reductionRatio = 2*pi/lead;
elseif (lead && screwDiameter) ~= 0
leadAngle = atan(lead/pi/screwDiameter);
reductionRatio = 2*pi/lead;
elseif (leadAngle && screwDiameter) ~= 0
lead = tan(leadAngle)*pi*screwDiameter;
reductionRatio = 2*pi/lead;
elseif (leadAngle && reductionRatio) ~= 0
screwDiameter = 1/(reductionRatio/2)/tan(leadAngle);
lead = tan(leadAngle)*pi*screwDiameter;
elseif (screwDiameter && reductionRatio) ~= 0
leadAngle = atan(1/(screwDiameter/2)/reductionRatio);
lead = tan(leadAngle)*pi*screwDiameter;
else
end
end
LSDgeometry = [lead; leadAngle; screwDiameter; reductionRatio];
end
function WDgeometry = setWDgeometry(lead, leadAngle, wormDiameter, gearDiameter, reductionRatio)
% geometric equations:
% Eq.(1) tan(leadAngle) = lead/pi/wormDiameter
% Eq.(2) reductionRatio = pi*gearDiameter/lead ( = gearDiameter/wormDiameter/tan(leadAngle) )
eq1variables = [wormDiameter leadAngle lead];
eq2variables = [reductionRatio gearDiameter lead];
variables = [lead leadAngle wormDiameter gearDiameter reductionRatio];
if numel(variables(variables~=0)) < 3
error('Geometry error: inadequate data provided')
elseif all(variables~=0)
tolerance = 10^-9;
if abs(tan(leadAngle)-lead/pi/wormDiameter) > tolerance ...
|| abs(reductionRatio - pi*gearDiameter/lead) > tolerance
error('Geometry error: inadequate data provided')
end
elseif numel(eq1variables(eq1variables~=0)) > 2 || numel(eq2variables(eq2variables~=0)) > 2 ...
|| numel(variables(variables~=0)) > 3
error('Geometry error: inadequate data provided')
% 2 restrictions when 3 variables are provided
else
% 5 choose 3 combinations minus 2 restrictions (8 different cases)
if (lead && leadAngle && gearDiameter) ~= 0
wormDiameter = lead/pi/tan(leadAngle);
reductionRatio = gearDiameter/wormDiameter/tan(leadAngle);
elseif (lead && leadAngle && reductionRatio) ~= 0
wormDiameter = lead/pi/tan(leadAngle);
gearDiameter = tan(leadAngle)*wormDiameter*reductionRatio;
elseif (lead && wormDiameter && gearDiameter) ~= 0
leadAngle = atan(lead/pi/wormDiameter);
reductionRatio = gearDiameter/wormDiameter/tan(leadAngle);
elseif (lead && wormDiameter && reductionRatio) ~= 0
leadAngle = atan(lead/pi/wormDiameter);
gearDiameter = tan(leadAngle)*wormDiameter*reductionRatio;
elseif (leadAngle && wormDiameter && gearDiameter) ~= 0
lead = tan(leadAngle)*pi*wormDiameter;
reductionRatio = gearDiameter/wormDiameter/tan(leadAngle);
elseif (leadAngle && wormDiameter && reductionRatio) ~= 0
lead = tan(leadAngle)*pi*wormDiameter;
gearDiameter = tan(leadAngle)*wormDiameter*reductionRatio;
elseif (leadAngle && gearDiameter && reductionRatio) ~= 0
lead = pi*gearDiameter/reductionRatio;
wormDiameter = lead/pi/tan(leadAngle);
elseif (wormDiameter && gearDiameter && reductionRatio) ~= 0
lead = pi*gearDiameter/reductionRatio;
leadAngle = atan(lead/pi/wormDiameter);
else
end
end
WDgeometry = [lead; leadAngle; wormDiameter; gearDiameter; reductionRatio];
end
function gamma = getGamma(inElemDia, outElemDia)
if outElemDia == 0
gamma = inElemDia/2;
else
gamma = inElemDia/outElemDia;
end
end
function psi0 = getPsi0(leadAngle)
psi0 = tan(leadAngle);
end
function nonCompression(preload, payload, gamma0, psi0, acceleration, velocity, mnOutElemInertia,...
loadInertia, secOutElemInertia, outSupBreak, outSupVisc)
if preload == 0
return
else
if velocity == 0
if (preload + payload - (mnOutElemInertia + loadInertia)*gamma0*psi0*acceleration...
- outSupBreak*sign(acceleration)) > 0 &&...
(preload + secOutElemInertia*gamma0*psi0*acceleration) > 0
return
else
error('Antibacklash operation violated')
end
else
if (preload + payload - (mnOutElemInertia + loadInertia)*gamma0*psi0*acceleration...
- outSupBreak*sign(velocity) - outSupVisc*gamma0*psi0*velocity) > 0 &&...
(preload + secOutElemInertia*gamma0*psi0*acceleration) > 0
return
else
error('Antibacklash operation violated')
end
end
end
end
function Dvar = getDvar(preload, payload, gamma0, psi0, tendency, acceleration, velocity,...
mnOutElemInertia, loadInertia, outSupBreak, outSupVisc)
if preload == 0
if acceleration == 0 && velocity == 0
Dvar = (payload - outSupBreak*sign(tendency))*sign(tendency);
elseif acceleration ~=0 && velocity == 0
Dvar = (payload - (mnOutElemInertia + loadInertia)*gamma0*psi0*acceleration...
- outSupBreak*sign(acceleration))*sign(acceleration);
else
Dvar = (payload - (mnOutElemInertia + loadInertia)*gamma0*psi0*acceleration...
- outSupBreak*sign(velocity) - outSupVisc*gamma0*psi0*velocity)*sign(velocity);
end
else
if acceleration == 0 && velocity == 0
Dvar = sign(tendency);
elseif acceleration ~=0 && velocity == 0
Dvar = sign(acceleration);
else
Dvar = sign(velocity);
end
end
end
function [strbFriction, strbArrival] = getstrbFriction(kinFriction, strbInf, risingCst, dwellTime,...
dwellTimePrev, frictionCoeffPrev, strbFrictionPrev, strbArrivalPrev)
if dwellTime == 0
strbArrival = strbArrivalPrev;
if dwellTimePrev ~=0 %breakaway
strbFriction = frictionCoeffPrev - kinFriction;
else
strbFriction = strbFrictionPrev;
end
else
if dwellTimePrev == 0
strbArrival = frictionCoeffPrev - kinFriction;
else
strbArrival = strbArrivalPrev;
end
strbFriction = strbArrival + (strbInf - strbArrival)*exp(-risingCst/dwellTime);
end
end
function frictionCoeff = getFrictionCoeff(velocityD, kinFriction, strbFriction, strbVelocity)
if velocityD == 0
frictionCoeff = kinFriction + strbFriction;
else
frictionCoeff = kinFriction + strbFriction*exp(-abs(velocityD)/strbVelocity)^2;
end
end
function psiStar = getPsiStar(Dvar, pressureAngle, leadAngle, frictionCoeff, preload)
reposeAngleEquiv = atan(frictionCoeff/cos(pressureAngle));
downhill = tan(leadAngle - reposeAngleEquiv);
uphill = tan(leadAngle + reposeAngleEquiv);
if Dvar > 0
if preload == 0
psiStar = downhill;
else
psiStar = [downhill uphill];
end
else
if preload == 0
psiStar = uphill;
else
psiStar = [uphill downhill];
end
end
end
function equivInertia = getEquivInertia(gamma0, psi0, gamma, psiStar, inElemInertia,...
mnOutElemInertia, loadInertia, secOutElemInertia)
if secOutElemInertia == 0
equivInertia = inElemInertia + gamma0*psi0*gamma*psiStar(1)*(mnOutElemInertia + loadInertia);
else
equivInertia = inElemInertia + ...
gamma0*psi0*gamma*dot(psiStar,[mnOutElemInertia;secOutElemInertia] + [loadInertia;0]);
end
end
function supportTorque = getSupportTorque(gamma0, psi0, gamma, psiStar, inSupBreak, inSupVisc,...
outSupBreak, outSupVisc, preload, tendency, velocity)
if velocity == 0
if preload == 0
supportTorque = inSupBreak*sign(tendency) + gamma*psiStar(1)*outSupBreak*sign(tendency);
else
supportTorque = inSupBreak*sign(tendency) + gamma*psiStar(1)*outSupBreak*sign(tendency)...
+ preload*gamma*(psiStar(2)-psiStar(1));
end
else
if preload == 0
supportTorque = inSupBreak*sign(velocity) + inSupVisc*velocity...
+ gamma*psiStar(1)*outSupBreak*sign(gamma0*psi0*velocity)...
+ gamma*psiStar(1)*outSupVisc*(gamma0*psi0*velocity);
else
supportTorque = inSupBreak*sign(velocity) + inSupVisc*velocity...
+ gamma*psiStar(1)*outSupBreak*sign(gamma0*psi0*velocity)...
+ gamma*psiStar(1)*outSupVisc*(gamma0*psi0*velocity)...
+ preload*gamma*(psiStar(2)-psiStar(1));
end
end
end
function equivTorque = getEquivTorque(actrTorque, payload, gamma, psiStar, supportTorque)
uTorque = actrTorque + gamma*psiStar(1)*payload;
equivTorque = uTorque - supportTorque;
end
function acceleration = getAcceleration(equivTorque, equivInertia, tendency, velocity)
if velocity == 0
if sign(tendency) ~= sign(equivTorque)
acceleration = 0;
else
acceleration = equivTorque/equivInertia;
end
else
acceleration = equivTorque/equivInertia;
end
end
function torque = getTorque(gamma, psiStar, payload, equivInertia, supportTorque, acceleration,...
velocity)
if velocity == 0
torque = 0;
else
torque = -gamma*psiStar(1)*payload + equivInertia*acceleration + supportTorque;
end
end
end
methods
%% Constructor
function set.geometry(drive, geometry)
parameters = [geometry.lead, geometry.leadAngle, geometry.threadAngle, geometry.inElemDia,...
geometry.inElemEffDia, geometry.outElemDia, geometry.outElemEffDia, geometry.reductionRatio];
if ~isempty(parameters(parameters < 0))
error('Geometry error: invalid parameters provided')
end
drive.geometry.threadAngle = geometry.threadAngle;
if ~ismember(geometry.type, [1 2 3])
error('Unknown transmission type')
else
drive.geometry.type = geometry.type;
end
if drive.geometry.type ~= 3
LSDgeometry = Transmission.setLSDgeometry(geometry.lead, geometry.leadAngle,...
geometry.inElemDia, geometry.reductionRatio);
drive.geometry.lead = LSDgeometry(1);
drive.geometry.leadAngle = LSDgeometry(2);
drive.geometry.inElemDia = LSDgeometry(3);
drive.geometry.reductionRatio = LSDgeometry(4);
else
WDgeometry = Transmission.setWDgeometry(geometry.lead, geometry.leadAngle,...
geometry.inElemDia, geometry.outElemDia, geometry.reductionRatio);
drive.geometry.lead = WDgeometry(1);
drive.geometry.leadAngle = WDgeometry(2);
drive.geometry.inElemDia = WDgeometry(3);
drive.geometry.outElemDia = WDgeometry(4);
drive.geometry.reductionRatio = WDgeometry(5);
end
if geometry.inElemEffDia == 0 || geometry.inElemEffDia > drive.geometry.inElemDia
drive.geometry.inElemEffDia = drive.geometry.inElemDia;
else
drive.geometry.inElemEffDia = geometry.inElemEffDia;
end
if geometry.outElemEffDia == 0 || geometry.outElemEffDia > drive.geometry.outElemDia
drive.geometry.outElemEffDia = drive.geometry.outElemDia;
else
drive.geometry.outElemEffDia = geometry.outElemEffDia;
end
drive.geometry.pressureAngle = atan(tan(drive.geometry.threadAngle/2)*cos(drive.geometry.leadAngle));
drive.geometry = struct('type', drive.geometry.type, 'lead', drive.geometry.lead,...
'leadAngle', drive.geometry.leadAngle, 'inElemDia', drive.geometry.inElemDia,...
'inElemEffDia', drive.geometry.inElemEffDia, 'outElemDia', drive.geometry.outElemDia,...
'outElemEffDia', drive.geometry.outElemEffDia, 'reductionRatio', drive.geometry.reductionRatio,...
'threadAngle', drive.geometry.threadAngle, 'pressureAngle', drive.geometry.pressureAngle);
end
function set.preload(drive, preload)
if preload.springForce < 0
error('Preload error: invalid parameters provided')
else
drive.preload.springForce = preload.springForce;
end
end
function set.friction(drive, friction)
parameters = [friction.kinFriction, friction.strbVelocity, friction.risingCst...
friction.memoryCst, friction.inSupBreak, friction.inSupVisc, friction.outSupBreak,...
friction.outSupVisc];
if ~isempty(parameters(parameters < 0))
error('Friction error: invalid parameters provided')
else
drive.friction.inSupBreak = friction.inSupBreak;
drive.friction.inSupVisc = friction.inSupVisc;
drive.friction.outSupBreak = friction.outSupBreak;
drive.friction.outSupVisc = friction.outSupVisc;
drive.friction.kinFriction = friction.kinFriction;
drive.friction.strbInf = friction.strbInf;
drive.friction.strbVelocity = friction.strbVelocity;
drive.friction.risingCst = friction.risingCst;
drive.friction.memoryCst = friction.memoryCst;
end
drive.friction = struct('inSupBreak', drive.friction.inSupBreak,...
'inSupVisc', drive.friction.inSupVisc, 'outSupBreak', drive.friction.outSupBreak,...
'outSupVisc', drive.friction.outSupVisc, 'kinFriction', drive.friction.kinFriction,...
'strbInf', drive.friction.strbInf, 'strbVelocity', drive.friction.strbVelocity,...
'risingCst', drive.friction.risingCst, 'memoryCst', drive.friction.memoryCst);
end
function set.inertia(drive, inertia)
parameters = [inertia.inElemInertia, inertia.mnOutElemInertia, inertia.secOutElemInertia];
if ~isempty(parameters(parameters < 0))
error('Inertia error: invalid parameters provided')
else
drive.inertia.inElemInertia = inertia.inElemInertia;
drive.inertia.mnOutElemInertia = inertia.mnOutElemInertia;
drive.inertia.secOutElemInertia = inertia.secOutElemInertia;
end
drive.inertia = struct('inElemInertia', drive.inertia.inElemInertia, 'mnOutElemInertia',...
drive.inertia.mnOutElemInertia, 'secOutElemInertia', drive.inertia.secOutElemInertia);
end
function set.actuation(drive, actuation)
parameters = [actuation.nominalTorque, actuation.torqueCst, actuation.encoderCounts];
if ~isempty(parameters(parameters < 0))
error('Actuation error: invalid parameters provided')
else
drive.actuation.nominalTorque = actuation.nominalTorque;
drive.actuation.torqueCst = actuation.torqueCst;
drive.actuation.encoderCounts = actuation.encoderCounts;
end
drive.actuation = struct('nominalTorque', drive.actuation.nominalTorque, 'torqueCst',...
drive.actuation.torqueCst, 'encoderCounts', drive.actuation.encoderCounts);
end
end
methods(Access = protected)
%% Dynamics
function setupImpl(drive)
drive.gamma0 = Transmission.getGamma(drive.geometry.inElemDia, drive.geometry.outElemDia);
drive.gamma = Transmission.getGamma(drive.geometry.inElemEffDia, drive.geometry.outElemEffDia);
drive.psi0 = Transmission.getPsi0(drive.geometry.leadAngle);
end
function [torque, acceleration, frictionCoeff, strbFriction, strbArrival] = ...
stepImpl(drive, acceleration, velocity, velocityD, actrTorque, loadInertia, payload,...
dwellTime, dwellTimePrev, frictionCoeffPrev, strbFrictionPrev, strbArrivalPrev)
velocity(abs(velocity) <= drive.zeroTolerance) = 0;
velocityD(abs(velocityD) <= drive.zeroTolerance) = 0;
Transmission.nonCompression(drive.preload.springForce, payload, drive.gamma0, drive.psi0,...
acceleration, velocity, drive.inertia.mnOutElemInertia, loadInertia,...
drive.inertia.secOutElemInertia, drive.friction.outSupBreak, drive.friction.outSupVisc)
[strbFriction, strbArrival] = Transmission.getstrbFriction(drive.friction.kinFriction,...
drive.friction.strbInf, drive.friction.risingCst, dwellTime, dwellTimePrev,...
frictionCoeffPrev, strbFrictionPrev, strbArrivalPrev);
frictionCoeff = Transmission.getFrictionCoeff(velocityD, drive.friction.kinFriction,...
strbFriction, drive.friction.strbVelocity);
tendency = actrTorque + drive.gamma0*drive.psi0*payload;
Dvar = Transmission.getDvar(drive.preload.springForce, payload, drive.gamma0, drive.psi0,...
tendency, acceleration, velocity, drive.inertia.mnOutElemInertia, loadInertia,...
drive.friction.outSupBreak, drive.friction.outSupVisc);
psiStar = Transmission.getPsiStar(Dvar, drive.geometry.pressureAngle, drive.geometry.leadAngle,...
frictionCoeff, drive.preload.springForce);
equivInertia = Transmission.getEquivInertia(drive.gamma0, drive.psi0, drive.gamma, psiStar,...
drive.inertia.inElemInertia, drive.inertia.mnOutElemInertia, loadInertia,...
drive.inertia.secOutElemInertia);
supportTorque = Transmission.getSupportTorque(drive.gamma0, drive.psi0, drive.gamma, psiStar,...
drive.friction.inSupBreak, drive.friction.inSupVisc, drive.friction.outSupBreak,...
drive.friction.outSupVisc, drive.preload.springForce, tendency, velocity);
equivTorque = Transmission.getEquivTorque(actrTorque, payload, drive.gamma, psiStar,...
supportTorque);
torque = Transmission.getTorque(drive.gamma, psiStar, payload, equivInertia, supportTorque,...
acceleration, velocity);
acceleration = Transmission.getAcceleration(equivTorque, equivInertia, tendency, velocity);
end
end
end