@@ -16,15 +16,15 @@ Flange fixed in housing at a given angle.
1616 flange = Flange ()
1717 end
1818 @parameters begin
19- phi0, [description = " Fixed offset angle of flange" ]
19+ phi0 = 0.0 , [description = " Fixed offset angle of flange" ]
2020 end
2121 @equations begin
2222 flange. phi ~ phi0
2323 end
2424end
2525
2626"""
27- 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)
2828
29291D-rotational component with inertia.
3030
4646 - `w_start`: [`rad/s`] Initial value of absolute angular velocity of component
4747 - `a_start`: [`rad/s²`] Initial value of absolute angular acceleration of component
4848"""
49- @component function Inertia (; name, J, phi_start = 0.0 , w_start = 0.0 , a_start = 0.0 )
50- @named flange_a = Flange ()
51- @named flange_b = Flange ()
52- @symcheck J > 0 || throw (ArgumentError (" Expected `J` to be positive" ))
53- @parameters J= J [description = " Moment of inertia of $name " ]
54- sts = @variables (phi (t)= phi_start, [description = " Absolute rotation angle of $name " ],
55- w (t)= w_start, [description = " Absolute angular velocity of $name " ],
56- a (t)= a_start,
57- [description = " Absolute angular acceleration of $name " ],)
58- eqs = [phi ~ flange_a. phi
49+ @mtkmodel Inertia begin
50+ @parameters begin
51+ J, [description = " Moment of inertia" ]
52+ phi_start = 0.0
53+ w_start = 0.0
54+ a_start = 0.0
55+ end
56+ @components begin
57+ flange_a = Flange ()
58+ flange_b = Flange ()
59+ end
60+ begin
61+ @symcheck J > 0 || throw (ArgumentError (" Expected `J` to be positive" ))
62+ end
63+ @variables begin
64+ phi (t) = phi_start, [description = " Absolute rotation angle" ]
65+ w (t) = w_start, [description = " Absolute angular velocity" ]
66+ a (t) = a_start, [description = " Absolute angular acceleration" ]
67+ end
68+ @equations begin
69+ phi ~ flange_a. phi
5970 phi ~ flange_b. phi
6071 D (phi) ~ w
6172 D (w) ~ a
62- J * a ~ flange_a. tau + flange_b. tau]
63- return compose ( ODESystem (eqs, t, sts, [J]; name = name), flange_a, flange_b)
73+ J * a ~ flange_a. tau + flange_b. tau
74+ end
6475end
6576
6677"""
@@ -83,15 +94,18 @@ Linear 1D rotational spring
8394 - `c`: [`N.m/rad`] Spring constant
8495 - `phi_rel0`: [`rad`] Unstretched spring angle
8596"""
86- @component function Spring (; name, c, phi_rel0 = 0.0 )
87- @named partial_comp = PartialCompliant ()
88- @unpack phi_rel, tau = partial_comp
89- @symcheck c > 0 || throw (ArgumentError (" Expected `c` to be positive" ))
90- pars = @parameters (c= c, [description = " Spring constant of $name " ],
91- phi_rel0= phi_rel0,
92- [description = " Unstretched spring angle of $name " ],)
93- eqs = [tau ~ c * (phi_rel - phi_rel0)]
94- extend (ODESystem (eqs, t, [], pars; name = name), partial_comp)
97+ @mtkmodel Spring begin
98+ @extend phi_rel, tau = partial_comp = PartialCompliant ()
99+ begin
100+ @symcheck c > 0 || throw (ArgumentError (" Expected `c` to be positive" ))
101+ end
102+ @parameters begin
103+ c, [description = " Spring constant" ]
104+ phi_rel0 = 0.0 , [description = " Unstretched spring angle" ]
105+ end
106+ @equations begin
107+ tau ~ c * (phi_rel - phi_rel0)
108+ end
95109end
96110
97111"""
@@ -149,18 +163,22 @@ Linear 1D rotational spring and damper
149163 - `d`: [`N.m.s/rad`] Damping constant
150164 - `c`: [`N.m/rad`] Spring constant
151165"""
152- @component function SpringDamper (; name, c, d, phi_rel0 = 0.0 )
153- @named partial_comp = PartialCompliantWithRelativeStates ()
154- @unpack phi_rel, w_rel, tau = partial_comp
155- @variables tau_c (t) [description = " Spring torque" ]
156- @variables tau_d (t) [description = " Damper torque" ]
157- @parameters d= d [description = " Damping constant" ]
158- @parameters c= c [description = " Spring constant" ]
159- @parameters phi_rel0= phi_rel0 [description = " Unstretched spring angle" ]
160- eqs = [tau_c ~ c * (phi_rel - phi_rel0)
166+ @mtkmodel SpringDamper begin
167+ @extend phi_rel, w_rel, tau = partial_comp = PartialCompliantWithRelativeStates ()
168+ @variables begin
169+ tau_c (t), [description = " Spring torque" ]
170+ tau_d (t), [description = " Damper torque" ]
171+ end
172+ @parameters begin
173+ d, [description = " Damping constant" ]
174+ c, [description = " Spring constant" ]
175+ phi_rel0 = 0.0 , [description = " Unstretched spring angle" ]
176+ end
177+ @equations begin
178+ tau_c ~ c * (phi_rel - phi_rel0)
161179 tau_d ~ d * w_rel
162- tau ~ tau_c + tau_d]
163- extend ( ODESystem (eqs, t; name = name), partial_comp)
180+ tau ~ tau_c + tau_d
181+ end
164182end
165183
166184"""
@@ -186,18 +204,24 @@ This element characterizes any type of gear box which is fixed in the ground and
186204 - `ratio`: Transmission ratio (flange_a.phi/flange_b.phi)
187205 - `use_support`: If support flange enabled, otherwise implicitly grounded
188206"""
189- @component function IdealGear (; name, ratio, use_support = false )
190- @named partial_element = PartialElementaryTwoFlangesAndSupport2 (use_support = use_support)
191- @unpack phi_support, flange_a, flange_b = partial_element
192- @parameters ratio= ratio [description = " Transmission ratio of $name " ]
193- sts = @variables phi_a (t)= 0.0 [
194- description = " Relative angle between shaft a and the support of $name " ,
195- ] phi_b (t)= 0.0 [description = " Relative angle between shaft b and the support of $name " ]
196- eqs = [phi_a ~ flange_a. phi - phi_support
207+ @mtkmodel IdealGear begin # (; name, ratio, use_support = false)
208+ @parameters begin
209+ use_support
210+ end
211+ @extend phi_support, flange_a, flange_b = partial_element = PartialElementaryTwoFlangesAndSupport2 (use_support = use_support)
212+ @parameters begin
213+ ratio, [description = " Transmission ratio" ]
214+ end
215+ @variables begin
216+ phi_a (t) = 0.0 , [description = " Relative angle between shaft a and the support" ]
217+ phi_b (t) = 0.0 , [description = " Relative angle between shaft b and the support" ]
218+ end
219+ @equations begin
220+ phi_a ~ flange_a. phi - phi_support
197221 phi_b ~ flange_b. phi - phi_support
198222 phi_a ~ ratio * phi_b
199- 0 ~ ratio * flange_a. tau + flange_b. tau]
200- extend ( ODESystem (eqs, t, sts, [ratio]; name = name), partial_element)
223+ 0 ~ ratio * flange_a. tau + flange_b. tau
224+ end
201225end
202226
203227"""
@@ -227,22 +251,22 @@ Friction model: "Armstrong, B. and C.C. de Wit, Friction Modeling and Compensati
227251 - `w_brk`: [`rad/s`] Breakaway friction velocity
228252 - `tau_brk`: [`N⋅m`] Breakaway friction torque
229253"""
230- @component function RotationalFriction (; name, f, tau_c, w_brk, tau_brk)
231- @named partial_comp = PartialCompliantWithRelativeStates ()
232- @unpack w_rel, tau = partial_comp
233- pars = @parameters ( f= f, [description = " Viscous friction coefficient of $name " ],
234- tau_c= tau_c, [description = " Coulomb friction torque of $name " ],
235- w_brk= w_brk, [description = " Breakaway friction velocity of $name " ],
236- tau_brk= tau_brk,
237- [description = " Breakaway friction torque of $name " ],)
238-
239- str_scale = sqrt ( 2 * exp ( 1 )) * (tau_brk - tau_c)
240- w_st = w_brk * sqrt (2 )
241- w_coul = w_brk / 10
242-
243- eqs = [
244- tau ~ str_scale * ( exp ( - (w_rel / w_st) ^ 2 ) * w_rel / w_st) +
245- tau_c * tanh ( w_rel / w_coul) + f * w_rel, # Stribeck friction + Coulomb friction + Viscous friction
246- ]
247- extend ( ODESystem (eqs, t, [], pars; name = name), partial_comp)
254+ @mtkmodel RotationalFriction begin
255+ @extend w_rel, tau = partial_comp = PartialCompliantWithRelativeStates ()
256+ @parameters begin
257+ f= f, [description = " Viscous friction coefficient" ]
258+ tau_c= tau_c, [description = " Coulomb friction torque" ]
259+ w_brk= w_brk, [description = " Breakaway friction velocity" ]
260+ tau_brk= tau_brk, [description = " Breakaway friction torque " ]
261+ end
262+
263+ begin
264+ str_scale = sqrt (2 * exp ( 1 )) * (tau_brk - tau_c )
265+ w_st = w_brk * sqrt ( 2 )
266+ w_coul = w_brk / 10
267+ end
268+ @equations begin
269+ tau ~ str_scale * ( exp ( - ( w_rel / w_st) ^ 2 ) * w_rel / w_st) +
270+ tau_c * tanh (w_rel / w_coul) + f * w_rel # Stribeck friction + Coulomb friction + Viscous friction
271+ end
248272end
0 commit comments