@@ -24,7 +24,7 @@ If `axisflange`, flange connectors for ModelicaStandardLibrary.Mechanics.Rotatio
2424""" 
2525@component  function  Revolute (; name, phi0 =  0 , w0 =  0 , n =  Float64[0 , 0 , 1 ], axisflange =  false ,
2626                  isroot =  true , iscut =  false , radius =  0.05 , length =  radius, color =  [0.5019608f0 ,0.0f0 ,0.5019608f0 ,1.0f0 ], state_priority =  3.0 )
27-     if  ! (eltype (n) <:  Num )
27+     if  ! (eltype (n) <:  Num )  &&   ! isa (n, Symbolics . Arr{Num,  1 }) 
2828        norm (n) ≈  1  ||  error (" Axis of rotation must be a unit vector" 
2929    end 
3030    @named  frame_a =  Frame ()
@@ -37,7 +37,7 @@ If `axisflange`, flange connectors for ModelicaStandardLibrary.Mechanics.Rotatio
3737    end 
3838    @variables  tau (t)= 0  [
3939        connect =  Flow,
40-         state_priority =  2 ,
40+         #   state_priority = 2,
4141        description =  " Driving torque in direction of axis of rotation" 
4242    ]
4343    @variables  phi (t)= phi0 [
@@ -102,8 +102,8 @@ If `axisflange`, flange connectors for ModelicaStandardLibrary.Mechanics.Transla
102102The function returns an ODESystem representing the prismatic joint. 
103103""" 
104104@component  function  Prismatic (; name, n =  Float64[0 , 0 , 1 ], axisflange =  false ,
105-                    s0 =  0 , v0 =  0 , radius =  0.05 , color =  [0 ,0.8 ,1 ,1 ], state_priority= 10 , iscut= false )
106-     if  ! (eltype (n) <:  Num )
105+                    s0 =  0 , v0 =  0 , radius =  0.05 , color =  [0 ,0.8 ,1 ,1 ], state_priority= 10 , iscut= false , render = true )
106+     if  ! (eltype (n) <:  Num )  &&   ! isa (n, Symbolics . Arr{Num,  1 }) 
107107        norm (n) ≈  1  ||  error (" Prismatic axis of motion must be a unit vector, got norm(n) = $(norm (n)) " 
108108    end 
109109    @named  frame_a =  Frame ()
@@ -114,6 +114,7 @@ The function returns an ODESystem representing the prismatic joint.
114114    pars =  @parameters  begin 
115115        radius =  radius, [description =  " radius of the joint in animations" 
116116        color[1 : 4 ] =  color, [description =  " color of the joint in animations (RGBA)" 
117+         render =  render, [description =  " render the joint in animations" 
117118    end 
118119
119120    @variables  s (t)= s0 [
@@ -125,7 +126,6 @@ The function returns an ODESystem representing the prismatic joint.
125126        description =  " Relative velocity between frame_a and frame_b" 
126127    ]
127128    @variables  a (t)= 0  [
128-         state_priority =  state_priority,
129129        description =  " Relative acceleration between frame_a and frame_b" 
130130    ]
131131    @variables  f (t)= 0  [
@@ -987,3 +987,54 @@ s_y=prismatic_y.s=0` and `phi=revolute.phi=0`.
987987        connect (revolute. frame_b, frame_b)
988988    end 
989989end 
990+ 
991+ @mtkmodel  Cylindrical begin 
992+     begin 
993+         n_def =  [1 , 0 , 0 ] #  Workaround for mtkmodel bug
994+         cylinder_color_def =  [1 , 0 , 1 , 1 ]
995+     end 
996+ 
997+     @structural_parameters  begin 
998+         #  _state_priority = 2 # mtkmodel bug prevents this from being any form of parameter at all :/
999+         cylinder_color =  [1 , 0 , 1 , 1 ]# , [description = "Color of cylinder"]
1000+     end 
1001+ 
1002+     @parameters  begin 
1003+         n[1 : 3 ] =  n_def, [description =  " Cylinder axis resolved in frame_a (= same as in frame_b)" 
1004+         cylinder_diameter =  0.05 , [description =  " Diameter of cylinder" 
1005+         render =  true , [description =  " Enable rendering of the joint in animations" 
1006+     end 
1007+     begin 
1008+         n =  collect (n)
1009+         cylinder_color =  collect (cylinder_color)
1010+     end 
1011+ 
1012+     @components  begin 
1013+         frame_a =  Frame ()
1014+         frame_b =  Frame ()
1015+         prismatic =  Prismatic (; n, state_priority= 1 , render =  false )
1016+         revolute =  Revolute (; n, state_priority= 1 , color =  cylinder_color, radius =  cylinder_diameter/ 2 )
1017+     end 
1018+ 
1019+     @variables  begin 
1020+         (s (t) =  0 ), [state_priority =  200 , description =  " Relative distance between frame_a and frame_b" 
1021+         (phi (t) =  0 ), [state_priority =  200 , description =  " Relative rotation angle from frame_a to frame_b" 
1022+         (v (t) =  0 ), [state_priority =  200 , description =  " First derivative of s (relative velocity)" 
1023+         (w (t) =  0 ), [state_priority =  200 , description =  " First derivative of angle phi (relative angular velocity)" 
1024+         (a (t) =  0 ), [description =  " Second derivative of s (relative acceleration)" 
1025+         (wd (t) =  0 ), [description =  " Second derivative of angle phi (relative angular acceleration)" 
1026+     end 
1027+ 
1028+     @equations  begin 
1029+         phi ~  revolute. phi
1030+         w ~  D (phi)
1031+         wd ~  D (w)
1032+         s ~  prismatic. s
1033+         v ~  D (s)
1034+         a ~  D (v)
1035+         connect (frame_a, prismatic. frame_a)
1036+         connect (prismatic. frame_b, revolute. frame_a)
1037+         connect (revolute. frame_b, frame_b)
1038+     end 
1039+ 
1040+ end 
0 commit comments