(*Version 12/20/13 by Nasser M. Abbasi *)

Manipulate[
 
 tick;
 
 If[Ls > L - beamWidth/2, Ls = L - beamWidth/2.];
 If[L < beamWidth, {L = beamWidth, Ls = beamWidth/2.}];
 
 Module[{r1, r2, h3, h2, r3, g = 9.8, rideG, graphics, a, cs, si, ww, 
   zeta, momentWeld, massLoad = massLoadI*0.46 (*convert to kg*), 
   debug = False, tmp, Mxx, Myy, Mzz},
  
  If[state == "running" || state == "step" || state == "shutdown",
   t = t + timeTick;
   phi = Mod[phi + wp*timeTick + 1/2 wpDot*timeTick^2, 2 Pi];
   theta = Mod[theta + ws*timeTick + 1/2 wsDot*timeTick^2, 2 Pi];
   
   If[state == "running" || state == "shutdown",
    If[state == "running",
     tick += del]
    ],
   If[state == "reset",
    t = -timeTick; phi = 0; theta = 0; tick = 0; 
    timeHistoryIndex = 0; wp = 0; ws = 0; isAcc = True; z1dot = 0; 
    z2dot = 0; z3dot = 0; z1 = 0; z2 = 0; z3 = 0; Fcgx = 0; Fcgy = 0; 
    Fcgz = 0; Fmx = 0; Fmy = 0; Fmz = 0;
    maxMoment = {0, 0, 0}; maxShear = {0, 0, 0}; 
    maxDirectStress = {0, 0, 0}; maxShearStress = {0, 0, 0};
    accHistory = ConstantArray[0, 5000];
    timeValues = ConstantArray[0, 5000];
    timeHistoryRidObject = ConstantArray[0, 5000];
    timeHistorywp = ConstantArray[0, 5000];
    timeHistoryws = ConstantArray[0, 5000];
    maxGReached = 0; maxVelocity = 0; timeReachedMaxG = 0
    ]
   ];
  
  r1 = 0.1*h1;  (*h1 is height of column, from zero level=
  4m fixed in design, below*)
  (* column width=depth and fixed at 1.2 meter or 3 r1*)
  columnMass = h1*3 r1*3 r1*density;
  I1column = 1/12*columnMass (h1^2 + (3 r1)^2);
  I2column = I1column;
  I3column = 1/12*columnMass (2 (3 r1)^2);
  Mcolumnx = 0; Mcolumny = 0; Mcolumnz = I3column* wpDot;
  
  r2 = .8*r1;
  h3 = .7*h1;
  h2 = 0.2*L;
  r3 = .2*L;
  
  beamMass = beamThickness*beamWidth*L*density;
  
  cs = Cos[theta]; si = Sin[theta];
  ww = wp ws;
  (*--------*)
  z1 = -wp si;
  z2 = ws;
  z3 = wp cs;
  
  If[Not[state == "reset"],
   z1dot = -wpDot si - ww cs;
   z2dot = wsDot;
   z3dot = wpDot cs - ww si
   ];
  
  (*beam dynamic moment*)
  I1 = 1/12*beamMass (beamThickness^2 + L^2)   ;
  I2 = 1/12*beamMass (beamThickness^2 + beamWidth^2);
  I3 = 1/12*beamMass (beamWidth^2 + L^2);
  
  Mx = I1 z1dot + z2 z3 (I3 - I2);
  My = I2 z2dot + z1 z3 (I1 - I3);
  Mz = I3 z3dot + z1 z2 (I2 - I1);
  
  (*back*)
  Mxx = Mx cs + Mz si;
  Myy = My;
  Mzz = -Mx si + Mz cs;
  
  Mx = Mxx; My = Myy; Mz = Mzz;
  
  (*cabinet dynamic moment*)
  I1c = 1/6*massLoad beamWidth^2 ;
  I2c = I1c;
  I3c = I1c;
  
  Mmx = I1c z1dot + z2 z3 (I3c - I2c);
  Mmy = I2c z2dot + z1 z3 (I1c - I3c);
  Mmz = I3c z3dot + z1 z2 (I2c - I1c);
  
  (*back*)
  Mxx = Mmx cs + Mmz si;
  Myy = Mmy;
  Mzz = -Mmx si + Mmz cs;
  
  Mmx = Mxx; Mmy = Myy; Mmz = Mzz;
  
  (*inertial force ride object*)
  If[Not[state == "reset"],
   Fmx = massLoad (beamWidth/2  wsDot cs - beamWidth/2  ws^2 si - 
       wpDot Ls - wp^2  beamWidth/2  si  );
   Fmy = massLoad (2 beamWidth/2  ww  cs + wpDot beamWidth/2  si - 
       wp^2 Ls  );
   Fmz = massLoad (-beamWidth/2  wsDot si - beamWidth/2  ws^2 cs)
   ];
  
  (*beam mass center dynamic force*)
  If[Not[state == "reset"],
   Fcgx = -beamMass L/2  wpDot;
   Fcgy = -beamMass L/2 wp^2;
   Fcgz = 0;
   ];
  
  momentWeld = 
   g {L/2 beamMass + Ls massLoad , 0, 0} + {Mx, My, Mz} + {Mmx, Mmy, 
     Mmz} + Cross[{0, L/2, 0}, {Fcgx, Fcgy, Fcgz}] + 
    Cross[{0, Ls, beamWidth/2}, {Fmx, Fmy, Fmz}];
  
  Mweldx = momentWeld[[1]];
  Mweldy = momentWeld[[2]];
  Mweldz = momentWeld[[3]];
  
  (*weld Force*)
  Fweldx = Fcgx + Fmx;
  Fweldy = Fcgy + Fmy;
  Fweldz = Fcgz + Fmz + g (beamMass  + massLoad);
  
  a = If[massLoad == 0, 0, 
    Sqrt[ (Fmx /massLoad)^2 + (Fmy /massLoad)^2 + (Fmz /massLoad)^2 ]];
  
  If[a > maxGReached,
   maxGReached = a;
   timeReachedMaxG = t
   ];
  
  timeHistoryIndex++;
  
  If[timeHistoryIndex > 5000,
   timeHistoryIndex = 1
   ];
  
  timeValues[[timeHistoryIndex]] = t;
  accHistory[[timeHistoryIndex]] = a/g;
  timeHistorywp[[timeHistoryIndex]] = wp;
  timeHistoryws[[timeHistoryIndex]] = ws;
  
  If[timeHistoryIndex == 1,
   timeHistoryRidObject[[timeHistoryIndex]] =  a* timeTick
   ,
   If[accHistory[[timeHistoryIndex - 1]] < 
     accHistory[[timeHistoryIndex]], (*acc or deceleratig?"*)
    timeHistoryRidObject[[timeHistoryIndex]] = 
     timeHistoryRidObject[[timeHistoryIndex - 1]] + a* timeTick;
    If[timeHistoryRidObject[[timeHistoryIndex]] > maxVelocity,
     maxVelocity = timeHistoryRidObject[[timeHistoryIndex]]
     ]
    ,
    If[accHistory[[timeHistoryIndex - 1]] > 
      accHistory[[timeHistoryIndex]], (*deceleratig?"*)
     (
      timeHistoryRidObject[[timeHistoryIndex]] = 
       timeHistoryRidObject[[timeHistoryIndex - 1]] - a* timeTick;
      If[timeHistoryRidObject[[timeHistoryIndex]] < 0,
       timeHistoryRidObject[[timeHistoryIndex]] = 0
       ]
      )
     ,
     timeHistoryRidObject[[timeHistoryIndex]] = 
      timeHistoryRidObject[[timeHistoryIndex - 1]]
     ]
    ]
   ];
  
  If[state == "running" || state == "step" || state == "shutdown",
   If[state == "shutdown",
    (
     isAcc = False;
     
     Module[{keep = False},
      If[(wp - Sign[wpDot]*Abs[wpDot]*timeTick)*wp > 0,
       keep = True;
       wp = wp - Sign[wpDot]*Abs[wpDot]*timeTick
       ];
      If[(ws - Sign[wsDot]*Abs[wsDot]*timeTick) *ws > 0,
       keep = True;
       ws = ws - Sign[wsDot]*Abs[wsDot]*timeTick
       ];
      
      If[keep,
       tick += del,
       state = "paused"
       ]
      ]
     )
    ,
    If[isAcc,
     If[(a/g) < gLimit,
      wp = wp + wpDot*timeTick;
      ws = ws + wsDot*timeTick
      ,
      isAcc = False
      ]
     ]
    ]
   ];
  
  
  currentDirectStressx = (Mweldx*beamThickness/2)/(beamWidth*
      beamThickness^3/12);
  If[Abs@Mweldx > Abs@maxMoment[[1]],
   maxMoment[[1]] = Mweldx;
   maxDirectStress[[1]] = currentDirectStressx;
   ];
  
  currentDirectStressy = 6*Mweldy/(beamWidth*beamThickness^2);
  If[Abs@Mweldy > Abs@maxMoment[[2]],
   maxMoment[[2]] = Mweldy;
   maxDirectStress[[2]] = currentDirectStressy
   ];
  
  currentDirectStressz = 6*Mweldz/(beamWidth*beamThickness^2);
  If[Abs@Mweldz > Abs@maxMoment[[2]],
   maxMoment[[3]] = Mweldz;
   maxDirectStress[[3]] = currentDirectStressz
   ];
  
  currentShearStressx = 3/2 Fweldx/(beamWidth*beamThickness);
  If[Abs@Fweldx > Abs@maxShear[[1]],
   maxShear[[1]] = Fweldx;
   maxShearStress[[1]] = currentShearStressx
   ];
  
  
  currentShearStressy = 3/2 Fweldy/(beamWidth*beamThickness);
  If[Abs@Fweldy > Abs@maxShear[[2]],
   maxShear[[2]] = Fweldy;
   maxShearStress[[2]] = currentShearStressy
   ];
  
  
  currentShearStressz = 3/2 Fweldz/(beamWidth*beamThickness);
  If[Abs@Fweldz > Abs@maxShear[[3]],
   maxShear[[3]] = Fweldz;
   maxShearStress[[3]] = currentShearStressz
   ];
  
  graphics = Graphics3D[
    {
     Cuboid[{-4 r1, -4 r1, -2.3 r1}, {4 r1, 4 r1, -2 r1}],
     GeometricTransformation[
      {
       
       {LightGray, 
        Cylinder[{{0, 0, -2 r1}, {0, 0, 0}}, 3 r1]},(*base*)
       (*4 lines around the base*)
       {Red, Line[{{3.01 r1, 0, -2 r1}, {3.01 r1, 0, 0}}]},
       {Red, Line[{{-3.01 r1, 0, -2 r1}, {-3.01 r1, 0, 0}}]},
       {Red, Line[{{0, 3.01 r1, -2 r1}, {0, 3.01 r1, 0}}]},
       {Red, Line[{{0, -3.01 r1, -2 r1}, {0, -3.01 r1, 0}}]},
       
       (*main column*)
       Cuboid[{-1.5 r1, -1.5 r1, 0}, {1.5 r1, 1.5 r1, h1}],
       
       (*riding ring*)
       Rotate[
        {
         
         (*body axes*)
         If[showAxes,
          {
           {Black, Arrowheads[.02], 
            Arrow[{{0, 1.9 r1 + L/2, h3 + beamThickness/2}, {0, 
               1.9 r1 + L/2 , h3 + beamThickness + 3 r1}}]},
           
           Text[Style["(3)", Italic, 10], {0, 1.9 r1 + L/2 , 
             h3 + beamThickness + 3.4 r1}],
           
           {Black, Arrowheads[.02], 
            Arrow[{{0, 1.9 r1 + L/2, 
               h3 + beamThickness/2}, {beamThickness + 3 r1, 
               1.9 r1 + L/2 , h3 + beamThickness/2}}]},
           
           Text[Style["(1)", Italic, 10], {beamThickness + 3.3 r1, 
             1.9 r1 + L/2 , h3 + beamThickness/2}]
           }
          ],
         
         (*cm*)
         {Black, 
          Sphere[{0, 1.9 r1 + L/2, h3 + beamThickness/2}, 0.3 r1]},
         
         (*horizontal beam*)
         {Opacity[op], LightBlue, 
          Cuboid[{1/2 beamWidth, 1.9 r1, h3}, {-1/2 beamWidth, 
            1.9 r1 + L, h3 + beamThickness}]},
         
         (*joint between beam and column*)
         {LightBlue, 
          Cylinder[{{0, 1.5 r1, h3 + 0.5 beamThickness}, {0, 1.9 r1, 
             h3 + 0.5 beamThickness}}, 0.5 beamThickness]},
         
         (*2 persons*)
         Cylinder[{{0.2 beamWidth , 1.6 r1 + Ls, 
            h3 + beamThickness}, {0.2 beamWidth , 1.6 r1 + Ls, 
            h3 + beamThickness + .7 beamWidth}}, .04],
         Cylinder[{{-0.2 beamWidth , 1.6 r1 + Ls, 
            h3 + beamThickness}, {-0.2 beamWidth , 1.6 r1 + Ls, 
            h3 + beamThickness + .7 beamWidth}}, .04],
         {Red, 
          Sphere[{0.2 beamWidth , 1.6 r1 + Ls, 
            h3 + beamThickness + .7 beamWidth}, 0.15]},
         {Red, 
          Sphere[{-0.2 beamWidth , 1.6 r1 + Ls, 
            h3 + beamThickness + .7 beamWidth}, 0.15]},
         
         (*cabinet*)
         {Opacity[opc], Blue, 
          Cuboid[{1/2 beamWidth, 1.9 r1 + Ls - 1/2 beamWidth, 
            h3 + 1.1 beamThickness}, {-1/2 beamWidth, 
            1.9 r1 + Ls + 1/2 beamWidth, 
            h3 + beamThickness + 1.1 beamWidth}]}
         
         },
        theta,
        {0, 1, 0},
        {0, 0 L, 
         h3 + 0.5 beamThickness} (*z value has to be middle of beam*)
\

        ],
       (*axes*)
       If[showAxes,
        {
         {Black, Arrowheads[.03], 
          Arrow[{{0, 1.5 r1, h3 + beamThickness/2}, {0, 3.8 r1 + L , 
             h3 + beamThickness/2}}]},
         Text[
          Style["y,(2)", Italic, 10], {0, 4 r1 + L , 
           h3 + beamThickness/2}],
         
         {Black, Arrowheads[.03], 
          Arrow[{{0, 0, h3 + beamThickness/2}, {3.5 r1, 0 , 
             h3 + beamThickness/2}}]},
         Text[
          Style["x", Italic, 10], {3.9 r1, 0 , h3 + beamThickness/2}],
         
         {Black, Arrowheads[.03], 
          Arrow[{{0, 0, h3 + beamThickness/2}, {0, 0 , h3 + 5.2 r1}}]},
         Text[Style["z", Italic, 10], {0, 0 , h3 + 5.5 r1}]
         }
        ]
       
       },
      RotationTransform[phi, {0, 0, 1}]
      ]
     },
    SphericalRegion -> True, Axes -> False, Boxed -> False, 
    ViewVertical -> {0, 0, 1}, ViewPoint -> {.8, 1, .7}, 
    PlotRange -> {{- 7, 7}, {-6.5, 6.9}, {-2.5 r1, 1.9 h1}}, 
    AxesLabel -> {"x", "y", "z"}, ImageSize -> {300}, 
    ImageMargins -> 1, ImagePadding -> 1
    ];
  
  
  Text@Grid[
    {
     {Style[
       "Structural Dynamics Research Corporation (SDRC) ride \
simulation", 12], SpanFromLeft},
     {Row[{"system status : ", 
        If[state == "running",
         If[isAcc,
          Row[{"accelerating ", padIt2[a/g, {4, 2}], " g" }], 
          Row[{"steady state ", padIt2[a/g, {4, 2}], " g"}],
          "ready..."
          ],
         If[state == "shutdown",
          Row[{"decelerating ", padIt2[a/g, {4, 2}], " g" }],
          "ready..."
          ]
         ]
        }], SpanFromLeft},
     {graphics, SpanFromLeft},
     {
      Grid[{
        {
         ListLinePlot[
          Transpose[{ timeValues[[1 ;; timeHistoryIndex]], 
            accHistory[[1 ;; timeHistoryIndex]] } ], Frame -> True, 
          PlotRange -> {{0, tscale}, Automatic}, 
          ImagePadding -> {{65, 25}, {34, 60}},
          
          FrameLabel -> {{"g", None}, {"time (sec)", 
             Row[{"current acceleration", Spacer[5], 
               padIt2[a/g, {4, 2}], Spacer[5], "g", Spacer[5], 
               " time ", padIt2[t, {7, 5}], Spacer[5], "sec"}]
             }}, RotateLabel -> False, GridLines -> Automatic, 
          GridLinesStyle -> LightGray, ImageMargins -> 1, 
          ImageSize -> {200}
          ]
         
         ,
         
         ListLinePlot[ 
          Transpose[ { timeValues[[1 ;; timeHistoryIndex]], 
            timeHistoryRidObject[[1 ;; timeHistoryIndex]] }], 
          Frame -> True, PlotRange -> {{0, tscale}, Automatic}, 
          ImagePadding -> {{65, 25}, {34, 60}},
          
          FrameLabel -> {{"v", None}, {"time (sec)", 
             Row[{"current velocity", Spacer[5], 
               padIt2[timeHistoryRidObject[[timeHistoryIndex]], {4, 
                 2}], Spacer[5], "m/s", Spacer[5], 
               padIt2[timeHistoryRidObject[[
                  timeHistoryIndex]]*2.23694, {4, 2}], Spacer[4], 
               "mph"}]
             }}, RotateLabel -> False, GridLines -> Automatic, 
          GridLinesStyle -> LightGray, ImageMargins -> 1, 
          ImageSize -> {200}
          ]
         }
        
        }, Frame -> All], SpanFromLeft
      },
     {
      Grid[{
        {
         ListLinePlot[
          Transpose[{ timeValues[[1 ;; timeHistoryIndex]], 
            timeHistorywp[[1 ;; timeHistoryIndex]] } ], Frame -> True,
           PlotRange -> {{0, tscale}, Automatic}, 
          ImagePadding -> {{65, 25}, {34, 60}},
          
          FrameLabel -> {{"\!\(\*SubscriptBox[\(w\), \(p\)]\)", 
             None}, {"time (sec)", 
             Row[{"current column spin speed ", 
               padIt2[timeHistorywp[[timeHistoryIndex]], {4, 2}], 
               "  (rad/sec)"}]}},
          RotateLabel -> False, GridLines -> Automatic, 
          GridLinesStyle -> LightGray, ImageMargins -> 1, 
          ImageSize -> {200}
          ]
         ,
         ListLinePlot[
          Transpose[{ timeValues[[1 ;; timeHistoryIndex]], 
            timeHistoryws[[1 ;; timeHistoryIndex]] } ], Frame -> True,
           PlotRange -> {{0, tscale}, Automatic}, 
          ImagePadding -> {{65, 25}, {34, 40}},
          
          FrameLabel -> {{"\!\(\*SubscriptBox[\(w\), \(s\)]\)", 
             None}, {"time (sec)", 
             Row[{"current beam spin speed ", 
               padIt2[timeHistoryws[[timeHistoryIndex]], {4, 2}], 
               " (rad/sec)"}]}},
          RotateLabel -> False, GridLines -> Automatic, 
          GridLinesStyle -> LightGray, ImageMargins -> 1, 
          ImageSize -> {200}
          ]
         
         }
        
        }, Frame -> All], SpanFromLeft
      }
     
     }, Spacings -> {.05, .05}, Alignment -> Center, Frame -> All
    
    ]
  ],
 
 Text@Grid[{
    {
     Grid[{
       {
        Button[Text[Style["run", 12]], state = "running"; tick += del,
          ImageSize -> {80, 35}],
        Button[Text[Style["pause", 12]], state = "paused"; 
         tick += del, ImageSize -> {80, 35}],
        Button[Text[Style["step", 12]], state = "step"; tick += del, 
         ImageSize -> {80, 35}]
        },
       {
        Button[Text[Style["reset", 12]], state = "reset"; tick += del,
          ImageSize -> {80, 35}],
        Button[Text[Style["ramp-down", 12]], state = "shutdown"; 
         tick += del, ImageSize -> {80, 35}],
        Button[Text[Style["design reset", 12]], state = "reset"; 
         beamThickness = 1;
         beamWidth = 1;
         L = 3.5;
         Ls = 3;
         material = "Aluminum 6061-O";
         density = 2700;
         massLoadI = 2*175 + 200;
         gLimit = 5.8;
         wpDot = 0.2;
         wsDot = 0.9;
         timeTick = 0.041;
         tscale = 15;
         tick += del, ImageSize -> {80, 35}]
        }
       }, Spacings -> {0.4, .2}, Alignment -> Center
      ], SpanFromLeft
     },
    {
     Grid[{
       {
        "slow",
        Manipulator[
         Dynamic[timeTick, {timeTick = #} &], {0.0001, 0.1, 0.0001}, 
         ImageSize -> Tiny, ContinuousAction -> True],
        "fast", SpanFromLeft
        },
       {
        "show Axes",
        Checkbox[Dynamic[showAxes, {showAxes = #; tick += del} &]]
        },
       {
        "ramp-up g limit",
        Manipulator[
         Dynamic[gLimit, {gLimit = #; state = "reset"; 
            tick += del} &], {3, 6, 0.1}, ImageSize -> Tiny, 
         ContinuousAction -> True],
        Dynamic[padIt2[gLimit, {2, 1}]], Spacer[2], "g"
        },
       {
        "cabinet weight",
        Manipulator[
         Dynamic[massLoadI, {massLoadI = #; state = "reset"; 
            tick += del} &], {0.0, 5000, 5}, ImageSize -> Tiny, 
         ContinuousAction -> True],
        Dynamic@
         Row[{padIt2[massLoadI, {4, 0}], Spacer[2], "lb (", 
           padIt2[massLoadI*0.45, {5, 1}], Spacer[5], "kg)"}], 
        SpanFromLeft
        },
       {
        "beam length",
        Manipulator[
         Dynamic[L, {L = #; state = "reset"; tick += del} &], {0.5, 5,
           0.01}, ImageSize -> Tiny, ContinuousAction -> True],
        Dynamic[padIt2[L, {3, 2}]], Spacer[2], "m"
        },
       {
        Grid[{
          {Style["select Material", 12],
           
           PopupMenu[
            Dynamic[
             material, {material = #; 
               Which[material == "Aluminum 6061-O", density = 2700, 
                material == "Steel", density = 1000*7.8, 
                material == "Wood", density = 1300]; state = "reset"; 
               tick += del} &],
            { 
             
             "Aluminum 6061-O" -> 
              Style["Aluminum 6061-O", 10],(*Style[
             "Aluminum 6061-O, 2700 kg/m^3, tensile 125 MPa, yield 55 \
MPa",10],*)
             "Steel" -> Style["Steal, ASTM A36 steel", 10](*Style[
             "Steal, ASTM A36 steel, 7800 kg/m^3, tensile 500 MPa, \
yield 250 MPa",10]*)
             }, ImageSize -> All
            ]
           }}, Spacings -> {0.4, 0.35}
         ], SpanFromLeft
        },
       {
        "beam thickness",
        Manipulator[
         Dynamic[beamThickness, {beamThickness = #; state = "reset"; 
            tick += del} &], {0.1, 3, 0.01}, ImageSize -> Tiny, 
         ContinuousAction -> True],
        Dynamic[padIt2[beamThickness, {3, 2}]], Spacer[2], "m"
        },
       {
        "beam width",
        Manipulator[
         Dynamic[beamWidth, {beamWidth = #; state = "reset"; 
            tick += del} &], {1, 3, 0.01}, ImageSize -> Tiny, 
         ContinuousAction -> True],
        Dynamic[padIt2[beamWidth, {3, 2}]], Spacer[2], "m"
        },
       {
        "cabinet distance",
        Manipulator[
         Dynamic[Ls, {Ls = #; state = "reset"; tick += del} &], {0.1, 
          5, 0.01}, ImageSize -> Tiny, ContinuousAction -> True],
        Dynamic[padIt2[Ls, {3, 2}]], Spacer[2], "m"
        },
       {
        "\[Omega]\!\(\*SubscriptBox[\('\), \(1\)]\)",
        Manipulator[Dynamic[wpDot, {wpDot = #; state = "reset";
            tick += del} &], {-4, 4, 0.01}, ImageSize -> Tiny, 
         ContinuousAction -> True],
        Row[{Dynamic[padIt1[wpDot, {3, 2}]], Spacer[2], 
          "rad/\!\(\*SuperscriptBox[\(sec\), \(2\)]\)", Spacer[5], 
          Button[Style["zero", 9], wpDot = 0; state = "reset"; 
           tick += del]}], SpanFromLeft
        },
       {
        "\[Omega]\!\(\*SubscriptBox[\('\), \(2\)]\)",
        Manipulator[Dynamic[wsDot, {wsDot = #; state = "reset";
            tick += del} &], {-4, 4, 0.01}, ImageSize -> Tiny, 
         ContinuousAction -> True],
        Row[{Dynamic[padIt1[wsDot, {3, 2}]], Spacer[2], 
          "rad/\!\(\*SuperscriptBox[\(sec\), \(2\)]\)", Spacer[5], 
          Button[Style["zero", 9], wsDot = 0; state = "reset"; 
           tick += del]}], SpanFromLeft
        },
       {
        "beam opacity",
        Manipulator[
         Dynamic[op, {op = #; tick += del} &], {0.1, 1, 0.1}, 
         ImageSize -> Tiny, ContinuousAction -> True],
        Dynamic[padIt2[op, {1, 1}]], SpanFromLeft
        },
       {
        "cabinet opacity",
        Manipulator[
         Dynamic[opc, {opc = #; tick += del} &], {0.1, 1, 0.1}, 
         ImageSize -> Tiny, ContinuousAction -> True],
        Dynamic[padIt2[opc, {1, 1}]], SpanFromLeft
        },
       {
        "plot time scale",
        Manipulator[
         Dynamic[tscale, {tscale = #; tick += del} &], {1, 100, 1}, 
         ImageSize -> Tiny, ContinuousAction -> True],
        Dynamic[padIt2[tscale, {4, 0}]], Spacer[2], "sec"
        }
       }, Alignment -> Left
      ], SpanFromLeft
     },
    {
     Dynamic@Grid[{
        {Text@Style["acceleration/velocity recorded", 11], 
         SpanFromLeft},
        {"max g", "reached (sec)", "max mph"},
        {padIt2[maxGReached/9.81, {3, 2}],
         padIt1[timeReachedMaxG, {6, 1}],
         padIt1[maxVelocity*2.23694, {3, 1}]}
        }, Frame -> All, FrameStyle -> Gray, Spacings -> {.2, .2}
       ],
     Grid[
      {
       {"\!\(\*SubscriptBox[\(\[Omega]\), \(1\)]\)(t)", Spacer[5], 
        Row[{Dynamic@padIt1[wp, {6, 2}], Spacer[5], "r/s"}]},
       {"\!\(\*SubscriptBox[\(\[Omega]\), \(2\)]\)(t)", Spacer[5], 
        Row[{Dynamic@padIt1[ws, {6, 2}], Spacer[5], "r/s"}]},
       {"\[Theta](t)", Spacer[5], 
        Row[{Dynamic@padIt2[theta*180/Pi, {4, 1}], Degree}]},
       {"\[Phi](t)", Spacer[5], 
        Row[{Dynamic@padIt2[phi*180/Pi, {4, 1}], Degree}]}
       }, Spacings -> {.5, .2}, Alignment -> Left]
     }
    }, Frame -> All, Alignment -> Center, Spacings -> {.2, .2}],
 
 Item[(****** MAIN TABLE *************)
  (****** MAIN TABLE *************)
  (****** MAIN TABLE *************)
  Text@Grid[{
     {"Dynamic loads "},
     {
      Dynamic[Grid[{
         {"", Item["mass (ton)", Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(M\), \(x\)]\) (Nm)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(M\), \(y\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(M\), \(z\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(F\), \(x\)]\) (N)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(F\), \(y\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(F\), \(z\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(I\), \(1\)]\) \
(kg/\!\(\*SuperscriptBox[\(m\), \(3\)]\))", Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(I\), \(2\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(I\), \(3\)]\)", 
           Alignment -> Center]},
         
         {"beam", padIt2[beamMass/907.184, {3, 3}], 
          padIt1[Mx, {6, 1}], padIt1[My, {6, 1}], padIt1[Mz, {6, 1}],
          padIt1[Fcgx, {7, 1}], padIt1[Fcgy, {7, 1}], 
          padIt1[Fcgz, {7, 1}],
          padIt2[I1, {8, 1}], padIt2[I2, {8, 1}], padIt2[I3, {8, 1}]},
         
         {"cabinet", padIt2[massLoadI*0.46/907.184, {3, 3}], 
          padIt1[Mmx, {6, 1}], padIt1[Mmy, {6, 1}], 
          Dynamic@padIt1[Mmz, {6, 1}],
          padIt1[Fmx, {7, 1}], padIt1[Fmy, {7, 1}], 
          padIt1[Fmz, {7, 1}],
          padIt2[I1c, {7, 1}], padIt2[I2c, {7, 1}], 
          padIt2[I3c, {7, 1}]},
         
         {"column", padIt2[columnMass/907.184, {3, 3}], 
          padIt1[Mcolumnx, {6, 1}], padIt1[Mcolumny, {6, 1}], 
          Dynamic@padIt1[Mcolumnz, {6, 1}],
          padIt1[0, {7, 1}], padIt1[0, {7, 1}], padIt1[0, {7, 1}],
          padIt2[I1column, {7, 1}], padIt2[I2column, {7, 1}], 
          padIt2[I3column, {7, 1}]}
         }, Frame -> All, Spacings -> {0.5, 0.5}, Alignment -> Left
        ]]
      }
     }
    ], ControlPlacement -> Top
  ],
 
 Item[
  Text@Grid[{
     {"critical joint section (beam/column joint)"},
     {
      Dynamic[Grid[{
         
         {"", 
          Item["\!\(\*SubscriptBox[\(M\), \(x\)]\) (kNm)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(M\), \(y\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(M\), \(z\)]\)", 
           Alignment -> Center],
          
          Item["\!\(\*SubscriptBox[\(F\), \(x\)]\) (k N)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(F\), \(y\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(F\), \(z\)]\)", 
           Alignment -> Center],
          
          Item["\!\(\*SubscriptBox[\(\[Sigma]\), \(x\)]\) (M Pa)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(\[Sigma]\), \(y\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(\[Sigma]\), \(z\)]\)", 
           Alignment -> Center],
          
          Item["\!\(\*SubscriptBox[\(\[Tau]\), \(x\)]\) (k Pa)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(\[Tau]\), \(y\)]\)", 
           Alignment -> Center], 
          Item["\!\(\*SubscriptBox[\(\[Tau]\), \(z\)]\)", 
           Alignment -> Center]},
         
         {"current",
          padIt1[Mweldx/10^3, {7, 3}],
          padIt1[Mweldy/10^3, {7, 3}],
          padIt1[Mweldz/10^3, {7, 3}],
          padIt1[Fweldx/10^3, {7, 3}],
          padIt1[Fweldy/10^3, {7, 3}],
          padIt1[Fweldz/10^3, {7, 3}],
          padIt1[currentDirectStressx/10^6, {6, 3}],
          padIt1[currentDirectStressy/10^6, {6, 3}],
          padIt1[currentDirectStressz/10^6, {6, 3}],
          padIt1[currentShearStressx/10^3, {7, 3}],
          padIt1[currentShearStressy/10^3, {7, 3}],
          padIt1[currentShearStressz/10^3, {7, 3}]
          },
         
         {"maximum",
          padIt1[maxMoment[[1]]/10^3, {7, 3}],
          padIt1[maxMoment[[2]]/10^3, {7, 3}],
          padIt1[maxMoment[[3]]/10^3, {7, 3}],
          
          padIt1[maxShear[[1]]/10^3, {7, 3}],
          padIt1[maxShear[[2]]/10^3, {7, 3}],
          padIt1[maxShear[[3]]/10^3, {7, 3}],
          padIt1[maxDirectStress[[1]]/10^6, {6, 3}],
          padIt1[maxDirectStress[[2]]/10^6, {6, 3}],
          padIt1[maxDirectStress[[3]]/10^6, {6, 3}],
          padIt1[maxShearStress[[1]]/10^3, {7, 3}],
          padIt1[maxShearStress[[2]]/10^3, {7, 3}],
          padIt1[maxShearStress[[3]]/10^3, {7, 3}]}
         
         }, Frame -> All, Spacings -> {0.5, 0.5}, Alignment -> Left
        ]]
      }
     }
    ], ControlPlacement -> Top
  ],
 
 
 {{tick, 0}, None},
 {{del, $MachineEpsilon}, None},
 {{tscale, 15}, None},
 {{showAxes, True}, None},
 {{material, "Aluminum 6061-O"}, None},
 {{density, 2700}, None},
 {{showW2Coordinates, True}, None},
 {{showW1Coordinates, False}, None},
 {{timeTick, 0.041}, None},
 {{state, "reset"}, None},
 {{t, 0}, None},
 {{phi, 0}, None},
 {{h1, 4}, None}, (*hight of main column in meters*)
 {{theta, 0}, None},
 {{op, 1}, None},
 {{opc, 0.2}, None},
 {{w1, 0}, None},
 {{w2, 0}, None},
 {{wpDot, 0.2}, None},
 {{wsDot, 0.9}, None},
 
 
 {{accHistory, ConstantArray[0, 5000]}, None},(*g vs. time *)
 {{timeHistoryIndex, 0}, None},
 {{timeValues, ConstantArray[0, 5000]}, None},(*time *)
 {{timeHistoryRidObject, ConstantArray[0, 5000]}, 
  None},(*velocity *)
 {{timeHistorywp, ConstantArray[0, 5000]}, None},(*wp *)
 {{timeHistoryws, ConstantArray[0, 5000]}, None},(*ws *)
 
 {{wp, 0}, None},
 {{ws, 0}, None},
 {{I1, 0}, None},
 {{I2, 0}, None},
 {{I3, 0}, None},
 {{I1column, 0}, None},
 {{I2column, 0}, None},
 {{I3column, 0}, None},
 
 {{I1c, 0}, None},
 {{I2c, 0}, None},
 {{I3c, 0}, None},
 {{Mx, 0}, None},
 {{My, 0}, None},
 {{Mz, 0}, None},
 
 {{Mcolumnx, 0}, None},
 {{Mcolumny, 0}, None},
 {{Mcolumnz, 0}, None},
 
 {{Mmx, 0}, None},
 {{Mmy, 0}, None},
 {{Mmz, 0}, None},
 
 {{Mweldx, 0}, None},
 {{Mweldy, 0}, None},
 {{Mweldz, 0}, None},
 {{Fweldx, 0}, None},
 {{Fweldy, 0}, None},
 {{Fweldz, 0}, None},
 
 {{beamMass, 0}, None},
 {{columnMass, 0}, None},
 
 {{currentDirectStressx, 0}, None},
 {{currentDirectStressy, 0}, None},
 {{currentDirectStressz, 0}, None},
 
 {{currentShearStressx, 0}, None},
 {{currentShearStressy, 0}, None},
 {{currentShearStressz, 0}, None},
 
 {{Fcgx, 0}, None},
 {{Fcgy, 0}, None},
 {{Fcgz, 0}, None},
 
 {{Fmx, 0}, None},
 {{Fmy, 0}, None},
 {{Fmz, 0}, None},
 
 {{beamThickness, 1}, None},
 {{beamWidth, 1}, None},
 {{L, 3.5}, None},
 {{Ls, 3}, None},
 
 {{isAcc, True}, None},
 {{gLimit, 5.8}, None},
 
 (*these are body axes angular velocity and angular acc *)
 {{z1, 0}, None},
 {{z2, 0}, None},
 {{z3, 0}, None},
 {{z1dot, 0}, None},
 {{z2dot, 0}, None},
 {{z3dot, 0}, None},
 
 {{maxMoment, {0, 0, 0}}, None},
 {{maxShear, {0, 0, 0}}, None},
 
 {{maxDirectStress, {0, 0, 0}}, None},
 {{maxShearStress, {0, 0, 0}}, None},
 {{massLoadI, 2*175 + 200}, 
  None},(*added 500 lb for seats and cabinet*)
 {{maxGReached, 0}, None},(*max g felt by rider*)
 {{maxVelocity, 0}, None},(*max velocity felt by rider*)
 {{timeReachedMaxG, 0}, None},(*time to reach max g*)
 
 SynchronousUpdating -> False,
 SynchronousInitialization -> False,
 ContinuousAction -> True,
 Alignment -> Center,
 ImageMargins -> 5,
 FrameMargins -> 5,
 Paneled -> True,(*False,*)
 Frame -> False,
 ControlPlacement -> Left,
 AutorunSequencing -> {1},
 TrackedSymbols :> {tick},
 Initialization :>
  (
   (*definitions used for parameter checking*)
   integerStrictPositive = (IntegerQ[#] && # > 0 &);
   integerPositive = (IntegerQ[#] && # >= 0 &);
   numericStrictPositive = (Element[#, Reals] && # > 0 &);
   numericPositive = (Element[#, Reals] && # >= 0 &);
   numericStrictNegative = (Element[#, Reals] && # < 0 &);
   numericNegative = (Element[#, Reals] && # <= 0 &);
   bool = (Element[#, Booleans] &);
   numeric = (Element[#, Reals] &);
   integer = (Element[#, Integers] &);
   (*--------------------------------------------*)
   padIt1[v_?numeric, f_List] := AccountingForm[v,
     f, NumberSigns -> {"-", "+"}, NumberPadding -> {"0", "0"}, 
     SignPadding -> True];
   (*--------------------------------------------*)
   padIt1[v_?numeric, f_Integer] := AccountingForm[Chop[v],
     f, NumberSigns -> {"-", "+"}, NumberPadding -> {"0", "0"}, 
     SignPadding -> True];
   (*--------------------------------------------*)
   padIt2[v_?numeric, f_List] := AccountingForm[v,
     f, NumberSigns -> {"", ""}, NumberPadding -> {"0", "0"}, 
     SignPadding -> True];
   (*--------------------------------------------*)
   padIt2[v_?numeric, f_Integer] := AccountingForm[Chop[v],
     f, NumberSigns -> {"", ""}, NumberPadding -> {"0", "0"}, 
     SignPadding -> True]
   (*--------------------------------------------*)
   )
 ]