@@ -2,7 +2,7 @@ export Object3D, Scene, Visual, Solid
22export Box, Beam, Cylinder, Sphere, Ellipsoid
33export Cone, Capsule, GearWheel, Grid, SpringShape
44export CoordinateSystem, FileMesh
5- export Font, TextShape
5+ export Font, TextShape, ModelicaShape
66export VisualMaterial
77export MassProperties, MassPropertiesFromShape
88export MassPropertiesFromShapeAndMass
@@ -14,7 +14,7 @@ export multibodyResiduals!, setModiaJointVariables!
1414export Fix
1515export Revolute, RevoluteWithFlange
1616export Prismatic, PrismaticWithFlange
17- export J123, J132, FreeMotion
17+ export J123, J132, J123or132, singularRem, FreeMotion, change_rotSequenceInNextIteration!
1818
1919export buildModia3D
2020
@@ -49,6 +49,7 @@ CoordinateSystem(; kwargs...) = Par(; _constructor = :(Modia.Modia3D.CoordinateS
4949FileMesh ( ; kwargs... ) = Par (; _constructor = :(Modia. Modia3D. FileMesh) , kwargs... )
5050Font ( ; kwargs... ) = Par (; _constructor = :(Modia. Modia3D. Font) , kwargs... )
5151TextShape ( ; kwargs... ) = Par (; _constructor = :(Modia. Modia3D. TextShape) , kwargs... )
52+ ModelicaShape ( ; kwargs... ) = Par (; _constructor = :(Modia. Modia3D. ModelicaShape) , kwargs... )
5253Fix ( ; kwargs... ) = Par (; _constructor = :(Modia. Modia3D. Fix) , kwargs... )
5354
5455MassPropertiesFromShape () = Par (; _constructor = :(Modia. Modia3D. MassPropertiesFromShape))
@@ -160,18 +161,63 @@ function J132(rot132::AbstractVector)
160161
161162end
162163
164+
165+
166+ """
167+ next_isrot123 = change_rotSequenceInNextIteration!(rot::AbstractVector, isrot123::Bool, instantiatedModel::SimulationModel, x, rot_name)
168+
169+ Change rotation sequence of `rot` from `x-axis, y-axis, z-axis` to `x-axis, z-axis, y-axis` or visa versa in the next event iteration:
170+
171+ - If `isrot123 = true`, return `next_isrot123 = false` and `x[..] = rot132fromR(Rfromrot123(rot))`
172+
173+ - If `isrot123 = false`, return `next_isrot123 = true` and `x[..] = rot123fromR(Rfromrot132(rot))`
174+ """
175+ function change_rotSequenceInNextIteration! (rot:: AbstractVector , isrot123:: Bool , instantiatedModel:: SimulationModel , x, rot_name):: Bool
176+ if isrot123
177+ # println(" switch $rot_name 123 -> 132")
178+ next_rot = Modia3D. rot132fromR (Modia3D. Rfromrot123 (rot))
179+ next_isrot123 = false
180+ else
181+ # println(" switch $rot_name 132 -> 123")
182+ next_rot = Modia3D. rot123fromR (Modia3D. Rfromrot132 (rot))
183+ next_isrot123 = true
184+ end
185+
186+ # Change x-vector with the next_rot values
187+ eqInfo = instantiatedModel. equationInfo
188+ startIndex = eqInfo. x_info[ eqInfo. x_dict[rot_name] ]. startIndex
189+ x[startIndex] = next_rot[1 ]
190+ x[startIndex+ 1 ] = next_rot[2 ]
191+ x[startIndex+ 2 ] = next_rot[3 ]
192+ return next_isrot123
193+ end
194+
195+
196+ singularRem (ang) = abs (rem2pi (ang, RoundNearest)) - 1.5 # is negative/positive in valid/singular angle range
197+ J123or132 (rot, isrot123) = isrot123 ? J123 (rot) : J132 (rot)
198+
199+
163200FreeMotion (; obj1, obj2, r= Var (init= zeros (3 )), rot= Var (init= zeros (3 )), v= Var (init= zeros (3 )), w= Var (init= zeros (3 ))) = Model (; _constructor = Par (value = :(Modia. Modia3D. FreeMotion), _path = true , ndof = 6 ),
164201 obj1 = Par (value = obj1),
165202 obj2 = Par (value = obj2),
166203 r = r,
167204 rot = rot,
168205 v = v,
169206 w = w,
207+
208+ next_isrot123 = Var (start= true ),
209+ _rotName = " ???" , # is changed by buildModia3D to the full path name of "rot"
210+
170211 equations = :[
171- der (r) = v
172- der (rot) = J123 (rot) * w
212+ der (r) = v
213+
214+ isrot123 = pre (next_isrot123)
215+ rot2_singularity = positive (singularRem (rot[2 ]))
216+ next_isrot123 = if rot2_singularity; change_rotSequenceInNextIteration! (rot, isrot123, instantiatedModel, _x, _rotName) else isrot123 end
217+ der (rot) = J123or132 (rot,isrot123) * w
218+
173219 der (v) = qdd[1 : 3 ]
174220 der (w) = qdd[4 : 6 ]
175- variables = getVariables (r, rot, v, w)
221+ variables = getVariables (r, rot, v, w, isrot123 )
176222 ]
177223)
0 commit comments