1
1
"""
2
- Fixed(;name, phi0= 0.0)
2
+ Fixed(;name, phi0 = 0.0)
3
3
4
4
Flange fixed in housing at a given angle.
5
5
@@ -11,15 +11,20 @@ Flange fixed in housing at a given angle.
11
11
12
12
- `phi0`: [`rad`] Fixed offset angle of housing
13
13
"""
14
- @component function Fixed (; name, phi0 = 0.0 )
15
- @named flange = Flange ()
16
- @parameters phi0= phi0 [description = " Fixed offset angle of flange" ]
17
- eqs = [flange. phi ~ phi0]
18
- return compose (ODESystem (eqs, t, [], [phi0]; name = name), flange)
14
+ @mtkmodel Fixed begin
15
+ @components begin
16
+ flange = Flange ()
17
+ end
18
+ @parameters begin
19
+ phi0 = 0.0 , [description = " Fixed offset angle of flange" ]
20
+ end
21
+ @equations begin
22
+ flange. phi ~ phi0
23
+ end
19
24
end
20
25
21
26
"""
22
- Inertia(;name, J, phi_start= 0.0, w_start= 0.0, a_start= 0.0)
27
+ Inertia(;name, J, phi = 0.0, w = 0.0, a = 0.0)
23
28
24
29
1D-rotational component with inertia.
25
30
37
42
# Parameters:
38
43
39
44
- `J`: [`kg·m²`] Moment of inertia
40
- - `phi_start`: [`rad`] Initial value of absolute rotation angle of component
41
- - `w_start`: [`rad/s`] Initial value of absolute angular velocity of component
42
- - `a_start`: [`rad/s²`] Initial value of absolute angular acceleration of component
43
45
"""
44
- @component function Inertia (; name, J, phi_start = 0.0 , w_start = 0.0 , a_start = 0.0 )
45
- @named flange_a = Flange ()
46
- @named flange_b = Flange ()
47
- @symcheck J > 0 || throw (ArgumentError (" Expected `J` to be positive" ))
48
- @parameters J= J [description = " Moment of inertia of $name " ]
49
- sts = @variables (phi (t)= phi_start, [description = " Absolute rotation angle of $name " ],
50
- w (t)= w_start, [description = " Absolute angular velocity of $name " ],
51
- a (t)= a_start,
52
- [description = " Absolute angular acceleration of $name " ],)
53
- eqs = [phi ~ flange_a. phi
46
+ @mtkmodel Inertia begin
47
+ @parameters begin
48
+ J, [description = " Moment of inertia" ]
49
+ end
50
+ @components begin
51
+ flange_a = Flange ()
52
+ flange_b = Flange ()
53
+ end
54
+ begin
55
+ @symcheck J > 0 || throw (ArgumentError (" Expected `J` to be positive" ))
56
+ end
57
+ @variables begin
58
+ phi (t) = 0.0 , [description = " Absolute rotation angle" ]
59
+ w (t) = 0.0 , [description = " Absolute angular velocity" ]
60
+ a (t) = 0.0 , [description = " Absolute angular acceleration" ]
61
+ end
62
+ @equations begin
63
+ phi ~ flange_a. phi
54
64
phi ~ flange_b. phi
55
65
D (phi) ~ w
56
66
D (w) ~ a
57
- J * a ~ flange_a. tau + flange_b. tau]
58
- return compose ( ODESystem (eqs, t, sts, [J]; name = name), flange_a, flange_b)
67
+ J * a ~ flange_a. tau + flange_b. tau
68
+ end
59
69
end
60
70
61
71
"""
62
- Spring(;name, c, phi_rel0= 0.0)
72
+ Spring(; name, c, phi_rel0 = 0.0)
63
73
64
74
Linear 1D rotational spring
65
75
@@ -78,19 +88,22 @@ Linear 1D rotational spring
78
88
- `c`: [`N.m/rad`] Spring constant
79
89
- `phi_rel0`: [`rad`] Unstretched spring angle
80
90
"""
81
- @component function Spring (; name, c, phi_rel0 = 0.0 )
82
- @named partial_comp = PartialCompliant ()
83
- @unpack phi_rel, tau = partial_comp
84
- @symcheck c > 0 || throw (ArgumentError (" Expected `c` to be positive" ))
85
- pars = @parameters (c= c, [description = " Spring constant of $name " ],
86
- phi_rel0= phi_rel0,
87
- [description = " Unstretched spring angle of $name " ],)
88
- eqs = [tau ~ c * (phi_rel - phi_rel0)]
89
- extend (ODESystem (eqs, t, [], pars; name = name), partial_comp)
91
+ @mtkmodel Spring begin
92
+ @extend phi_rel, tau = partial_comp = PartialCompliant ()
93
+ begin
94
+ @symcheck c > 0 || throw (ArgumentError (" Expected `c` to be positive" ))
95
+ end
96
+ @parameters begin
97
+ c, [description = " Spring constant" ]
98
+ phi_rel0 = 0.0 , [description = " Unstretched spring angle" ]
99
+ end
100
+ @equations begin
101
+ tau ~ c * (phi_rel - phi_rel0)
102
+ end
90
103
end
91
104
92
105
"""
93
- Damper(;name, d)
106
+ Damper(; name, d)
94
107
95
108
Linear 1D rotational damper
96
109
@@ -110,17 +123,20 @@ Linear 1D rotational damper
110
123
111
124
- `d`: [`N.m.s/rad`] Damping constant
112
125
"""
113
- @component function Damper (; name, d)
114
- @named partial_comp = PartialCompliantWithRelativeStates ()
115
- @unpack w_rel, tau = partial_comp
116
- @symcheck d > 0 || throw (ArgumentError (" Expected `d` to be positive" ))
117
- pars = @parameters d= d [description = " Damping constant of $name " ]
118
- eqs = [tau ~ d * w_rel]
119
- extend (ODESystem (eqs, t, [], pars; name = name), partial_comp)
126
+ @mtkmodel Damper begin
127
+ @extend w_rel, tau = partial_comp = PartialCompliantWithRelativeStates ()
128
+ begin
129
+ @symcheck d > 0 || throw (ArgumentError (" Expected `d` to be positive" ))
130
+ end
131
+ @parameters begin
132
+ d, [description = " Damping constant" ]
133
+ end
134
+ @equations begin
135
+ tau ~ d * w_rel
136
+ end
120
137
end
121
-
122
138
"""
123
- SpringDamper(;name, d)
139
+ SpringDamper(; name, d)
124
140
125
141
Linear 1D rotational spring and damper
126
142
@@ -140,23 +156,28 @@ Linear 1D rotational spring and damper
140
156
141
157
- `d`: [`N.m.s/rad`] Damping constant
142
158
- `c`: [`N.m/rad`] Spring constant
159
+ - `phi_rel0`: [`rad`] Unstretched spring angle
143
160
"""
144
- @component function SpringDamper (; name, c, d, phi_rel0 = 0.0 )
145
- @named partial_comp = PartialCompliantWithRelativeStates ()
146
- @unpack phi_rel, w_rel, tau = partial_comp
147
- @variables tau_c (t) [description = " Spring torque" ]
148
- @variables tau_d (t) [description = " Damper torque" ]
149
- @parameters d= d [description = " Damping constant" ]
150
- @parameters c= c [description = " Spring constant" ]
151
- @parameters phi_rel0= phi_rel0 [description = " Unstretched spring angle" ]
152
- eqs = [tau_c ~ c * (phi_rel - phi_rel0)
161
+ @mtkmodel SpringDamper begin
162
+ @extend phi_rel, w_rel, tau = partial_comp = PartialCompliantWithRelativeStates ()
163
+ @variables begin
164
+ tau_c (t), [description = " Spring torque" ]
165
+ tau_d (t), [description = " Damper torque" ]
166
+ end
167
+ @parameters begin
168
+ d, [description = " Damping constant" ]
169
+ c, [description = " Spring constant" ]
170
+ phi_rel0 = 0.0 , [description = " Unstretched spring angle" ]
171
+ end
172
+ @equations begin
173
+ tau_c ~ c * (phi_rel - phi_rel0)
153
174
tau_d ~ d * w_rel
154
- tau ~ tau_c + tau_d]
155
- extend ( ODESystem (eqs, t; name = name), partial_comp)
175
+ tau ~ tau_c + tau_d
176
+ end
156
177
end
157
178
158
179
"""
159
- IdealGear(;name, ratio, use_support= false)
180
+ IdealGear(; name, ratio, use_support = false)
160
181
161
182
Ideal gear without inertia.
162
183
@@ -178,22 +199,28 @@ This element characterizes any type of gear box which is fixed in the ground and
178
199
- `ratio`: Transmission ratio (flange_a.phi/flange_b.phi)
179
200
- `use_support`: If support flange enabled, otherwise implicitly grounded
180
201
"""
181
- @component function IdealGear (; name, ratio, use_support = false )
182
- @named partial_element = PartialElementaryTwoFlangesAndSupport2 (use_support = use_support)
183
- @unpack phi_support, flange_a, flange_b = partial_element
184
- @parameters ratio= ratio [description = " Transmission ratio of $name " ]
185
- sts = @variables phi_a (t)= 0.0 [
186
- description = " Relative angle between shaft a and the support of $name " ,
187
- ] phi_b (t)= 0.0 [description = " Relative angle between shaft b and the support of $name " ]
188
- eqs = [phi_a ~ flange_a. phi - phi_support
202
+ @mtkmodel IdealGear begin # (; name, ratio, use_support = false)
203
+ @parameters begin
204
+ use_support
205
+ end
206
+ @extend phi_support, flange_a, flange_b = partial_element = PartialElementaryTwoFlangesAndSupport2 (use_support = use_support)
207
+ @parameters begin
208
+ ratio, [description = " Transmission ratio" ]
209
+ end
210
+ @variables begin
211
+ phi_a (t) = 0.0 , [description = " Relative angle between shaft a and the support" ]
212
+ phi_b (t) = 0.0 , [description = " Relative angle between shaft b and the support" ]
213
+ end
214
+ @equations begin
215
+ phi_a ~ flange_a. phi - phi_support
189
216
phi_b ~ flange_b. phi - phi_support
190
217
phi_a ~ ratio * phi_b
191
- 0 ~ ratio * flange_a. tau + flange_b. tau]
192
- extend ( ODESystem (eqs, t, sts, [ratio]; name = name), partial_element)
218
+ 0 ~ ratio * flange_a. tau + flange_b. tau
219
+ end
193
220
end
194
221
195
222
"""
196
- RotationalFriction(;name, f, tau_c, w_brk, tau_brk)
223
+ RotationalFriction(; name, f, tau_c, w_brk, tau_brk)
197
224
198
225
Models rotational friction with Stribeck effect, Coulomb friction and viscous friction between the two flanges.
199
226
The friction torque is a function of the relative angular velocity between `flange_a` and `flange_b`.
@@ -219,22 +246,22 @@ Friction model: "Armstrong, B. and C.C. de Wit, Friction Modeling and Compensati
219
246
- `w_brk`: [`rad/s`] Breakaway friction velocity
220
247
- `tau_brk`: [`N⋅m`] Breakaway friction torque
221
248
"""
222
- @component function RotationalFriction (; name, f, tau_c, w_brk, tau_brk)
223
- @named partial_comp = PartialCompliantWithRelativeStates ()
224
- @unpack w_rel, tau = partial_comp
225
- pars = @parameters (f= f, [description = " Viscous friction coefficient of $name " ],
226
- tau_c= tau_c, [description = " Coulomb friction torque of $name " ],
227
- w_brk= w_brk, [description = " Breakaway friction velocity of $name " ],
228
- tau_brk= tau_brk,
229
- [description = " Breakaway friction torque of $name " ],)
230
-
231
- str_scale = sqrt (2 * exp (1 )) * (tau_brk - tau_c)
232
- w_st = w_brk * sqrt (2 )
233
- w_coul = w_brk / 10
234
-
235
- eqs = [
249
+ @mtkmodel RotationalFriction begin
250
+ @extend w_rel, tau = partial_comp = PartialCompliantWithRelativeStates ()
251
+ @parameters begin
252
+ f, [description = " Viscous friction coefficient" ]
253
+ tau_c, [description = " Coulomb friction torque" ]
254
+ w_brk, [description = " Breakaway friction velocity" ]
255
+ tau_brk, [description = " Breakaway friction torque" ]
256
+ end
257
+
258
+ begin
259
+ str_scale = sqrt (2 * exp (1 )) * (tau_brk - tau_c)
260
+ w_st = w_brk * sqrt (2 )
261
+ w_coul = w_brk / 10
262
+ end
263
+ @equations begin
236
264
tau ~ str_scale * (exp (- (w_rel / w_st)^ 2 ) * w_rel / w_st) +
237
- tau_c * tanh (w_rel / w_coul) + f * w_rel, # Stribeck friction + Coulomb friction + Viscous friction
238
- ]
239
- extend (ODESystem (eqs, t, [], pars; name = name), partial_comp)
265
+ tau_c * tanh (w_rel / w_coul) + f * w_rel # Stribeck friction + Coulomb friction + Viscous friction
266
+ end
240
267
end
0 commit comments