@@ -374,65 +374,43 @@ This component has a single frame, `frame_a`. To represent bodies with more than
374374 # @warn "Make the body have state variables by using isroot=true rather than state=true"
375375 isroot = true
376376 end
377- @variables r_0 (t)[1 : 3 ]= r_0 [
378- state_priority = state_priority+ isroot,
379- description = " Position vector from origin of world frame to origin of frame_a" ,
380- ]
381- @variables v_0 (t)[1 : 3 ]= v_0 [
382- state_priority = state_priority+ isroot,
383- description = " Absolute velocity of frame_a, resolved in world frame (= D(r_0))" ,
384- ]
385- @variables a_0 (t)[1 : 3 ] [
386- description = " Absolute acceleration of frame_a resolved in world frame (= D(v_0))" ,
387- ]
388- @variables g_0 (t)[1 : 3 ] [ description = " gravity acceleration" ]
389- @variables w_a (t)[1 : 3 ]= w_a [
390- state_priority = isroot ? quat ? state_priority : - 1 : 0 ,
391- description = " Absolute angular velocity of frame_a resolved in frame_a" ,
392- ]
393- @variables z_a (t)[1 : 3 ] [
394- description = " Absolute angular acceleration of frame_a resolved in frame_a" ,
395- ]
396- # 6*3 potential variables + Frame: 2*3 flow + 3 potential + 3 residual = 24 equations + 2*3 flow
397- @parameters m= m [description = " mass" ]
398- @parameters r_cm[1 : 3 ]= r_cm [
399- description = " Vector from frame_a to center of mass, resolved in frame_a" ,
400- ]
401- @parameters radius= radius [
402- description = " Radius of the body in animations" ,
403- ]
404- @parameters cylinder_radius= cylinder_radius [
405- description = " Radius of the cylinder from frame to COM in animations" ,
406- ]
407- @parameters color[1 : 4 ] = color [description = " Color of the body in animations (RGBA)" ]
408- @parameters length_fraction= length_fraction, [description = " Fraction of the length of the body that is the cylinder from frame to COM in animations" ]
409- @parameters render = render [description = " Render the component in animations" ]
410- # @parameters I[1:3, 1:3]=I [description="inertia tensor"]
411377
412378 if sparse_I
413379 Isparsity = sparse (.! isequal .(0 , [I_11 I_21 I_31; I_21 I_22 I_32; I_31 I_32 I_33]))
414380 end
415381
416- @parameters I_11= I_11 [description = " Element (1,1) of inertia tensor" ]
417- @parameters I_22= I_22 [description = " Element (2,2) of inertia tensor" ]
418- @parameters I_33= I_33 [description = " Element (3,3) of inertia tensor" ]
419- @parameters I_21= I_21 [description = " Element (2,1) of inertia tensor" ]
420- @parameters I_31= I_31 [description = " Element (3,1) of inertia tensor" ]
421- @parameters I_32= I_32 [description = " Element (3,2) of inertia tensor" ]
382+ vars = @variables begin
383+ r_0 (t)[1 : 3 ]= r_0, [state_priority = state_priority+ isroot, description = " Position vector from origin of world frame to origin of frame_a" ]
384+ v_0 (t)[1 : 3 ]= v_0, [state_priority = state_priority+ isroot, description = " Absolute velocity of frame_a, resolved in world frame (= D(r_0))" ]
385+ a_0 (t)[1 : 3 ], [description = " Absolute acceleration of frame_a resolved in world frame (= D(v_0))" ]
386+ g_0 (t)[1 : 3 ], [description = " gravity acceleration" ]
387+ w_a (t)[1 : 3 ]= w_a, [state_priority = isroot ? quat ? state_priority : - 1 : 0 , description = " Absolute angular velocity of frame_a resolved in frame_a" ]
388+ z_a (t)[1 : 3 ], [description = " Absolute angular acceleration of frame_a resolved in frame_a" ]
389+ end
390+
391+ pars = @parameters begin
392+ m= m, [description = " mass" ]
393+ r_cm[1 : 3 ]= r_cm, [description = " Vector from frame_a to center of mass, resolved in frame_a" ]
394+ I_11= I_11, [description = " Element (1,1) of inertia tensor" ]
395+ I_22= I_22, [description = " Element (2,2) of inertia tensor" ]
396+ I_33= I_33, [description = " Element (3,3) of inertia tensor" ]
397+ I_21= I_21, [description = " Element (2,1) of inertia tensor" ]
398+ I_31= I_31, [description = " Element (3,1) of inertia tensor" ]
399+ I_32= I_32, [description = " Element (3,2) of inertia tensor" ]
400+ radius= radius, [description = " Radius of the body in animations" ]
401+ cylinder_radius= cylinder_radius, [description = " Radius of the cylinder from frame to COM in animations" ]
402+ color[1 : 4 ] = color, [description = " Color of the body in animations (RGBA)" ]
403+ length_fraction= length_fraction, [description = " Fraction of the length of the body that is the cylinder from frame to COM in animations" ]
404+ render = render, [description = " Render the component in animations" ]
405+ end
422406
423407 I = [I_11 I_21 I_31; I_21 I_22 I_32; I_31 I_32 I_33]
424408 if sparse_I
425409 I = I.* Isparsity
426410 end
427411
428- # r_0, v_0, a_0, g_0, w_a, z_a, r_cm = collect.((r_0, v_0, a_0, g_0, w_a, z_a, r_cm))
429-
430- # DRa = D(Ra)
431-
432- dvs = [r_0;v_0;a_0;g_0;w_a;z_a;]
433-
434412 eqs = if isroot # isRoot
435-
413+
436414 if quat
437415 @named frame_a = Frame (varw= false )
438416 Ra = ori (frame_a, false )
@@ -443,7 +421,7 @@ This component has a single frame, `frame_a`. To represent bodies with more than
443421 @variables phi (t)[1 : 3 ]= phi0 [state_priority = 10 , description = " Euler angles" ]
444422 @variables phid (t)[1 : 3 ]= phid0 [state_priority = 10 ]
445423 @variables phidd (t)[1 : 3 ] [state_priority = 0 ]
446- # phi, phid, phidd = collect.(( phi, phid, phidd) )
424+ append! (vars, [ phi; phid; phidd] )
447425 ar = axes_rotations (sequence, phi, phid)
448426 Equation[
449427 phid .~ D .(phi)
@@ -478,10 +456,7 @@ This component has a single frame, `frame_a`. To represent bodies with more than
478456 end
479457 (frame_a. tau ~ I * z_a + cross (w_a, collect (I * w_a)) + cross (r_cm, frame_a. f))]
480458
481- # pars = [m;r_cm;radius;I_11;I_22;I_33;I_21;I_31;I_32;color]
482-
483- sys = System (eqs, t; name= :nothing , metadata = Dict (IsRoot => isroot), systems = [frame_a])
484- add_params (sys, [radius; cylinder_radius; color; length_fraction; render]; name)
459+ System (eqs, t, vars, pars; name, metadata = Dict (IsRoot => isroot), systems = [frame_a])
485460end
486461
487462
0 commit comments