-
Notifications
You must be signed in to change notification settings - Fork 164
/
Parts.mo
2979 lines (2833 loc) · 127 KB
/
Parts.mo
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
within Modelica.Mechanics.MultiBody;
package Parts
"Rigid components such as bodies with mass and inertia and massless rods"
extends Modelica.Icons.Package;
model Fixed "Frame fixed in the world frame at a given position"
import Modelica.Mechanics.MultiBody.Types;
import Modelica.SIunits.Conversions.to_unit1;
Interfaces.Frame_b frame_b "Coordinate system fixed in the world frame"
annotation (Placement(transformation(extent={{84,-16},{116,16}})));
parameter Boolean animation=true "= true, if animation shall be enabled";
parameter SI.Position r[3]={0,0,0}
"Position vector from world frame to frame_b, resolved in world frame";
parameter Types.ShapeType shapeType="cylinder" "Type of shape" annotation (
Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Position r_shape[3]={0,0,0}
"Vector from world frame to shape origin, resolved in world frame"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.Axis lengthDirection = to_unit1(r - r_shape)
"Vector in length direction of shape, resolved in world frame"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.Axis widthDirection={0,1,0}
"Vector in width direction of shape, resolved in world frame"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Length length=Modelica.Math.Vectors.length(r - r_shape)
"Length of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance width=length/world.defaultWidthFraction
"Width of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance height=width "Height of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.ShapeExtra extra=0.0
"Additional parameter for cone, pipe etc. (see docu of Visualizers.Advanced.Shape)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
input Types.Color color=Modelica.Mechanics.MultiBody.Types.Defaults.RodColor
"Color of shape" annotation (Dialog(
colorSelector=true,
tab="Animation",
group="if animation = true",
enable=animation));
input Types.SpecularCoefficient specularCoefficient=world.defaultSpecularCoefficient
"Reflection of ambient light (= 0: light is completely absorbed)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
protected
outer Modelica.Mechanics.MultiBody.World world;
Visualizers.Advanced.Shape shape(
shapeType=shapeType,
color=color,
specularCoefficient=specularCoefficient,
length=length,
width=width,
height=height,
lengthDirection=lengthDirection,
widthDirection=widthDirection,
extra=extra,
r_shape=r_shape,
r=zeros(3),
R=Frames.nullRotation()) if world.enableAnimation and animation;
equation
Connections.root(frame_b.R);
frame_b.r_0 = r;
frame_b.R = Frames.nullRotation();
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Rectangle(
extent={{-90,90},{90,-90}},
lineColor={255,255,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Text(
extent={{150,145},{-150,105}},
textString="%name",
textColor={0,0,255}),
Line(points={{0,100},{0,-100}}),
Line(points={{0,-80},{-100,-20}}),
Line(points={{0,-40},{-100,20}}),
Line(points={{0,0},{-100,60}}),
Line(points={{0,40},{-100,100}}),
Line(points={{0,0},{100,0}}),
Text(
extent={{-150,-105},{150,-135}},
textString="r=%r")}),
Documentation(info="<html>
<p>
Element consisting of a frame (frame_b) that is fixed in the world
frame at a given position defined by parameter vector <strong>r</strong>
(vector from origin of world frame to frame_b, resolved in the
world frame).
</p>
<p>
By default, this component is visualized by a cylinder connecting the
world frame and frame_b of this components, as shown in the figure below.
Note, that the visualized world frame on the left side and
Fixed.frame_b on the right side are not part of the
component animation and that the animation may be switched off via parameter
animation = <strong>false</strong>.
</p>
<p>
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Parts/Fixed.png\" alt=\"Parts.Fixed\">
</p>
</html>"));
end Fixed;
model FixedTranslation "Fixed translation of frame_b with respect to frame_a"
import Modelica.Mechanics.MultiBody.Types;
import Modelica.SIunits.Conversions.to_unit1;
Interfaces.Frame_a frame_a
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
Interfaces.Frame_b frame_b
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{84,-16},{116,16}})));
parameter Boolean animation=true "= true, if animation shall be enabled";
parameter SI.Position r[3](start={0,0,0})
"Vector from frame_a to frame_b resolved in frame_a";
parameter Types.ShapeType shapeType="cylinder" "Type of shape" annotation (
Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Position r_shape[3]={0,0,0}
"Vector from frame_a to shape origin, resolved in frame_a" annotation (
Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.Axis lengthDirection = to_unit1(r - r_shape)
"Vector in length direction of shape, resolved in frame_a" annotation (
Evaluate=true, Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.Axis widthDirection={0,1,0}
"Vector in width direction of shape, resolved in frame_a" annotation (
Evaluate=true, Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Length length=Modelica.Math.Vectors.length(r - r_shape)
"Length of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance width=length/world.defaultWidthFraction
"Width of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance height=width "Height of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.ShapeExtra extra=0.0
"Additional parameter depending on shapeType (see docu of Visualizers.Advanced.Shape)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
input Types.Color color=Modelica.Mechanics.MultiBody.Types.Defaults.RodColor
"Color of shape" annotation (Dialog(
colorSelector=true,
tab="Animation",
group="if animation = true",
enable=animation));
input Types.SpecularCoefficient specularCoefficient=world.defaultSpecularCoefficient
"Reflection of ambient light (= 0: light is completely absorbed)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
protected
outer Modelica.Mechanics.MultiBody.World world;
Visualizers.Advanced.Shape shape(
shapeType=shapeType,
color=color,
specularCoefficient=specularCoefficient,
r_shape=r_shape,
lengthDirection=lengthDirection,
widthDirection=widthDirection,
length=length,
width=width,
height=height,
extra=extra,
r=frame_a.r_0,
R=frame_a.R) if world.enableAnimation and animation;
equation
Connections.branch(frame_a.R, frame_b.R);
assert(cardinality(frame_a) > 0 or cardinality(frame_b) > 0,
"Neither connector frame_a nor frame_b of FixedTranslation object is connected");
frame_b.r_0 = frame_a.r_0 + Frames.resolve1(frame_a.R, r);
frame_b.R = frame_a.R;
/* Force and torque balance */
zeros(3) = frame_a.f + frame_b.f;
zeros(3) = frame_a.t + frame_b.t + cross(r, frame_b.f);
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Rectangle(
extent={{-99,5},{101,-5}},
fillPattern=FillPattern.Solid),
Text(
extent={{-150,85},{150,45}},
textString="%name",
textColor={0,0,255}),
Text(
extent={{150,-50},{-150,-20}},
textString="r=%r"),
Text(
extent={{-89,38},{-53,13}},
textColor={128,128,128},
textString="a"),
Text(
extent={{57,39},{93,14}},
textColor={128,128,128},
textString="b")}),
Documentation(info="<html>
<p>
Component for a <strong>fixed translation</strong> of frame_b with respect
to frame_a, i.e., the relationship between connectors frame_a and frame_b
remains constant and frame_a is always <strong>parallel</strong> to frame_b.
</p>
<p>
By default, this component is visualized by a cylinder connecting
frame_a and frame_b, as shown in the figure below. Note, that the
two visualized frames are not part of the component animation and that
the animation may be switched off via parameter animation = <strong>false</strong>.
</p>
<p>
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Parts/FixedTranslation.png\" alt=\"Parts.FixedTranslation\">
</p>
</html>"));
end FixedTranslation;
model FixedRotation
"Fixed translation followed by a fixed rotation of frame_b with respect to frame_a"
import Modelica.Mechanics.MultiBody.Frames;
import Modelica.SIunits.Conversions.to_unit1;
Interfaces.Frame_a frame_a
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
Interfaces.Frame_b frame_b
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{84,-16},{116,16}})));
parameter Boolean animation=true "= true, if animation shall be enabled";
parameter SI.Position r[3]={0,0,0}
"Vector from frame_a to frame_b resolved in frame_a";
parameter Modelica.Mechanics.MultiBody.Types.RotationTypes rotationType=
Modelica.Mechanics.MultiBody.Types.RotationTypes.RotationAxis
"Type of rotation description" annotation (Evaluate=true);
parameter Modelica.Mechanics.MultiBody.Types.Axis n={1,0,0}
"Axis of rotation in frame_a (= same as in frame_b)" annotation (
Evaluate=true, Dialog(group="if rotationType = RotationAxis", enable=
rotationType == Modelica.Mechanics.MultiBody.Types.RotationTypes.RotationAxis));
parameter Cv.NonSIunits.Angle_deg angle=0
"Angle to rotate frame_a around axis n into frame_b" annotation (Dialog(
group="if rotationType = RotationAxis", enable=rotationType ==
Modelica.Mechanics.MultiBody.Types.RotationTypes.RotationAxis));
parameter Modelica.Mechanics.MultiBody.Types.Axis n_x={1,0,0}
"Vector along x-axis of frame_b resolved in frame_a" annotation (
Evaluate=true, Dialog(group="if rotationType = TwoAxesVectors", enable=
rotationType == Modelica.Mechanics.MultiBody.Types.RotationTypes.TwoAxesVectors));
parameter Modelica.Mechanics.MultiBody.Types.Axis n_y={0,1,0}
"Vector along y-axis of frame_b resolved in frame_a" annotation (
Evaluate=true, Dialog(group="if rotationType = TwoAxesVectors", enable=
rotationType == Modelica.Mechanics.MultiBody.Types.RotationTypes.TwoAxesVectors));
parameter Modelica.Mechanics.MultiBody.Types.RotationSequence sequence(
min={1,1,1},
max={3,3,3}) = {1,2,3} "Sequence of rotations" annotation (Evaluate=true,
Dialog(group="if rotationType = PlanarRotationSequence", enable=
rotationType == Modelica.Mechanics.MultiBody.Types.RotationTypes.PlanarRotationSequence));
parameter Cv.NonSIunits.Angle_deg angles[3]={0,0,0}
"Rotation angles around the axes defined in 'sequence'" annotation (
Dialog(group="if rotationType = PlanarRotationSequence", enable=
rotationType == Modelica.Mechanics.MultiBody.Types.RotationTypes.PlanarRotationSequence));
parameter Modelica.Mechanics.MultiBody.Types.ShapeType shapeType="cylinder"
"Type of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Position r_shape[3]={0,0,0}
"Vector from frame_a to shape origin, resolved in frame_a" annotation (
Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Modelica.Mechanics.MultiBody.Types.Axis lengthDirection=
to_unit1(r - r_shape)
"Vector in length direction of shape, resolved in frame_a"
annotation (Evaluate=true, Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Modelica.Mechanics.MultiBody.Types.Axis widthDirection={0,1,0}
"Vector in width direction of shape, resolved in frame_a" annotation (
Evaluate=true, Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Length length=Modelica.Math.Vectors.length(r - r_shape)
"Length of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance width=length/world.defaultWidthFraction
"Width of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance height=width "Height of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Modelica.Mechanics.MultiBody.Types.ShapeExtra extra=0.0
"Additional parameter depending on shapeType (see docu of Visualizers.Advanced.Shape)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
/*
parameter Boolean checkTotalPower=false
"= true, if total power flowing into this component shall be determined (must be zero)"
annotation (Dialog(tab="Advanced"));
*/
input Modelica.Mechanics.MultiBody.Types.Color color=Modelica.Mechanics.MultiBody.Types.Defaults.RodColor
"Color of shape" annotation (Dialog(
colorSelector=true,
tab="Animation",
group="if animation = true",
enable=animation));
input Modelica.Mechanics.MultiBody.Types.SpecularCoefficient
specularCoefficient=world.defaultSpecularCoefficient
"Reflection of ambient light (= 0: light is completely absorbed)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
final parameter Frames.Orientation R_rel=if rotationType == Types.RotationTypes.RotationAxis
then Frames.planarRotation(
Modelica.Math.Vectors.normalizeWithAssert(n),
Cv.from_deg(angle),
0) else if rotationType == Types.RotationTypes.TwoAxesVectors then
Frames.from_nxy(n_x, n_y) else Frames.axesRotations(
sequence,
Cv.from_deg(angles),
zeros(3)) "Fixed rotation object from frame_a to frame_b";
/*
SI.Power totalPower
"Total power flowing into this element, if checkTotalPower=true (otherwise dummy)";
*/
protected
outer Modelica.Mechanics.MultiBody.World world;
/*
parameter Frames.Orientation R_rel_inv=
Frames.inverseRotation(R_rel)
*/
parameter Frames.Orientation R_rel_inv=Frames.from_T(transpose(R_rel.T),
zeros(3)) "Inverse of R_rel (rotate from frame_b to frame_a)";
Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape shape(
shapeType=shapeType,
color=color,
specularCoefficient=specularCoefficient,
r_shape=r_shape,
lengthDirection=lengthDirection,
widthDirection=widthDirection,
length=length,
width=width,
height=height,
extra=extra,
r=frame_a.r_0,
R=frame_a.R) if world.enableAnimation and animation;
equation
Connections.branch(frame_a.R, frame_b.R);
assert(cardinality(frame_a) > 0 or cardinality(frame_b) > 0,
"Neither connector frame_a nor frame_b of FixedRotation object is connected");
/* Relationships between quantities of frame_a and frame_b */
frame_b.r_0 = frame_a.r_0 + Frames.resolve1(frame_a.R, r);
if Connections.rooted(frame_a.R) then
frame_b.R = Frames.absoluteRotation(frame_a.R, R_rel);
zeros(3) = frame_a.f + Frames.resolve1(R_rel, frame_b.f);
zeros(3) = frame_a.t + Frames.resolve1(R_rel, frame_b.t) - cross(r,
frame_a.f);
else
frame_a.R = Frames.absoluteRotation(frame_b.R, R_rel_inv);
zeros(3) = frame_b.f + Frames.resolve1(R_rel_inv, frame_a.f);
zeros(3) = frame_b.t + Frames.resolve1(R_rel_inv, frame_a.t) + cross(
Frames.resolve1(R_rel_inv, r), frame_b.f);
end if;
/*
if checkTotalPower then
totalPower = frame_a.f*Frames.resolve2(frame_a.R, der(frame_a.r_0)) +
frame_b.f*Frames.resolve2(frame_b.R, der(frame_b.r_0)) +
frame_a.t*Frames.angularVelocity2(frame_a.R) +
frame_b.t*Frames.angularVelocity2(frame_b.R);
else
totalPower = 0;
end if;
*/
annotation (
Documentation(info="<html>
<p>
Component for a <strong>fixed translation</strong> and <strong>fixed rotation</strong> of frame_b with respect
to frame_a, i.e., the relationship between connectors frame_a and frame_b
remains constant. There are several possibilities to define the
orientation of frame_b with respect to frame_a:
</p>
<ul>
<li><strong>Planar rotation</strong> along axis 'n' (that is fixed and resolved
in frame_a) with a fixed angle 'angle'.</li>
<li><strong>Vectors n_x</strong> and <strong>n_y</strong> that are directed along the corresponding axes
direction of frame_b and are resolved in frame_a (if n_y is not
orthogonal to n_x, the y-axis of frame_b is selected such that it is
orthogonal to n_x and in the plane of n_x and n_y).</li>
<li><strong>Sequence</strong> of <strong>three planar axes rotations</strong>.
For example, \"sequence = {1,2,3}\" and \"angles = {90, 45, -90}\"
means to rotate frame_a around the x axis with 90 degrees, around the new
y axis with 45 degrees and around the new z axis around -90 degrees to
arrive at frame_b. Note, that sequence={1,2,3}
is the Cardan angle sequence and sequence = {3,1,3} is the Euler angle
sequence.</li>
</ul>
<p>
By default, this component is visualized by a cylinder connecting
frame_a and frame_b, as shown in the figure below. In this figure
frame_b is rotated along the z-axis of frame_a with 60 degree. Note, that the
two visualized frames are not part of the component animation and that
the animation may be switched off via parameter animation = <strong>false</strong>.
</p>
<p>
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Parts/FixedRotation.png\" alt=\"Parts.FixedRotation\">
</p>
</html>", revisions="<html><p><strong>Release Notes:</strong></p>
<ul>
<li><em>July 28, 2003</em><br>
Bug fixed: if rotationType = PlanarRotationSequence, then 'angles'
was used with unit [rad] instead of [deg].</li>
</ul>
</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Text(
extent={{-150,80},{150,120}},
textString="%name",
textColor={0,0,255}),
Rectangle(
extent={{-100,5},{100,-4}},
fillPattern=FillPattern.Solid),
Line(points={{80,20},{129,50}}),
Line(points={{80,20},{57,59}}),
Polygon(
points={{144,60},{117,59},{132,37},{144,60}},
fillPattern=FillPattern.Solid),
Polygon(
points={{43,80},{46,50},{68,65},{43,80}},
fillPattern=FillPattern.Solid),
Text(
extent={{-150,-50},{150,-80}},
textString="r=%r"),
Text(
extent={{-117,51},{-81,26}},
textColor={128,128,128},
textString="a"),
Text(
extent={{84,-24},{120,-49}},
textColor={128,128,128},
textString="b")}));
end FixedRotation;
model Body
"Rigid body with mass, inertia tensor and one frame connector (12 potential states)"
import Modelica.Mechanics.MultiBody.Types;
import Modelica.Mechanics.MultiBody.Frames;
import Modelica.SIunits.Conversions.to_unit1;
Modelica.Mechanics.MultiBody.Interfaces.Frame_a frame_a
"Coordinate system fixed at body" annotation (Placement(transformation(
extent={{-116,-16},{-84,16}})));
parameter Boolean animation=true
"= true, if animation shall be enabled (show cylinder and sphere)";
parameter SI.Position r_CM[3](start={0,0,0})
"Vector from frame_a to center of mass, resolved in frame_a";
parameter SI.Mass m(min=0, start=1) "Mass of rigid body";
parameter SI.Inertia I_11(min=0) = 0.001 "Element (1,1) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_22(min=0) = 0.001 "Element (2,2) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_33(min=0) = 0.001 "Element (3,3) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_21(min=-C.inf) = 0 "Element (2,1) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_31(min=-C.inf) = 0 "Element (3,1) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_32(min=-C.inf) = 0 "Element (3,2) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
SI.Position r_0[3](start={0,0,0}, each stateSelect=if enforceStates then
StateSelect.always else StateSelect.avoid)
"Position vector from origin of world frame to origin of frame_a"
annotation (Dialog(tab="Initialization",showStartAttribute=true));
SI.Velocity v_0[3](start={0,0,0}, each stateSelect=if enforceStates then
StateSelect.always else StateSelect.avoid)
"Absolute velocity of frame_a, resolved in world frame (= der(r_0))"
annotation (Dialog(tab="Initialization",showStartAttribute=true));
SI.Acceleration a_0[3](start={0,0,0})
"Absolute acceleration of frame_a resolved in world frame (= der(v_0))"
annotation (Dialog(tab="Initialization",showStartAttribute=true));
parameter Boolean angles_fixed=false
"= true, if angles_start are used as initial values, else as guess values"
annotation (
Evaluate=true,
choices(checkBox=true),
Dialog(tab="Initialization"));
parameter SI.Angle angles_start[3]={0,0,0}
"Initial values of angles to rotate world frame around 'sequence_start' axes into frame_a"
annotation (Dialog(tab="Initialization"));
parameter Types.RotationSequence sequence_start={1,2,3}
"Sequence of rotations to rotate world frame into frame_a at initial time"
annotation (Evaluate=true, Dialog(tab="Initialization"));
parameter Boolean w_0_fixed=false
"= true, if w_0_start are used as initial values, else as guess values"
annotation (
Evaluate=true,
choices(checkBox=true),
Dialog(tab="Initialization"));
parameter SI.AngularVelocity w_0_start[3]={0,0,0}
"Initial or guess values of angular velocity of frame_a resolved in world frame"
annotation (Dialog(tab="Initialization"));
parameter Boolean z_0_fixed=false
"= true, if z_0_start are used as initial values, else as guess values"
annotation (
Evaluate=true,
choices(checkBox=true),
Dialog(tab="Initialization"));
parameter SI.AngularAcceleration z_0_start[3]={0,0,0}
"Initial values of angular acceleration z_0 = der(w_0)"
annotation (Dialog(tab="Initialization"));
parameter SI.Diameter sphereDiameter=world.defaultBodyDiameter
"Diameter of sphere" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
input Types.Color sphereColor=Modelica.Mechanics.MultiBody.Types.Defaults.BodyColor
"Color of sphere" annotation (Dialog(
colorSelector=true,
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Diameter cylinderDiameter=sphereDiameter/Types.Defaults.BodyCylinderDiameterFraction
"Diameter of cylinder" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
input Types.Color cylinderColor=sphereColor "Color of cylinder" annotation (
Dialog(
colorSelector=true,
tab="Animation",
group="if animation = true",
enable=animation));
input Types.SpecularCoefficient specularCoefficient=world.defaultSpecularCoefficient
"Reflection of ambient light (= 0: light is completely absorbed)"
annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Boolean enforceStates=false
"= true, if absolute variables of body object shall be used as states (StateSelect.always)"
annotation (Evaluate=true,Dialog(tab="Advanced"));
parameter Boolean useQuaternions=true
"= true, if quaternions shall be used as potential states otherwise use 3 angles as potential states"
annotation (Evaluate=true,Dialog(tab="Advanced"));
parameter Types.RotationSequence sequence_angleStates={1,2,3}
"Sequence of rotations to rotate world frame into frame_a around the 3 angles used as potential states"
annotation (Evaluate=true, Dialog(tab="Advanced", enable=not
useQuaternions));
final parameter SI.Inertia I[3, 3]=[I_11, I_21, I_31; I_21, I_22, I_32;
I_31, I_32, I_33] "inertia tensor";
final parameter Frames.Orientation R_start=
Modelica.Mechanics.MultiBody.Frames.axesRotations(
sequence_start,
angles_start,
zeros(3))
"Orientation object from world frame to frame_a at initial time";
SI.AngularVelocity w_a[3](
start=Frames.resolve2(R_start, w_0_start),
fixed=fill(w_0_fixed, 3),
each stateSelect=if enforceStates then (if useQuaternions then
StateSelect.always else StateSelect.never) else StateSelect.avoid)
"Absolute angular velocity of frame_a resolved in frame_a";
SI.AngularAcceleration z_a[3](start=Frames.resolve2(R_start, z_0_start),
fixed=fill(z_0_fixed, 3))
"Absolute angular acceleration of frame_a resolved in frame_a";
SI.Acceleration g_0[3] "Gravity acceleration resolved in world frame";
protected
outer Modelica.Mechanics.MultiBody.World world;
// Declarations for quaternions (dummies, if quaternions are not used)
parameter Frames.Quaternions.Orientation Q_start=Frames.to_Q(R_start)
"Quaternion orientation object from world frame to frame_a at initial time";
Frames.Quaternions.Orientation Q(start=Q_start, each stateSelect=if
enforceStates then (if useQuaternions then StateSelect.prefer else
StateSelect.never) else StateSelect.avoid)
"Quaternion orientation object from world frame to frame_a (dummy value, if quaternions are not used as states)";
// Declaration for 3 angles
parameter SI.Angle phi_start[3]=if sequence_start[1] ==
sequence_angleStates[1] and sequence_start[2] == sequence_angleStates[2]
and sequence_start[3] == sequence_angleStates[3] then angles_start
else Frames.axesRotationsAngles(R_start, sequence_angleStates)
"Potential angle states at initial time";
SI.Angle phi[3](start=phi_start, each stateSelect=if enforceStates then (
if useQuaternions then StateSelect.never else StateSelect.always)
else StateSelect.avoid)
"Dummy or 3 angles to rotate world frame into frame_a of body";
SI.AngularVelocity phi_d[3](each stateSelect=if enforceStates then (if
useQuaternions then StateSelect.never else StateSelect.always) else
StateSelect.avoid) "= der(phi)";
SI.AngularAcceleration phi_dd[3] "= der(phi_d)";
// Declarations for animation
Visualizers.Advanced.Shape cylinder(
shapeType="cylinder",
color=cylinderColor,
specularCoefficient=specularCoefficient,
length=if Modelica.Math.Vectors.length(r_CM) > sphereDiameter/2 then
Modelica.Math.Vectors.length(r_CM) - (if cylinderDiameter > 1.1*
sphereDiameter then sphereDiameter/2 else 0) else 0,
width=cylinderDiameter,
height=cylinderDiameter,
lengthDirection = to_unit1(r_CM),
widthDirection={0,1,0},
r=frame_a.r_0,
R=frame_a.R) if world.enableAnimation and animation;
Visualizers.Advanced.Shape sphere(
shapeType="sphere",
color=sphereColor,
specularCoefficient=specularCoefficient,
length=sphereDiameter,
width=sphereDiameter,
height=sphereDiameter,
lengthDirection={1,0,0},
widthDirection={0,1,0},
r_shape=r_CM - {1,0,0}*sphereDiameter/2,
r=frame_a.r_0,
R=frame_a.R) if world.enableAnimation and animation and sphereDiameter >
0;
initial equation
if angles_fixed then
// Initialize positional variables
if not Connections.isRoot(frame_a.R) then
// frame_a.R is computed somewhere else
zeros(3) = Frames.Orientation.equalityConstraint(frame_a.R, R_start);
elseif useQuaternions then
// frame_a.R is computed from quaternions Q
zeros(3) = Frames.Quaternions.Orientation.equalityConstraint(Q, Q_start);
else
// frame_a.R is computed from the 3 angles 'phi'
phi = phi_start;
end if;
end if;
equation
if enforceStates then
Connections.root(frame_a.R);
else
Connections.potentialRoot(frame_a.R);
end if;
r_0 = frame_a.r_0;
if not Connections.isRoot(frame_a.R) then
// Body does not have states
// Dummies
Q = {0,0,0,1};
phi = zeros(3);
phi_d = zeros(3);
phi_dd = zeros(3);
elseif useQuaternions then
// Use Quaternions as states (with dynamic state selection)
frame_a.R = Frames.from_Q(Q, Frames.Quaternions.angularVelocity2(Q, der(Q)));
{0} = Frames.Quaternions.orientationConstraint(Q);
// Dummies
phi = zeros(3);
phi_d = zeros(3);
phi_dd = zeros(3);
else
// Use Cardan angles as states
phi_d = der(phi);
phi_dd = der(phi_d);
frame_a.R = Frames.axesRotations(
sequence_angleStates,
phi,
phi_d);
// Dummies
Q = {0,0,0,1};
end if;
// gravity acceleration at center of mass resolved in world frame
g_0 = world.gravityAcceleration(frame_a.r_0 + Frames.resolve1(frame_a.R,
r_CM));
// translational kinematic differential equations
v_0 = der(frame_a.r_0);
a_0 = der(v_0);
// rotational kinematic differential equations
w_a = Frames.angularVelocity2(frame_a.R);
z_a = der(w_a);
/* Newton/Euler equations with respect to center of mass
a_CM = a_a + cross(z_a, r_CM) + cross(w_a, cross(w_a, r_CM));
f_CM = m*(a_CM - g_a);
t_CM = I*z_a + cross(w_a, I*w_a);
frame_a.f = f_CM
frame_a.t = t_CM + cross(r_CM, f_CM);
Inserting the first three equations in the last two results in:
*/
frame_a.f = m*(Frames.resolve2(frame_a.R, a_0 - g_0) + cross(z_a, r_CM) +
cross(w_a, cross(w_a, r_CM)));
frame_a.t = I*z_a + cross(w_a, I*w_a) + cross(r_CM, frame_a.f);
annotation (Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Rectangle(
extent={{-100,30},{-3,-30}},
lineColor={0,24,48},
fillPattern=FillPattern.HorizontalCylinder,
fillColor={0,127,255},
radius=10),
Text(
extent={{150,-100},{-150,-70}},
textString="m=%m"),
Text(
extent={{-150,110},{150,70}},
textString="%name",
textColor={0,0,255}),
Ellipse(
extent={{-20,60},{100,-60}},
lineColor={0,24,48},
fillPattern=FillPattern.Sphere,
fillColor={0,127,255})}), Documentation(info="<html>
<p>
<strong>Rigid body</strong> with mass and inertia tensor.
All parameter vectors have to be resolved in frame_a.
The <strong>inertia tensor</strong> has to be defined with respect to a
coordinate system that is parallel to frame_a with the
origin at the center of mass of the body.
</p>
<p>
By default, this component is visualized by a <strong>cylinder</strong> located
between frame_a and the center of mass and by a <strong>sphere</strong> that has
its center at the center of mass. If the cylinder length is smaller as
the radius of the sphere, e.g., since frame_a is located at the
center of mass, the cylinder is not displayed. Note, that
the animation may be switched off via parameter animation = <strong>false</strong>.
</p>
<p>
<img src=\"modelica://Modelica/Resources/Images/Mechanics/MultiBody/Parts/Body.png\" alt=\"Parts.Body\">
</p>
<p>
<strong>States of Body Components</strong>
</p>
<p>
Every body has potential states. If possible a tool will select
the states of joints and not the states of bodies because this is
usually the most efficient choice. In this case the position, orientation,
velocity and angular velocity of frame_a of the body will be computed
by the component that is connected to frame_a. However, if a body is moving
freely in space, variables of the body have to be used as states. The potential
states of the body are:
</p>
<ul>
<li> The <strong>position vector</strong> frame_a.r_0 from the origin of the
world frame to the origin of frame_a of the body, resolved in
the world frame and the <strong>absolute velocity</strong> v_0 of the origin of
frame_a, resolved in the world frame (= der(frame_a.r_0)).
</li>
<li> If parameter <strong>useQuaternions</strong> in the \"Advanced\" menu
is <strong>true</strong> (this is the default), then <strong>4 quaternions</strong>
are potential states. Additionally, the coordinates of the
absolute angular velocity vector of the
body are 3 potential states.<br>
If <strong>useQuaternions</strong> in the \"Advanced\" menu
is <strong>false</strong>, then <strong>3 angles</strong> and the derivatives of
these angles are potential states. The orientation of frame_a
is computed by rotating the world frame along the axes defined
in parameter vector \"sequence_angleStates\" (default = {1,2,3}, i.e.,
the Cardan angle sequence) around the angles used as potential states.
For example, the default is to rotate the x-axis of the world frame
around angles[1], the new y-axis around angles[2] and the new z-axis
around angles[3], arriving at frame_a.
</li>
</ul>
<p>
The quaternions have the slight disadvantage that there is a
non-linear constraint equation between the 4 quaternions.
Therefore, at least one non-linear equation has to be solved
during simulation. A tool might, however, analytically solve this
simple constraint equation. Using the 3 angles as states has the
disadvantage that there is a singular configuration in which a
division by zero will occur. If it is possible to determine in advance
for an application class that this singular configuration is outside
of the operating region, the 3 angles might be used as potential
states by setting <strong>useQuaternions</strong> = <strong>false</strong>.
</p>
<p>
In text books about 3-dimensional mechanics often 3 angles and the
angular velocity are used as states. This is not the case here, since
3 angles and their derivatives are used as potential states
(if useQuaternions = false). The reason
is that for real-time simulation the discretization formula of the
integrator might be \"inlined\" and solved together with the body equations.
By appropriate symbolic transformation the performance is
drastically increased if angles and their
derivatives are used as states, instead of angles and the angular
velocity.
</p>
<p>
Whether or not variables of the body are used as states is usually
automatically selected by the Modelica translator. If parameter
<strong>enforceStates</strong> is set to <strong>true</strong> in the \"Advanced\" menu,
then body variables are forced to be used as states according
to the setting of parameters \"useQuaternions\" and
\"sequence_angleStates\".
</p>
</html>"));
end Body;
model BodyShape
"Rigid body with mass, inertia tensor, different shapes for animation, and two frame connectors (12 potential states)"
import Modelica.Mechanics.MultiBody.Types;
import Modelica.SIunits.Conversions.to_unit1;
Interfaces.Frame_a frame_a
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
Interfaces.Frame_b frame_b
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{84,-16},{116,16}})));
parameter Boolean animation=true
"= true, if animation shall be enabled (show shape between frame_a and frame_b and optionally a sphere at the center of mass)";
parameter Boolean animateSphere=true
"= true, if mass shall be animated as sphere provided animation=true";
parameter SI.Position r[3](start={0,0,0})
"Vector from frame_a to frame_b resolved in frame_a";
parameter SI.Position r_CM[3](start={0,0,0})
"Vector from frame_a to center of mass, resolved in frame_a";
parameter SI.Mass m(min=0, start=1) "Mass of rigid body";
parameter SI.Inertia I_11(min=0) = 0.001 "Element (1,1) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_22(min=0) = 0.001 "Element (2,2) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_33(min=0) = 0.001 "Element (3,3) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_21(min=-C.inf) = 0 "Element (2,1) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_31(min=-C.inf) = 0 "Element (3,1) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
parameter SI.Inertia I_32(min=-C.inf) = 0 "Element (3,2) of inertia tensor"
annotation (Dialog(group="Inertia tensor (resolved in center of mass, parallel to frame_a)"));
SI.Position r_0[3](start={0,0,0}, each stateSelect=if enforceStates then
StateSelect.always else StateSelect.avoid)
"Position vector from origin of world frame to origin of frame_a"
annotation (Dialog(tab="Initialization",showStartAttribute=true));
SI.Velocity v_0[3](start={0,0,0}, each stateSelect=if enforceStates then
StateSelect.always else StateSelect.avoid)
"Absolute velocity of frame_a, resolved in world frame (= der(r_0))"
annotation (Dialog(tab="Initialization",showStartAttribute=true));
SI.Acceleration a_0[3](start={0,0,0})
"Absolute acceleration of frame_a resolved in world frame (= der(v_0))"
annotation (Dialog(tab="Initialization",showStartAttribute=true));
parameter Boolean angles_fixed=false
"= true, if angles_start are used as initial values, else as guess values"
annotation (
Evaluate=true,
choices(checkBox=true),
Dialog(tab="Initialization"));
parameter SI.Angle angles_start[3]={0,0,0}
"Initial values of angles to rotate world frame around 'sequence_start' axes into frame_a"
annotation (Dialog(tab="Initialization"));
parameter Types.RotationSequence sequence_start={1,2,3}
"Sequence of rotations to rotate world frame into frame_a at initial time"
annotation (Evaluate=true, Dialog(tab="Initialization"));
parameter Boolean w_0_fixed=false
"= true, if w_0_start are used as initial values, else as guess values"
annotation (
Evaluate=true,
choices(checkBox=true),
Dialog(tab="Initialization"));
parameter SI.AngularVelocity w_0_start[3]={0,0,0}
"Initial or guess values of angular velocity of frame_a resolved in world frame"
annotation (Dialog(tab="Initialization"));
parameter Boolean z_0_fixed=false
"= true, if z_0_start are used as initial values, else as guess values"
annotation (
Evaluate=true,
choices(checkBox=true),
Dialog(tab="Initialization"));
parameter SI.AngularAcceleration z_0_start[3]={0,0,0}
"Initial values of angular acceleration z_0 = der(w_0)"
annotation (Dialog(tab="Initialization"));
parameter Types.ShapeType shapeType="cylinder" "Type of shape" annotation (
Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Position r_shape[3]={0,0,0}
"Vector from frame_a to shape origin, resolved in frame_a" annotation (
Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.Axis lengthDirection = to_unit1(r - r_shape)
"Vector in length direction of shape, resolved in frame_a" annotation (
Evaluate=true, Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter Types.Axis widthDirection={0,1,0}
"Vector in width direction of shape, resolved in frame_a" annotation (
Evaluate=true, Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Length length=Modelica.Math.Vectors.length(r - r_shape)
"Length of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance width=length/world.defaultWidthFraction
"Width of shape" annotation (Dialog(
tab="Animation",
group="if animation = true",
enable=animation));
parameter SI.Distance height=width "Height of shape" annotation (Dialog(