MGFourBarDynamicsKaneEmbedded.html  (MotionGenesis input/output).
   (1) % MotionGenesis file:  MGFourBarDynamicsKaneEmbedded.txt
   (2) % Copyright (c) 2009 Motion Genesis LLC.  All rights reserved.
   (3) %--------------------------------------------------------------------
   (4) NewtonianFrame  N                 % Ground link.
   (5) RigidBody       A, B, C           % Crank, coupler, rocker links.
   (6) Point           BC( B )           % Point of B connected to C.
   (7) Point           CB( C )           % Point of C connected to B.
   (8) %--------------------------------------------------------------------
   (9) Constant   LN = 1 m,  LA = 1 m    % Length of ground link, crank link.
   (10) Constant   LB = 2 m,  LC = 2 m    % Length of coupler link, rocker link.
   (11) Constant   g = 9.81 m/s^2         % Earth's gravitational acceleration.
   (12) Specified  H = 200                % Horizontal force at point CB.
-> (13) H = 200

   (14) Specified  TA = 0                 % Motor torque on crank A from ground N.
-> (15) TA = 0

   (16) Variable   qA'',  qB'',  qC''     % Link angles (relative to ground).
   (17) SetGeneralizedSpeed( qA' )
   (18) %--------------------------------------------------------------------
   (19) A.SetMassInertia( mA = 10 kg,  0,  IA = mA*LA^2/12,  IA  )
-> (20) IA = 0.08333333*mA*LA^2

   (21) B.SetMassInertia( mB = 20 kg,  0,  IB = mB*LB^2/12,  IB  )
-> (22) IB = 0.08333333*mB*LB^2

   (23) C.SetMassInertia( mC = 20 kg,  0,  IC = mC*LC^2/12,  IC  )
-> (24) IC = 0.08333333*mC*LC^2

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

   (31) B.RotateZ( N,  qB )
-> (32) B_N = [cos(qB), sin(qB), 0;  -sin(qB), cos(qB), 0;  0, 0, 1]
-> (33) w_B_N> = qB'*Bz>
-> (34) alf_B_N> = qB''*Bz>

   (35) C.RotateZ( N,  qC )
-> (36) C_N = [cos(qC), sin(qC), 0;  -sin(qC), cos(qC), 0;  0, 0, 1]
-> (37) w_C_N> = qC'*Cz>
-> (38) alf_C_N> = qC''*Cz>

   (39) %--------------------------------------------------------------------
   (40) %   Translational kinematics.
   (41) Ao.Translate(   No,          0> )
-> (42) p_No_Ao> = 0>
-> (43) v_Ao_N> = 0>
-> (44) a_Ao_N> = 0>

   (45) Acm.Translate(  Ao,  0.5*LA*Ax> )
-> (46) p_Ao_Acm> = 0.5*LA*Ax>
-> (47) v_Acm_N> = 0.5*LA*qA'*Ay>
-> (48) a_Acm_N> = -0.5*LA*qA'^2*Ax> + 0.5*LA*qA''*Ay>

   (49) Bo.Translate(   Ao,      LA*Ax> )
-> (50) p_Ao_Bo> = LA*Ax>
-> (51) v_Bo_N> = LA*qA'*Ay>
-> (52) a_Bo_N> = -LA*qA'^2*Ax> + LA*qA''*Ay>

   (53) Bcm.Translate(  Bo,  0.5*LB*Bx> )
-> (54) p_Bo_Bcm> = 0.5*LB*Bx>
-> (55) v_Bcm_N> = LA*qA'*Ay> + 0.5*LB*qB'*By>
-> (56) a_Bcm_N> = -LA*qA'^2*Ax> + LA*qA''*Ay> - 0.5*LB*qB'^2*Bx> + 0.5*LB*qB''*By>

   (57) BC.Translate(   Bo,      LB*Bx> )
-> (58) p_Bo_BC> = LB*Bx>
-> (59) v_BC_N> = LA*qA'*Ay> + LB*qB'*By>
-> (60) a_BC_N> = -LA*qA'^2*Ax> + LA*qA''*Ay> - LB*qB'^2*Bx> + LB*qB''*By>

   (61) Co.Translate(   No,      LN*Ny> )
-> (62) p_No_Co> = LN*Ny>
-> (63) v_Co_N> = 0>
-> (64) a_Co_N> = 0>

   (65) Ccm.Translate(  Co,  0.5*LC*Cx> )
-> (66) p_Co_Ccm> = 0.5*LC*Cx>
-> (67) v_Ccm_N> = 0.5*LC*qC'*Cy>
-> (68) a_Ccm_N> = -0.5*LC*qC'^2*Cx> + 0.5*LC*qC''*Cy>

   (69) CB.Translate(   Co,      LC*Cx> )
-> (70) p_Co_CB> = LC*Cx>
-> (71) v_CB_N> = LC*qC'*Cy>
-> (72) a_CB_N> = -LC*qC'^2*Cx> + LC*qC''*Cy>

   (73) %--------------------------------------------------------------------
   (74) %   Add relevant forces and torques (replace gravity forces with equivalent set).
   (75) Bo.AddForce( 0.5*(mA+mB)*g*Nx> )
-> (76) Force_Bo> = 0.5*(mA+mB)*g*Nx>

   (77) CB.AddForce( 0.5*(mB+mC)*g*Nx> + H*Ny> )
-> (78) Force_CB> = 0.5*(mB+mC)*g*Nx> + H*Ny>

   (79) A.AddTorque( N,  TA * Az> )
-> (80) Torque_A_N> = TA*Az>

   (81) %--------------------------------------------------------------------
   (82) %   Configuration (loop) constraints and their time-derivatives.
   (83) Loop> = LA*Ax> + LB*Bx> - LC*Cx> - LN*Ny>
-> (84) Loop> = LA*Ax> + LB*Bx> - LC*Cx> - LN*Ny>

   (85) Loop[1] = Dot( Loop>, Nx> )
-> (86) Loop[1] = LA*cos(qA) + LB*cos(qB) - LC*cos(qC)

   (87) Loop[2] = Dot( Loop>, Ny> )
-> (88) Loop[2] = LA*sin(qA) + LB*sin(qB) - LN - LC*sin(qC)

   (89) %--------------------------------------------------------------------
   (90) %   Use the loop constraints to solve for initial values of qB, qC and qB',qC'
   (91) %   (results depend on constants and initial values of qA and qA').
   (92) Input  qA = 30 deg,  qA' = 0 rad/sec
   (93) SolveSetInputDt( Loop = 0,   qB = 60 deg,  qC = 20 deg )

->   %  INPUT has been assigned as follows:
->   %   qB                        74.47751218592991       deg
->   %   qC                        45.52248781407007       deg

-> (94) qB' = -LA*sin(qA-qC)*qA'/(LB*sin(qB-qC))
-> (95) qC' = -LA*sin(qA-qB)*qA'/(LC*sin(qB-qC))
-> (96) qB'' = (LC*qC'^2-cos(qC)*(LB*cos(qB)*qB'^2+LA*(cos(qA)*qA'^2+sin(qA)*
        qA''))-sin(qC)*(LB*sin(qB)*qB'^2+LA*(sin(qA)*qA'^2-cos(qA)*qA'')))/(LB*
        sin(qB-qC))

-> (97) qC'' = -(LB*qB'^2-cos(qB)*(LC*cos(qC)*qC'^2-LA*(cos(qA)*qA'^2+sin(qA)*
        qA''))-sin(qB)*(LC*sin(qC)*qC'^2-LA*(sin(qA)*qA'^2-cos(qA)*qA'')))/(LC*
        sin(qB-qC))

   (98) %--------------------------------------------------------------------
   (99) %   Equations of motion with Kane's method (Optional: Solve for qA'').
   (100) Dynamics = System.GetDynamicsKane()
-> (101) Dynamics[1] = 0.5*(mA+mB)*g*LA*sin(qA) + 0.5*LA*sin(qA-qB)*(2*H*cos(
         qC)-(mB+mC)*g*sin(qC))/sin(qB-qC) + 0.25*(4*IA+mA*LA^2+4*IB*LA^2*sin(
         qA-qC)^2/(LB^2*sin(qB-qC)^2)+LA^2*(mC+4*IC/LC^2)*sin(qA-qB)^2/sin(qB-
         qC)^2+mB*LA^2*(4+sin(qA-qC)^2/sin(qB-qC)^2-4*sin(qA-qC)*cos(qA-qB)/sin
         (qB-qC)))*qA'' - TA - 0.25*LA*(4*IB*sin(qA-qC)*(LC*qC'^2-sin(qC)*(LA*
         sin(qA)*qA'^2+LB*sin(qB)*qB'^2)-cos(qC)*(LA*cos(qA)*qA'^2+LB*cos(qB)*qB'^2))
         /(LB^2*sin(qB-qC)^2)-mC*sin(qA-qB)*(LB*qB'^2+sin(qB)*(LA*sin(qA)*qA'^2
         -LC*sin(qC)*qC'^2)+cos(qB)*(LA*cos(qA)*qA'^2-LC*cos(qC)*qC'^2))/sin(
         qB-qC)^2-4*IC*sin(qA-qB)*(LB*qB'^2+sin(qB)*(LA*sin(qA)*qA'^2-LC*sin(
         qC)*qC'^2)+cos(qB)*(LA*cos(qA)*qA'^2-LC*cos(qC)*qC'^2))/(LC^2*sin(qB-
         qC)^2)-mB*(2*LB*sin(qA-qB)*qB'^2+(2*cos(qA-qB)*(LC*qC'^2-sin(qC)*(LA*
         sin(qA)*qA'^2+LB*sin(qB)*qB'^2)-cos(qC)*(LA*cos(qA)*qA'^2+LB*cos(qB)*qB'^2))
         +sin(qA-qC)*(2*LA*sin(qA-qB)*qA'^2-(LC*qC'^2-sin(qC)*(LA*sin(qA)*qA'^2
         +LB*sin(qB)*qB'^2)-cos(qC)*(LA*cos(qA)*qA'^2+LB*cos(qB)*qB'^2))/sin(
         qB-qC)))/sin(qB-qC)))

   (102) Solve( Dynamics = 0,   qA'' )
-> (103) qA'' = -(2*(mA+mB)*g*LA*sin(qA)+2*LA*sin(qA-qB)*(2*H*cos(qC)-(mB+mC)*g
         *sin(qC))/sin(qB-qC)-4*TA-LA*(4*IB*sin(qA-qC)*(LC*qC'^2-sin(qC)*(LA*
         sin(qA)*qA'^2+LB*sin(qB)*qB'^2)-cos(qC)*(LA*cos(qA)*qA'^2+LB*cos(qB)*qB'^2))
         /(LB^2*sin(qB-qC)^2)-mC*sin(qA-qB)*(LB*qB'^2+sin(qB)*(LA*sin(qA)*qA'^2
         -LC*sin(qC)*qC'^2)+cos(qB)*(LA*cos(qA)*qA'^2-LC*cos(qC)*qC'^2))/sin(
         qB-qC)^2-4*IC*sin(qA-qB)*(LB*qB'^2+sin(qB)*(LA*sin(qA)*qA'^2-LC*sin(
         qC)*qC'^2)+cos(qB)*(LA*cos(qA)*qA'^2-LC*cos(qC)*qC'^2))/(LC^2*sin(qB-
         qC)^2)-mB*(2*LB*sin(qA-qB)*qB'^2+(2*cos(qA-qB)*(LC*qC'^2-sin(qC)*(LA*
         sin(qA)*qA'^2+LB*sin(qB)*qB'^2)-cos(qC)*(LA*cos(qA)*qA'^2+LB*cos(qB)*qB'^2))
         +sin(qA-qC)*(2*LA*sin(qA-qB)*qA'^2-(LC*qC'^2-sin(qC)*(LA*sin(qA)*qA'^2
         +LB*sin(qB)*qB'^2)-cos(qC)*(LA*cos(qA)*qA'^2+LB*cos(qB)*qB'^2))/sin(
         qB-qC)))/sin(qB-qC))))/(4*IA+mA*LA^2+4*IB*LA^2*sin(qA-qC)^2/(LB^2*sin(
         qB-qC)^2)+LA^2*(mC+4*IC/LC^2)*sin(qA-qB)^2/sin(qB-qC)^2+mB*LA^2*(4+sin
         (qA-qC)^2/sin(qB-qC)^2-4*sin(qA-qC)*cos(qA-qB)/sin(qB-qC)))

   (104) %--------------------------------------------------------------------
   (105) %   Numerical integration parameters.
   (106) Input  tFinal = 7 sec,  tStep = 0.02 sec,  absError = 1.0E-07
   (107) %--------------------------------------------------------------------
   (108) %   List quantities to be output from ODE.
   (109) Output  t sec,  qA deg,  qB deg,  qC deg
   (110) %--------------------------------------------------------------------
   (111) %   Solve ODEs (plot results).
   (112) ODE()  MGFourBarDynamicsKaneEmbedded

   (113) % Plot  MGFourBarDynamicsKaneEmbedded.1 [1, 2, 3, 4]
   (114) %
   (115) %
   (116) %
   (117) %********************************************************************
   (118) %   Design 4-bar linkage to draw Valentines heart.
   (119) Input LN := 2,  LA := 4 m,  LB := 4 m,  LC := 4 m,  mA := 20 kg
   (120) %--------------------------------------------------------------------
   (121) %   Control motor torque so qA' is nearly 60 degrees/sec.
   (122) Constant  wMotor = 60 deg/sec     % Desired motor angular speed.
   (123) Constant  kw = 9600 N*m/rad       % Control constant.
   (124) TA := kw * (wMotor - qA')         % Motor torque on crank A from ground N.
-> (125) TA = kw*(wMotor-qA')

   (126) H := 0                            % Remove horizontal force at point CB.
-> (127) H = 0

   (128) %--------------------------------------------------------------------
   (129) %   Output coupler point position for Valentines heart.
   (130) Point     CouplerPoint( B )
   (131) Constant  CouplerDistance = sqrt(8) m     % For conventional heart, use  2.66
   (132) Constant  CouplerAngle = 45 degrees       % For conventional heart, use 41.20
   (133) couplerPointBx = CouplerDistance * cos(CouplerAngle)
-> (134) couplerPointBx = CouplerDistance*cos(CouplerAngle)

   (135) couplerPointBy = CouplerDistance * sin(CouplerAngle)
-> (136) couplerPointBy = CouplerDistance*sin(CouplerAngle)

   (137) CouplerPoint.SetPosition( Bo,  couplerPointBx * Bx> + couplerPointBy * By> )
-> (138) p_Bo_CouplerPoint> = couplerPointBx*Bx> + couplerPointBy*By>

   (139) couplerPointHorizontal = Dot( CouplerPoint.GetPosition(No),  Ny> )
-> (140) couplerPointHorizontal = LA*sin(qA) + couplerPointBx*sin(qB) + couple
         rPointBy*cos(qB)

   (141) CouplerPointVertical  = -Dot( CouplerPoint.GetPosition(No),  Nx> )
-> (142) CouplerPointVertical = couplerPointBy*sin(qB) - LA*cos(qA) - couplerP
         ointBx*cos(qB)

   (143) Output  couplerPointHorizontal m,  CouplerPointVertical m,  qA' deg/sec, TA N*m
   (144) %--------------------------------------------------------------------
   (145) %   Initial configuration is coupler link B horizontal (qB = 90 degrees).
   (146) %   Use the loop constraints to solve for initial values of qA, qB.
   (147) %   Use loopDt to solve for initial values of qB', qC'.
   (148) Input  qB := 90 deg,  qA' := Input(wMotor, noUnitSystem) deg/sec
   (149) SolveSetInput( Loop = 0,   qA = -15 deg,   qC  = 15 deg )

->    %  INPUT has been assigned as follows:
->    %   qA                       -14.47751218592985       deg
->    %   qC                        14.47751218592986       deg

   (150) %--------------------------------------------------------------------
   (151) %   Solve ODEs (plot results).
   (152) ODE() MGFourBarDynamicsValentinesHeart

   (153) Plot MGFourBarDynamicsValentinesHeart.2 [1, 2]
   (154) %--------------------------------------------------------------------
   (155) %   Save input together with program responses.
Saved by Motion Genesis LLC.   Command names and syntax: Copyright (c) 2009-2018 Motion Genesis LLC. All rights reserved.