1
+ purple = Multibody. purple
1
2
"""
2
3
Fixed(; name, r = (0.0, 0.0), phi = 0.0)
3
4
@@ -13,7 +14,6 @@ Frame fixed in the planar world frame at a given position and orientation
13
14
14
15
- `frame: 2-dim. Coordinate system
15
16
16
- https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Fixed.mo
17
17
"""
18
18
@mtkmodel Fixed begin
19
19
@parameters begin
@@ -34,44 +34,40 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
34
34
end
35
35
36
36
"""
37
- Body(; name, m, j , r, g = nothing )
37
+ Body(; name, m=1, I=0.1 , r=0, gy=-9.807, radius=0.1, render=true, color=Multibody.purple )
38
38
39
39
Body component with mass and inertia
40
40
41
41
# Parameters:
42
-
43
- - `m`: [kg] mass of the body
44
- - `j`: [kg.m²] inertia of the body with respect to the origin of `frame` along the z-axis of `frame`
45
- - `r`: [m, m] (optional) Translational position x,y-position
46
- - `gy`: [m/s²] (optional) gravity field acting on the mass in the y-direction, positive value acts in the positive direction defaults to -9.807
47
-
48
- # States:
49
-
50
- - `rx`: [m] x position
51
- - `ry`: [m] y position
52
- - `vx`: [m/s] x velocity
53
- - `vy`: [m/s] y velocity
54
- - `ax`: [m/s²] x acceleration
55
- - `ay`: [m/s²] y acceleration
42
+ - `m`: [kg] mass of the body
43
+ - `j`: [kg.m²] inertia of the body with respect to the origin of `frame` along the z-axis of `frame`
44
+ - `r`: [m, m] Translational position x,y-position
45
+ - `gy`: [m/s²] gravity field acting on the mass in the y-direction, positive value acts in the positive direction defaults to -9.807
46
+ - `radius`: [m] Radius of the body in animations
47
+ - `render`: [Bool] Render the body in animations
48
+ - `color`: [Array{Float64,1}] Color of the body in animations
49
+
50
+ # Variables:
51
+ - `r`: [m, m] x,y position
52
+ - `v`: [m/s, m/s] x,y velocity
53
+ - `a`: [m/s², m/s²] x,y acceleration
56
54
- `phi`: [rad] rotation angle (counterclockwise)
57
55
- `ω`: [rad/s] angular velocity
58
56
- `α`: [rad/s²] angular acceleration
59
57
60
58
# Connectors:
61
-
62
59
- `frame`: 2-dim. Coordinate system
63
-
64
- https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Body.mo
65
60
"""
66
61
@component function Body (; name, m, I, r = zeros (2 ), phi = 0 , gy = - 9.807 , radius= 0.1 , render= true , color= Multibody. purple)
67
62
@named frame = Frame ()
68
63
pars = @parameters begin
69
- m = m
70
- I = I
71
- gy = gy
64
+ m = m, [description = " Mass of the body " ]
65
+ I = I, [description = " Inertia of the body with respect to the origin of frame_a along the z-axis of frame_a " ]
66
+ gy = gy, [description = " Gravity field acting on the mass in the y-direction, positive value acts in the positive direction " ]
72
67
radius = radius, [description = " Radius of the body in animations" ]
73
68
render = render, [description = " Render the body in animations" ]
74
69
color[1 : 4 ] = color, [description = " Color of the body in animations" ]
70
+ z = 0 , [description = " Fixed z-position" ]
75
71
end
76
72
77
73
vars = @variables begin
@@ -95,30 +91,68 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
95
91
α .~ D .(ω)
96
92
# newton's law
97
93
f .~ [frame. fx, frame. fy]
98
- f .~ m * a + m * [0 , - gy]# ifelse(gy !== nothing, fy / m + gy, fy / m),
94
+ f + [0 , m * gy] .~ m * a # ifelse(gy !== nothing, fy / m + gy, fy / m),
99
95
I * α ~ frame. j
100
96
]
101
97
102
98
return compose (ODESystem (eqs, t, vars, pars; name),
103
99
frame)
104
100
end
105
101
102
+ """
103
+ BodyShape(; name, r = [1,0], r_cm = 0.5*r, gy = -9.807)
104
+
105
+ The `BodyShape` component is similar to a [`Body`](@ref), but it has two frames and a vector `r` that describes the translation between them, while the body has a single frame only.
106
+
107
+ # Parameters
108
+ - `r`: (Structural) Vector from `frame_a` to `frame_b` resolved in `frame_a`
109
+ - `r_cm`: (Structural) Vector from `frame_a` to the center of mass resolved in `frame_a`
110
+ """
111
+ @mtkmodel BodyShape begin
112
+ @structural_parameters begin
113
+ r = [1 ,0 ]
114
+ r_cm = 0.5 * r
115
+ gy = - 9.807
116
+ end
117
+ @parameters begin
118
+ # r[1:2] = [1,0], [description = "Fixed x,y-length of the rod resolved w.r.t to body frame_a at phi = 0"]
119
+ # r_cm[1:2] = 0.5*r, [description = "Vector from frame_a to center of mass, resolved in frame_a"]
120
+ m = 1 , [description = " mass of the body" ]
121
+ I = 0.1 , [description = " inertia of the body with respect to the center of mass" ]
122
+ radius = 0.1 , [description = " Radius of the body in animations" ]
123
+ render = true , [description = " Render the body in animations" ]
124
+ (color[1 : 4 ] = purple), [description = " Color of the body in animations" ]
125
+ end
126
+ @components begin
127
+ translation = FixedTranslation (; r)
128
+ translation_cm = FixedTranslation (; r= r_cm)
129
+ body = Body (; r= r_cm, I, m, gy)
130
+ frame_a = Frame ()
131
+ frame_b = Frame ()
132
+ end
133
+ @equations begin
134
+ connect (frame_a, translation. frame_a, translation_cm. frame_a)
135
+ connect (frame_b, translation. frame_b)
136
+ connect (translation_cm. frame_b, body. frame)
137
+ end
138
+ end
139
+
106
140
"""
107
141
FixedTranslation(; name, r::AbstractArray, l)
108
142
109
143
A fixed translation between two components (rigid rod)
110
144
111
145
# Parameters:
112
-
113
- - `rx`: [m] Fixed x-length of the rod resolved w.r.t to body frame_a at phi = 0
114
- - `ry`: [m] Fixed y-length of the rod resolved w.r.t to body frame_a at phi = 0
146
+ - `rx`: [m] Fixed x-length of the rod resolved w.r.t to body frame_a at phi = 0
147
+ - `ry`: [m] Fixed y-length of the rod resolved w.r.t to body frame_a at phi = 0
148
+ - `radius`: [m] Radius of the rod in animations
149
+ - `render`: [Bool] Render the rod in animations
115
150
116
151
# Connectors:
117
-
118
- - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
119
- - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
120
152
121
- https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/FixedTranslation.mo
153
+ - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
154
+ - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
155
+
122
156
"""
123
157
@mtkmodel FixedTranslation begin
124
158
@extend frame_a, frame_b = partial_frames = PartialTwoFrames ()
@@ -159,22 +193,23 @@ end
159
193
Linear 2D translational spring
160
194
161
195
# Parameters:
162
-
163
- - `c_x`: [N/m] Spring constant in x dir
164
- - `c_y`: [N/m] Spring constant in y dir
165
- - `c_phi`: [N.m/rad] Spring constant in phi dir
166
- - `s_relx0`: [m] Unstretched spring length
167
- - `s_rely0`: [m] Unstretched spring length
168
- - `phi_rel0`: [rad] Unstretched spring angle
169
- - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
170
-
196
+ - `c_x`: [N/m] Spring constant in x dir
197
+ - `c_y`: [N/m] Spring constant in y dir
198
+ - `c_phi`: [N.m/rad] Spring constant in phi dir
199
+ - `s_relx0`: [m] Unstretched spring length
200
+ - `s_rely0`: [m] Unstretched spring length
201
+ - `phi_rel0`: [rad] Unstretched spring angle
202
+ - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
203
+ - `num_windings`: [Int] Number of windings of the coil when rendered
204
+ - `color = [0,0,1,1]` Color of the spring in animations
205
+ - `render = true` Render the spring in animations
206
+ - `radius = 0.1` Radius of spring when rendered
207
+ - `N = 200` Number of points in mesh when rendered
171
208
172
209
# Connectors:
210
+ - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
211
+ - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
173
212
174
- - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
175
- - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
176
-
177
- https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Spring.mo
178
213
"""
179
214
@mtkmodel Spring begin
180
215
@extend frame_a, frame_b = partial_frames = PartialTwoFrames ()
@@ -232,18 +267,13 @@ end
232
267
Linear (velocity dependent) damper
233
268
234
269
# Parameters:
235
-
236
- - `d`: [N.s/m] Damoing constant
237
- - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
270
+ - `d`: [N.s/m] Damping constant
271
+ - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
238
272
239
273
240
274
# Connectors:
241
-
242
- - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
243
- - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
244
-
245
-
246
- https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Damper.mo
275
+ - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
276
+ - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
247
277
"""
248
278
@mtkmodel Damper begin
249
279
@extend frame_a, frame_b = partial_frames = PartialTwoFrames ()
@@ -298,25 +328,26 @@ end
298
328
Linear 2D translational spring damper model
299
329
300
330
# Parameters:
301
-
302
- - `c_x`: [N/m] Spring constant in x dir
303
- - `c_y`: [N/m] Spring constant in y dir
304
- - `c_phi`: [N.m/rad] Spring constant in phi dir
305
- - `d_x`: [N.s/m] Damping constant in x dir
306
- - `d_y`: [N.s/m] Damping constant in y dir
307
- - `d_phi`: [N.m.s/rad] Damping constant in phi dir
308
- - `s_relx0`: [m] Unstretched spring length
309
- - `s_rely0`: [m] Unstretched spring length
310
- - `phi_rel0`: [rad] Unstretched spring angle
311
- - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
312
-
331
+ - `c_x`: [N/m] Spring constant in x dir
332
+ - `c_y`: [N/m] Spring constant in y dir
333
+ - `c_phi`: [N.m/rad] Spring constant in phi dir
334
+ - `d_x`: [N.s/m] Damping constant in x dir
335
+ - `d_y`: [N.s/m] Damping constant in y dir
336
+ - `d_phi`: [N.m.s/rad] Damping constant in phi dir
337
+ - `s_relx0`: [m] Unstretched spring length
338
+ - `s_rely0`: [m] Unstretched spring length
339
+ - `phi_rel0`: [rad] Unstretched spring angle
340
+ - `s_small`: [m] Prevent zero-division if distance between frame_a and frame_b is zero
341
+ - `num_windings`: [Int] Number of windings of the coil when rendered
342
+ - `color = [0,0,1,1]` Color of the spring in animations
343
+ - `render = true` Render the spring in animations
344
+ - `radius = 0.1` Radius of spring when rendered
345
+ - `N = 200` Number of points in mesh when rendered
313
346
314
347
# Connectors:
348
+ - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
349
+ - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
315
350
316
- - `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
317
- - `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
318
-
319
- https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/SpringDamper.mo
320
351
"""
321
352
@mtkmodel SpringDamper begin
322
353
@extend frame_a, frame_b = partial_frames = PartialTwoFrames ()
0 commit comments