MGTrailerSingleWheelTrailerDynamics.html   (MotionGenesis input/output).
```   (1) % MotionGenesis file:  MGTrailerSingleWheelTrailerDynamics.txt
(3) %--------------------------------------------------------------------
(4) NewtonianFrame N             % Flat horizontal road.
(5) RigidBody      A             % Trailer chassis.
(6) RigidBody      B             % Trailer wheel.
(7) Point          AH( A )       % Trailer hitch connected to car.
(8) Point          BN( B )       % Point of wheel B in contact with road N.
(9) %--------------------------------------------------------------------
(10) Variable  q''                % Chassis A's rotation angle in N (theta).
(11) Variable  y''                % Wheel B's motion relative to chassis.
(12) Variable  w'                 % Wheel rotation relative to chassis.
(13) Constant  r = 0.25 m         % Radius of wheel.
(14) Constant  L = 1.5  m         % Ax> measure of AH's position from Bcm.
(15) Constant  k = 9000 N/m       % Linear spring constant.
(16) Constant  b = 900 N*s/m      % Linear damping constant.
(17) Constant  v                  % Known speed of point AH in N.
(18) B.SetMass( m = 20 kg )
(19) A.SetInertia( AH,  A, Ix, Iy, IA = 400 kg*m^2 )
(20) B.SetInertia( Bcm, A, JB, IB = 0.5*m*r^2, JB = 0.5*IB )
-> (21) IB = 0.5*m*r^2
-> (22) JB = 0.5*IB

(23) SetGeneralizedSpeed( q' )
(24) %--------------------------------------------------------------------
(25) %       Rotational kinematics.
(26) A.RotateZ( N, q )
-> (27) A_N = [cos(q), sin(q), 0;  -sin(q), cos(q), 0;  0, 0, 1]
-> (28) w_A_N> = q'*Az>
-> (29) alf_A_N> = q''*Az>

(30) B.SetAngularVelocityAcceleration( A, w*Ay> )
-> (31) w_B_A> = w*Ay>
-> (32) w_B_N> = w*Ay> + q'*Az>
-> (33) alf_B_A> = w'*Ay>
-> (34) alf_B_N> = -w*q'*Ax> + w'*Ay> + q''*Az>

(35) %--------------------------------------------------------------------
(36) %       Translational kinematics.
(37) AH.SetVelocityAcceleration( N, v*Nx> )
-> (38) v_AH_N> = v*Nx>
-> (39) a_AH_N> = 0>

(40) Ao.Translate( AH, -L*Ax> )
-> (41) p_AH_Ao> = -L*Ax>
-> (42) v_Ao_N> = -L*q'*Ay> + v*Nx>
-> (43) a_Ao_N> = L*q'^2*Ax> - L*q''*Ay>

(44) Bcm.Translate( Ao, y*Ay> )
-> (45) p_Ao_Bcm> = y*Ay>
-> (46) v_Bcm_N> = -y*q'*Ax> + (y'-L*q')*Ay> + v*Nx>
-> (47) a_Bcm_N> = (L*q'^2-2*q'*y'-y*q'')*Ax> + (y''-y*q'^2-L*q'')*Ay>

(48) BN.SetPositionVelocity( Bcm, -r*Az> )
-> (49) p_Bcm_BN> = -r*Az>
-> (50) v_BN_N> = (-r*w-y*q')*Ax> + (y'-L*q')*Ay> + v*Nx>

(51) %--------------------------------------------------------------------
(52) %       Motion constraints (B rolls on N).
(53) RollingConstraint[1] = Dot( BN.GetVelocity(N), Ax> )
-> (54) RollingConstraint[1] = v*cos(q) - r*w - y*q'

(55) RollingConstraint[2] = Dot( BN.GetVelocity(N), Ay> )
-> (56) RollingConstraint[2] = y' - v*sin(q) - L*q'

(57) SolveDt( RollingConstraint, y', w )
-> (58) y' = v*sin(q) + L*q'
-> (59) w = (v*cos(q)-y*q')/r
-> (60) y'' = v*cos(q)*q' + L*q''
-> (61) w' = -(v*sin(q)*q'+q'*y'+y*q'')/r

(62) %--------------------------------------------------------------------
(63) %       Add relevant forces (spring/damper).
(64) Bcm.AddForce( Ao, -(k*y + b*y')*Ay> )
-> (65) Force_Bcm_Ao> = (-k*y-b*y')*Ay>

(66) %--------------------------------------------------------------------
(67) %       Form and simplify Kane's equations of motion.
(68) Zero = System.GetDynamicsKane()
-> (69) Zero[1] = L*(k*y+b*y') + (IA+JB+m*y^2+IB*y^2/r^2)*q'' - y*q'*(m*(L*q'-2
*y')-IB*(v*sin(q)+y')/r^2)

(70) FactorQuadratic( Zero, q'', q', y' )
-> (71) Zero[1] = k*L*y + IB*v*y*sin(q)*q'/r^2 + b*L*y' + (2*m+IB/r^2)*y*q'*y'
+ (IA+JB+m*y^2+IB*y^2/r^2)*q'' - m*L*y*q'^2

(72) %--------------------------------------------------------------------
(73) %       Input and output quantities for all simulations.
(74) Input   tFinal = 8 sec,  tStep = 0.02 sec
(75) Input   q = 1 degree,  q' = 0 rad/sec,  y = 0 cm
(76) Output  t sec,  q degrees,  y cm
(77) %--------------------------------------------------------------------
(78) %       Simulate trailer's motion for various values of v.
(79) Input   v = -5 m/s
(80) ODE( Zero, q'' )  SingleWheelTrailerWithVNegative05

(81) Input   v := 10 m/s
(82) ODE( Zero, q'' )  SingleWheelTrailerWithVPositive10

(83) Input   v := 20 m/s
(84) ODE( Zero, q'' )  SingleWheelTrailerWithVPositive20

(85) %--------------------------------------------------------------------
```