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

   (20) %-----------------------------------------------------------
   (21) %       Position, velocity, acceleration
   (22) B.Translate(  No,  x*Nx>  )
-> (23) p_No_B> = x*Nx>
-> (24) v_B_N> = x'*Nx>
-> (25) a_B_N> = x''*Nx>

   (26) %-----------------------------------------------------------
   (27) %       Forces on B
   (28) B.AddForce( -m*g*Ny>  )                            % Gravitational force
-> (29) Force_B> = -m*g*Ny>

   (30) stretch = x - Ln                                   % Spring stretch.
-> (31) stretch = x - Ln

   (32) B.AddForce( -(k*stretch + b*Dt(stretch))*Nx> )     % Spring/damper force
-> (33) Force_B> = (-k*stretch-b*x')*Nx> - m*g*Ny>

   (34) B.AddForce( Fn*Ny> + Ff*Nx> )                      % Normal and friction forces
-> (35) Force_B> = (Ff-k*stretch-b*x')*Nx> + (Fn-m*g)*Ny>

   (36) B.AddForce( Fx*Nx> )                               % Specified force
-> (37) Force_B> = (Fx+Ff-k*stretch-b*x')*Nx> + (Fn-m*g)*Ny>

   (38) %-----------------------------------------------------------
   (39) %       Equations of motion for B via F = m*a
   (40) Dynamics[1] = Dot( Nx>,  B.GetDynamics() )
-> (41) Dynamics[1] = k*stretch + b*x' + m*x'' - Fx - Ff

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

   (44) %-----------------------------------------------------------
   (45) %       Equation governing Ff when B is sliding on N.
   (46) %       Note: Use Continuous Friction Law to simulate sticking and sliding.
   (47) %       Set epsilonV to a small positive number to avoid divide-by-zero problems.
   (48) magVelocity = B.GetSpeed( N )
-> (49) magVelocity = abs(x')

   (50) magVelocityPlusEpsilon = magVelocity + epsilonV
-> (51) magVelocityPlusEpsilon = epsilonV + magVelocity

   (52) Ff = Dot( -muK*Fn*B.GetVelocity(N) / magVelocityPlusEpsilon, Nx> )
-> (53) Ff = -muK*Fn*x'/magVelocityPlusEpsilon

   (54) %-----------------------------------------------------------
   (55) %       Solve sliding equation of motion for x''
   (56) Solve( Dynamics = 0,  x'', Fn )
-> (57) x'' = (Fx-k*stretch-b*x')/m - g*muK*x'/magVelocityPlusEpsilon
-> (58) Fn = m*g

   (59) %-----------------------------------------------------------
   (60) %       Integration parameters and initial values.
   (61) Input  tFinal = 12 sec,  tStep = 0.01 sec,  absError = 1.0E-07
   (62) Input  x = Input(Ln) m,  x' = 0 m/s
   (63) %-----------------------------------------------------------
   (64) %       List output quantities and solve ODEs.
   (65) Output  t sec,   x m,   x' m/s,  x'' m/s^2,  Ff Newton
   (66) ODE()  MGStickSlipMassSpringDamperPulledBySpecifiedForce

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