@@ -152,6 +152,140 @@ A fixed translation between two components (rigid rod)
152
152
end
153
153
end
154
154
155
+ """
156
+ Spring(; name, c_x = 1, c_y = 1, c_phi = 1e5, s_relx0 = 0, s_rely0 = 0, phi_rel0 = 0, s_small = 1.e-10)
157
+
158
+ Linear 2D translational spring
159
+
160
+ # Parameters:
161
+
162
+ - `c_x`: [N/m] Spring constant in x dir
163
+ - `c_y`: [N/m] Spring constant in y dir
164
+ - `c_phi`: [N.m/rad] Spring constant in phi dir
165
+ - `s_relx0`: [m] Unstretched spring length
166
+ - `s_rely0`: [m] Unstretched spring length
167
+ - `phi_rel0`: [rad] Unstretched spring angle
168
+ - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
169
+
170
+
171
+ # Connectors:
172
+
173
+ - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
174
+ - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
175
+
176
+ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Spring.mo
177
+ """
178
+ @mtkmodel Spring begin
179
+ @extend frame_a, frame_b = partial_frames = PartialTwoFrames ()
180
+
181
+ @parameters begin
182
+ c_x = 1 , [description = " Spring constant in x dir" ]
183
+ c_y = 1 , [description = " Spring constant in y dir" ]
184
+ c_phi = 1.0e5 , [description = " Spring constant" ]
185
+ s_relx0 = 0 , [description = " Unstretched spring length" ]
186
+ s_rely0 = 0 , [description = " Unstretched spring length" ]
187
+ phi_rel0 = 0 , [description = " Unstretched spring angle" ]
188
+ s_small = 1.e-10 ,
189
+ [
190
+ description = " Prevent zero-division if distance between frame_a and frame_b is zero" ,
191
+ ]
192
+ end
193
+
194
+ @variables begin
195
+ s_relx (t) = 0
196
+ s_rely (t) = 0
197
+ phi_rel (t) = 0
198
+ f_x (t)
199
+ f_y (t)
200
+ end
201
+
202
+ begin
203
+ r_rel_0 = [s_relx, s_rely, 0 ]
204
+ l = sqrt (r_rel_0' * r_rel_0)
205
+ e_rel_0 = r_rel_0 / max (l, s_small)
206
+ end
207
+
208
+ @equations begin
209
+ phi_rel ~ frame_b. phi - frame_a. phi
210
+ frame_a. j ~ 0
211
+ frame_b. j ~ 0
212
+ s_relx ~ frame_b. x - frame_a. x
213
+ s_rely ~ frame_b. y - frame_a. y
214
+ f_x ~ c_x * (s_relx - s_relx0)
215
+ f_y ~ c_y * (s_rely - s_rely0)
216
+ frame_a. fx ~ - f_x
217
+ frame_b. fx ~ f_x
218
+ frame_a. fy ~ - f_y
219
+ frame_b. fy ~ f_y
220
+ end
221
+ end
222
+
223
+ """
224
+ Damper(; name, d = 1, s_smal = 1.e-10)
225
+
226
+ Linear (velocity dependent) damper
227
+
228
+ # Parameters:
229
+
230
+ - `d`: [N.s/m] Damoing constant
231
+ - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
232
+
233
+
234
+ # Connectors:
235
+
236
+ - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
237
+ - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
238
+
239
+
240
+ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Damper.mo
241
+ """
242
+ @mtkmodel Damper begin
243
+ @extend frame_a, frame_b = partial_frames = PartialTwoFrames ()
244
+
245
+ @parameters begin
246
+ d = 1 , [description = " damping constant" ]
247
+ s_small = 1.e-10 ,
248
+ [
249
+ description = " Prevent zero-division if distance between frame_a and frame_b is zero" ,
250
+ ]
251
+ end
252
+
253
+ @variables begin
254
+ r0x (t) = 0
255
+ r0y (t) = 0
256
+ d0x (t) = 0
257
+ d0y (t) = 0
258
+ vx (t) = 0
259
+ vy (t) = 0
260
+ v (t)
261
+ f (t)
262
+ end
263
+
264
+ begin
265
+ r0 = [r0x, r0y]
266
+ l = sqrt (r0' * r0)
267
+ end
268
+
269
+ @equations begin
270
+ frame_a. x + r0x ~ frame_b. x
271
+ frame_a. y + r0y ~ frame_b. y
272
+ D (frame_a. x) + vx ~ D (frame_b. x)
273
+ D (frame_a. y) + vy ~ D (frame_b. y)
274
+ v ~ [vx, vy]' * [d0x, d0y]
275
+ f ~ - d * v
276
+ d0x ~ ifelse (l < s_small, r0[1 ], r0[1 ] / l)
277
+ d0y ~ ifelse (l < s_small, r0[2 ], r0[2 ] / l)
278
+ frame_a. fx ~ d0x * f
279
+ frame_a. fy ~ d0y * f
280
+ frame_a. j ~ 0
281
+ frame_a. fx + frame_b. fx ~ 0
282
+ frame_a. fy + frame_b. fy ~ 0
283
+ frame_a. j + frame_b. j ~ 0
284
+
285
+ # lossPower ~ -f * v
286
+ end
287
+ end
288
+
155
289
"""
156
290
SpringDamper(; name, c_x = 1, c_y = 1, c_phi = 1e5, d_x = 1, d_y = 1, d_phi = 1, s_relx0 = 0, s_rely0 = 0, phi_rel0 = 0, s_small = 1.e-10)
157
291
0 commit comments