MGStickSlipMassSpringDamperPulledBySpecifiedMotion.html  (MotionGenesis input/output).
   (1) % MotionGenesis file:  MGStickSlipMassSpringDamperPulledBySpecifiedMotion.txt
   (2) % Purpose: Simulate mass-spring-damper on rough table.
   (3) % Copyright (c) 2017 Motion Genesis LLC.  All rights reserved.
   (4) %-----------------------------------------------------------
   (5) NewtonianFrame  N                 % Ground (Earth).
   (6) Particle        A                 % Block whose motion is specified.
   (7) Particle        B                 % Block connected by spring/damper to A.
   (8) B.SetMass( m = 1 kg )
   (9) %-----------------------------------------------------------
   (10) Variable   x''                    % B's horizontal displacement from No.
   (11) Variable   Fn                     % Resultant normal   force on B.
   (12) Variable   Ff                     % Resultant friction force on B.
   (13) Constant   g = 9.8 m/s^2          % Earth's gravitational acceleration.
   (14) Constant   k = 400 N/m            % Linear spring constant.
   (15) Constant   Ln = 4 m               % Natural length of spring.
   (16) Constant   b = 4 N*s/m            % Linear damper constant (zeta = 0.1).
   (17) Constant   epsilonV = 1.0E-5 m/s  % For Continuous Friction law, small sliding speed.
   (18) Constant   muK = 0.2 noUnits      % Coefficient of kinetic friction.
   (19) Constant   muS = 0.4 noUnits      % Coefficient of static  friction.
   (20) Specified  xA''                   % A's horizontal displacement from No.
   (21) SetDt( xA = Ln + 2*t )            % A's specified horizontal displacement from No.
-> (22) xA = Ln + 2*t
-> (23) xA' = 2
-> (24) xA'' = 0

   (25) %-----------------------------------------------------------
   (26) %       Position, velocity, acceleration
   (27) A.Translate(  No,  xA*Nx>  )
-> (28) p_No_A> = xA*Nx>
-> (29) v_A_N> = xA'*Nx>
-> (30) a_A_N> = xA''*Nx>

   (31) B.Translate(  No,  x*Nx>  )
-> (32) p_No_B> = x*Nx>
-> (33) v_B_N> = x'*Nx>
-> (34) a_B_N> = x''*Nx>

   (35) %-----------------------------------------------------------
   (36) %       Forces on B
   (37) B.AddForce( -m*g*Ny>  )                            % Gravitational force
-> (38) Force_B> = -m*g*Ny>

   (39) stretch = xA - x - Ln                              % Spring stretch.
-> (40) stretch = xA - Ln - x

   (41) B.AddForce( A, (k*stretch + b*Dt(stretch))*Nx> )   % Spring/damper force
-> (42) Force_B_A> = (k*stretch+b*(xA'-x'))*Nx>

   (43) B.AddForce( Fn*Ny> + Ff*Nx> )                      % Normal and friction forces
-> (44) Force_B> = Ff*Nx> + (Fn-m*g)*Ny>

   (45) %-----------------------------------------------------------
   (46) %       Equations of motion for B via F = m*a
   (47) Dynamics[1] = Dot( Nx>,  B.GetDynamics() )
-> (48) Dynamics[1] = m*x'' - Ff - k*stretch - b*(xA'-x')

   (49) Dynamics[2] = Dot( Ny>,  B.GetDynamics() )
-> (50) Dynamics[2] = m*g - Fn

   (51) %-----------------------------------------------------------
   (52) %       Equation governing Ff when B is sliding on N.
   (53) %       Note: Use Continuous Friction Law to simulate sticking and sliding.
   (54) %       Set epsilonV to a small positive number to avoid divide-by-zero problems.
   (55) magVelocity = B.GetSpeed( N )
-> (56) magVelocity = abs(x')

   (57) magVelocityPlusEpsilon = magVelocity + epsilonV
-> (58) magVelocityPlusEpsilon = epsilonV + magVelocity

   (59) slidingEquation = Ff + Dot( muK*Fn*B.GetVelocity(N) / magVelocityPlusEpsilon, Nx> )
-> (60) slidingEquation = Ff + muK*Fn*x'/magVelocityPlusEpsilon

   (61) %-----------------------------------------------------------
   (62) %       Equation governing Ff when B is slicking on N.
   (63) %       Note: When sticking, x' = 0 and x'' = 0.
   (64) stickingEquation = x''
-> (65) stickingEquation = x''

   (66) %-----------------------------------------------------------
   (67) %       Combine sticking and sliding into a single equation.
   (68) Constant  isSticking = 0 noUnits
   (69) Dynamics[3] = isSticking * stickingEquation + (1-isSticking)*slidingEquation
-> (70) Dynamics[3] = (1-isSticking)*slidingEquation + isSticking*x''

   (71) %-----------------------------------------------------------
   (72) %       Integration parameters and initial values.
   (73) Input  tFinal = 3 sec,  tStep = 0.01 sec,  absError = 1.0E-07
   (74) Input  x = 0 m,  x' = 0 m/s
   (75) %-----------------------------------------------------------
   (76) %       List output quantities and solve ODEs.
   (77) Output  t sec,   x m,   x' m/s,  x'' m/s^2,  Stretch Newton,  Dt(Stretch) m/s,  Ff Newton,  isSticking noUnits
   (78) ODE( Dynamics = 0,   x'',  Fn,  Ff )  MGStickSlipMassSpringDamperPulledBySpecifiedMotion

   (79) %-----------------------------------------------------------
Saved by Motion Genesis LLC.   Command names and syntax: Copyright (c) 2009-2019 Motion Genesis LLC. All rights reserved.