Dynamic Equations for the 2 DOF Helicopter

©  2006 Quanser Consulting Inc.

URL: http://www.quanser.com

NOTE: This worksheet presents the general dynamic equations modelling a 2 DOF Helicopter.

Description

The Quanser_Tools  Package

References

Worksheet Initialization

>    restart: interface( imaginaryunit = j ):

>    with( LinearAlgebra ):

>    libname := "C:/Program Files/Quanser/Maple Repository", ".", libname:

>    with( Quanser_Tools );

[deriveA, deriveB, deriveF, kinetic_energy, lagrange_equations, moment_of_inertia, n_norm, potential_energy, write_ABCD_to_Mfile]

environment variable representing the order of series calculations

>    Order := 2:

Notations

Generalized Coordinates: q[i] 's

The generalized coordinates are also called Lagrangian coordinates.

theta(t)  =  pitch angle

psi(t)  = yaw angle

>    q := [ theta(t), psi(t)];

q := [theta(t), psi(t)]

Nq = number of Lagrangian coordinates (e.g. here, it is Nq = 2)

Nq is also the number of position states.

>    Nq := nops( q ):

qd = first-order time derivative of the generalized coordinates, e.g. position and angular velocities

>    qd := map( diff, q, t );

qd := [diff(theta(t),t), diff(psi(t),t)]

Transformation Matrices

Rotate base coordinate about yaw: T_0_1 = Rot(Z0, psi)

>    T_0_1 := matrix(4,4,[
cos(-q[2]),-sin(-q[2]),0,0,
sin(-q[2]),cos(-q[2]),0,0,
0,0,1,0,
0,0,0,1]);

T_0_1 := matrix([[cos(psi(t)), sin(psi(t)), 0, 0], [-sin(psi(t)), cos(psi(t)), 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

Rotate about pitch: T_1_2 =  Rot(Y1, theta)

>    T_1_2 := matrix(4,4,[
cos(-q[1]),0,sin(-q[1]),0,
0,1,0,0,
-sin(-q[1]),0,cos(-q[1]),0,
0,0,0,1]);

T_1_2 := matrix([[cos(theta(t)), 0, -sin(theta(t)), 0], [0, 1, 0, 0], [sin(theta(t)), 0, cos(theta(t)), 0], [0, 0, 0, 1]])

Translate about O2 to center of mass of helicopter: T_2_3 = Trans(X2, lcm)

>    T_2_3 := matrix(4,4,[
1,0,0,l[cm],
0,1,0,0,
0,0,1,0,
0,0,0,1]);

T_2_3 := matrix([[1, 0, 0, l[cm]], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

Base coordinate system, O0, to center of mass , O3: T_0_3 = T_0_1 * T_1_2 * T_2_3

>    T_0_3 := evalm( T_0_1 &* T_1_2 &* T_2_3);

T_0_3 := matrix([[cos(psi(t))*cos(theta(t)), sin(psi(t)), -cos(psi(t))*sin(theta(t)), cos(psi(t))*cos(theta(t))*l[cm]], [-sin(psi(t))*cos(theta(t)), cos(psi(t)), sin(psi(t))*sin(theta(t)), -sin(psi(t))...

Cartesian Coordinates of the Helicopter's Centre Of Gravity

conventions:

1) theta = 0  corresponds to the helicopter being horizontal

2) positive rotation about pitch axis,   0 < diff(theta(t),t) , is CCW

3) positive rotation of about yaw axis, 0 < diff(psi(t),t)  , is CW.

Absolute 3-dimensional Cartesian position: CM of 2 DOF Helicopter.

>    x[cm] := T_0_3[1,4];
y[cm] := T_0_3[2,4];
z[cm] := T_0_3[3,4];

x[cm] := cos(psi(t))*cos(theta(t))*l[cm]

y[cm] := -sin(psi(t))*cos(theta(t))*l[cm]

z[cm] := sin(theta(t))*l[cm]

Absolute 3-dimensional Cartesian velocities.

>    xd[cm] := diff( x[cm], t );
yd[cm] := diff( y[cm], t );
zd[cm] := diff( z[cm], t );

xd[cm] := -sin(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]-cos(psi(t))*sin(theta(t))*diff(theta(t),t)*l[cm]

yd[cm] := -cos(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]+sin(psi(t))*sin(theta(t))*diff(theta(t),t)*l[cm]

zd[cm] := cos(theta(t))*diff(theta(t),t)*l[cm]

State-Space Variables

  • The chosen states should at least include the generalized coordinates and their first-time derivatives.
  • X is the state vector.
  • In the state vector X: Lagrangian coordinates are first, followed by their first-time derivatives, and finally any other states, as required.

Substitution sets for the states (to obtain time-independent state equations).

>    subs_Xq := { seq( q[i] = X[i], i=1..Nq ) };
subs_Xqd := { seq( qd[i] = X[i+Nq], i=1..Nq ) };

subs_Xq := {theta(t) = X[1], psi(t) = X[2]}

subs_Xqd := {diff(theta(t),t) = X[3], diff(psi(t),t) = X[4]}

Substitution set for the input(s). set the input to be the motor voltage:

>    subs_U := { V[m_p] = U[1], V[m_y] = U[2] }:

set the input to be the torque applied by the motor shaft, tau[output]  (if not expressed as a function of the motor voltage):

>    #subs_U := { tau[p] = U[1], tau[y] = U[2] }:

Nu = number of inputs; U = input (row) vector (e.g. U = [ V[m] ] )

>    Nu := nops( subs_U ):

substitution set for the position states' second time derivatives

>    subs_Xqdd := { seq( diff( q[i], t$2 ) =  Xd[i+Nq], i=1..Nq ) };

subs_Xqdd := {diff(theta(t),`$`(t,2)) = Xd[3], diff(psi(t),`$`(t,2)) = Xd[4]}

second time derivatives of the position states (written as time-independent variables).

The set of unknowns is obtained from this list to solve the Lagrange's equations of motion.

>    Xqdd := [ seq( Xd[i+Nq], i=1..Nq ) ];

Xqdd := [Xd[3], Xd[4]]

substitution set to linearize the state-space matrices (i.e. A and B)

about the quiescent null state vector (small-displacement theory)

>    subs_XUzero := { seq( X[i] = 0, i=1..2*Nq ), seq( U[i] = 0, i=1..Nu ) }:

Nx = dim( X ) = total number of states (should be greater than or equal to: 2 * Nq)

Ny = chosen number of outputs

>    Nx := 2 * Nq + 0:
Ny := Nq:

Total Potential and Kinetic Energies of the System

The total potential and kinetic energies are needed to calculate the Lagrangian of the system.

Total Potential Energy: V[T]  

The total potential energy can be expressed in terms of the generalized coordinates alone.

V[e] = Total Elastic Potential Energy of the system

>    V[e] := 0:

V[g]  = potential energy of helicopter.

>    V[g] := potential_energy( 'gravity', m[heli], g, z[cm] );

V[g] := m[heli]*g*sin(theta(t))*l[cm]

V[T] = Total Potential Energy of the system

>    V[T] := simplify( V[g] + V[e] );

V[T] := m[heli]*g*sin(theta(t))*l[cm]

Total Kinetic Energy: T[T]

The total kinetic energy can be expressed in terms of the generalized coordinates and their first-time derivatives.

T[r1]  = kinetic energy due to rotation of arm

J[m]  = moment of inertia of motor and rotary arm.

>    Tr[1] := kinetic_energy( 'rotation', J[eq_p], qd[1] );

Tr[1] := 1/2*J[eq_p]*diff(theta(t),t)^2

>    Tr[2] := kinetic_energy( 'rotation', J[eq_y], qd[2] );

Tr[2] := 1/2*J[eq_y]*diff(psi(t),t)^2

v[cm] = cm cartesian velocity (magnitude)

Tt[2] = cm translational kinetic kinergy

>    v[cm] := n_norm( [ xd[cm], yd[cm], zd[cm] ], 2 ):
Tt := kinetic_energy( 'translation', m[heli], v[cm] );

Tt := 1/2*m[heli]*((-sin(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]-cos(psi(t))*sin(theta(t))*diff(theta(t),t)*l[cm])^2+(-cos(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]+sin(psi(t))*sin(theta(t))*diff(t...
Tt := 1/2*m[heli]*((-sin(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]-cos(psi(t))*sin(theta(t))*diff(theta(t),t)*l[cm])^2+(-cos(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]+sin(psi(t))*sin(theta(t))*diff(t...

Total kinetic energy

>    T[T] := Tr[1] + Tr[2] + Tt;
T[T] := collect( T[T], diff ):

T[T] := 1/2*J[eq_p]*diff(theta(t),t)^2+1/2*J[eq_y]*diff(psi(t),t)^2+1/2*m[heli]*((-sin(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]-cos(psi(t))*sin(theta(t))*diff(theta(t),t)*l[cm])^2+(-cos(psi(t))*diff(...
T[T] := 1/2*J[eq_p]*diff(theta(t),t)^2+1/2*J[eq_y]*diff(psi(t),t)^2+1/2*m[heli]*((-sin(psi(t))*diff(psi(t),t)*cos(theta(t))*l[cm]-cos(psi(t))*sin(theta(t))*diff(theta(t),t)*l[cm])^2+(-cos(psi(t))*diff(...

Generalized Forces: Q[i] 's

The non-conservative forces corresponding to the generalized coordinates are: tau[m]  and the viscous damping forces, where

tau[p]  = torque acting on pitch axis

tau[y]  = torque acting on yaw axis

B[eq,p]  = pitch viscous friction torque coefficient (a.k.a. viscous damping)

B[eq,y]  = yaw viscous friction torque coefficient (a.k.a. viscous damping)

B[eq,p]  = 0 and B[eq,y] = 0  if both viscous dampings are neglected

>    #B[eq_p] := 0:
#B[eq_y] := 0:

Q[i] = generalized force applied on generalized coordinate q[i]

>    Q[1] := tau[p] - B[p] * qd[1];

Q[1] := tau[p]-B[p]*diff(theta(t),t)

>    Q[2] := tau[y] - B[y] * qd[2];

Q[2] := tau[y]-B[y]*diff(psi(t),t)

rm: comment the following line out if u = [tau[p], tau[y]]^T , uncomment it if u = [v[p], v[y]]^T

>    tau[p] := K[pp] * V[m_p]  + K[py] * V[m_y];

tau[p] := K[pp]*V[m_p]+K[py]*V[m_y]

>    tau[y] := K[yy] * V[m_y] + K[yp] * V[m_p];

tau[y] := K[yy]*V[m_y]+K[yp]*V[m_p]

>    Q := [ seq( Q[i], i=1..Nq ) ];

Q := [K[pp]*V[m_p]+K[py]*V[m_y]-B[p]*diff(theta(t),t), K[yy]*V[m_y]+K[yp]*V[m_p]-B[y]*diff(psi(t),t)]

Euler-Lagrange's Equations

For a N -DOF system, the Lagrange's equations can be written:

Diff(Diff(L,qdot[i]),t)-Diff(L,q[i]) = Q[i]   for i = 1  through N

where:

  Q[i] 's are special combinations of external forces and called the generalized forces,

  q[1] , ..., q[N] , are N independent coordinates chosen to describe the system and called the generalized coordinates ,

 and L  is the Lagrangian  of the system.

L  is defined by:

L = T-U

where T  is the total kinetic energy of the system and U  the total potential energy of the system.

>    EOM_orig := lagrange_equations( T[T], V[T], q, Q ):

this is to display the EOM's

>    EOM_orig := collect( EOM_orig, { seq( diff( q[i], t$2 ), i=1..Nq ), seq( diff( q[i], t ), i=1..Nq ), seq( q[i], i=1..Nq ) } ):

Express the Euler-Lagrange equations of motion as functions of the states:

1) substitute (i.e. name) the acceleration states first!

2) then substitute the velocity states!

3) and only after, the position states, and the inputs!

>    EOM_states := subs( subs_Xqd, subs( subs_Xqdd, EOM_orig ) ):

>    EOM_states := subs( subs_Xq, subs_U, EOM_states ):

Linearization  in the EOM's   of the Trigonometric Functions

Linearization of the equations of motion around the quiescent point of operation (in order to solve them).

Here, linearization around the zero angles, i.e. for small-amplitude oscillations.

Linearization around: theta[0] = 0 , Diff(theta[0],t) = 0 , psi[0] = 0 ,  and Diff(psi[0],t) = 0

>    EOM_ser := EOM_states:

Generalized series expansions of the trigonometric functions is used (for small angles).

>    for i from 1 to Nq do
      EOM_ser[i] := subsop( 1 = convert( series( op( 1, EOM_ser[i] ), X[ 1 ] ), polynom ), EOM_ser[i] );
  EOM_ser[i] := simplify( EOM_ser[i] );
end do:

>    EOM_ser;

[Xd[3]*J[eq_p]+Xd[3]*m[heli]*l[cm]^2+m[heli]*g*l[cm]+m[heli]*X[4]^2*l[cm]^2*X[1] = K[pp]*U[1]+K[py]*U[2]-B[p]*X[3], (J[eq_y]+m[heli]*l[cm]^2)*Xd[4]-2*m[heli]*X[4]*l[cm]^2*X[3]*X[1] = K[yy]*U[2]+K[yp]*U...
[Xd[3]*J[eq_p]+Xd[3]*m[heli]*l[cm]^2+m[heli]*g*l[cm]+m[heli]*X[4]^2*l[cm]^2*X[1] = K[pp]*U[1]+K[py]*U[2]-B[p]*X[3], (J[eq_y]+m[heli]*l[cm]^2)*Xd[4]-2*m[heli]*X[4]*l[cm]^2*X[3]*X[1] = K[yy]*U[2]+K[yp]*U...

Additional Insight: Inertia (or mass) Matrix: Fi

The nonlinear system of equations resulting from the Lagrangian mechanics can be written in the following matrix form:

F( q ) . qdd + G( q, qd ) . qd + H( q ) . q = L( q, qd, u )

F, G, and H are called, respectively, the mass, damping, and stiffness matrices.

They are symmetric in form.

The inertia (a.k.a. mass) matrix, F, gives indications regarding the coupling existing in the system.

>    Fi := Matrix( Nq, Nq ):

>    for i from 1 to Nq do
  for k from 1 to Nq do
    Fi[ i, k ] := simplify( diff( op( 1, EOM_states[i] ), Xd[k+Nq] ) );
    Fi[ i, k ] := collect( combine( Fi[ i, k ], trig ), cos );
  end do;
end do:

>    'F[i]' = Fi;

F[i] = Matrix(%id = 485352)

Linearization of the inertia matrix for small-displacements

>    Fi_lin := Matrix( Nq, Nq ):

>    for i from 1 to Nq do
  for k from 1 to Nq do
    Fi_lin[ i, k ] := Fi[ i, k ];
    Fi_lin[ i, k ] := convert( series( Fi_lin[ i, k ], X[ 1 ] ), polynom );
    Fi_lin[ i, k ] := subs( subs_XUzero, Fi_lin[ i, k ] );
  end do;
end do:

>    'F_lin' = Fi_lin;

F_lin = Matrix(%id = 636292)

Solving the Euler-Lagrange's Equations

Reverse State Substitution for Pretty Display of the Solved EOM's

only for pretty print

>    subs_Xq_rev := { seq( X[i] = q[i], i=1..Nq ) }:
subs_Xqd_rev := { seq( X[i+Nq] = qd[i], i=1..Nq ) }:

>    subs_U_rev := { U[1] = V[m_p], U[2] = V[m_y] }:
#subs_U_rev := { U[1] = tau[m] }:

>    eom_collect_list := { seq( diff( q[i], t ), i=1..Nq ), seq( q[i], i=1..Nq ), J[eq_p], J[eq_y], V[m_p], V[m_y] };

eom_collect_list := {V[m_p], V[m_y], J[eq_p], diff(theta(t),t), diff(psi(t),t), theta(t), psi(t), J[eq_y]}

Solution to the Non-Linear Equations of Motion

Solve the non-linear form of the equations of motion for the states' second time derivatives

NOTE: These computations take long and therefore they have been commented.

>    Xqdd_solset_nl := solve( convert( EOM_states, set ), convert( Xqdd, set ) ):

>    assign( Xqdd_solset_nl );

>    for i from 1 to Nq do
  Xd_nl[i+Nq] := simplify( Xd[i+Nq] ):
  unassign( 'Xd[i+Nq]' ):
end do:

pretty display w.r.t. the named system states

>    for i from 1 to Nq do
 Xd_nl[i+Nq] := simplify( subs( subs_U_rev, subs_Xq_rev, subs_Xqd_rev, Xd_nl[i+Nq] )):
end do;

Xd_nl[3] := -(-K[pp]*V[m_p]-K[py]*V[m_y]+m[heli]*diff(psi(t),t)^2*sin(theta(t))*l[cm]^2*cos(theta(t))+m[heli]*g*cos(theta(t))*l[cm]+B[p]*diff(theta(t),t))/(J[eq_p]+m[heli]*l[cm]^2)

Xd_nl[4] := (2*m[heli]*diff(psi(t),t)*sin(theta(t))*l[cm]^2*cos(theta(t))*diff(theta(t),t)+K[yy]*V[m_y]+K[yp]*V[m_p]-B[y]*diff(psi(t),t))/(J[eq_y]+m[heli]*cos(theta(t))^2*l[cm]^2)

>    for i from 1 to Nq do
  diff( qd[i], t ) = collect( Xd_nl[i+Nq], eom_collect_list );
end do;

diff(theta(t),`$`(t,2)) = K[pp]/(J[eq_p]+m[heli]*l[cm]^2)*V[m_p]+K[py]/(J[eq_p]+m[heli]*l[cm]^2)*V[m_y]-(B[p]*diff(theta(t),t)+m[heli]*diff(psi(t),t)^2*sin(theta(t))*l[cm]^2*cos(theta(t))+m[heli]*g*cos...

diff(psi(t),`$`(t,2)) = K[yp]/(J[eq_y]+m[heli]*cos(theta(t))^2*l[cm]^2)*V[m_p]+K[yy]/(J[eq_y]+m[heli]*cos(theta(t))^2*l[cm]^2)*V[m_y]+2*m[heli]*diff(psi(t),t)*sin(theta(t))*l[cm]^2*cos(theta(t))/(J[eq_...
diff(psi(t),`$`(t,2)) = K[yp]/(J[eq_y]+m[heli]*cos(theta(t))^2*l[cm]^2)*V[m_p]+K[yy]/(J[eq_y]+m[heli]*cos(theta(t))^2*l[cm]^2)*V[m_y]+2*m[heli]*diff(psi(t),t)*sin(theta(t))*l[cm]^2*cos(theta(t))/(J[eq_...

Solution to the Linearized EOM's

Solve the linear form of the equations of motion for the states' second time derivatives

>    Xqdd_solset_ser := solve( convert( EOM_ser, set ), convert( Xqdd, set ) ):

>    assign( Xqdd_solset_ser );

Moreover, for small angles

>    subs_avsq_list := { X[Nq+2]^2 = 0, X[Nq+3]^2 = 0 }:

>    for i from 1 to Nq do
  Xd[i+Nq] := subs( subs_avsq_list, Xd[i+Nq] );
end:

pretty display w.r.t. the named system states

>    for i from 1 to Nq do
  diff( qd[i], t ) = collect( subs( subs_U_rev, subs_Xq_rev, subs_Xqd_rev, Xd[i+Nq] ), eom_collect_list );
end do;

diff(theta(t),`$`(t,2)) = K[pp]/(J[eq_p]+m[heli]*l[cm]^2)*V[m_p]+K[py]/(J[eq_p]+m[heli]*l[cm]^2)*V[m_y]-1/(J[eq_p]+m[heli]*l[cm]^2)*(m[heli]*g*l[cm]+B[p]*diff(theta(t),t))

diff(psi(t),`$`(t,2)) = K[yp]/(J[eq_y]+m[heli]*l[cm]^2)*V[m_p]+K[yy]/(J[eq_y]+m[heli]*l[cm]^2)*V[m_y]+2*m[heli]*diff(psi(t),t)*l[cm]^2*theta(t)/(J[eq_y]+m[heli]*l[cm]^2)*diff(theta(t),t)-B[y]*diff(psi(...

Determine the System State-Space Matrices: A, B, C, and D

>    A_ss := Matrix( Nx, Nx ):

>    A_ss := deriveA( Xqdd, A_ss, Nq, subs_XUzero ):

>    'A' = A_ss;

A = Matrix(%id = 589664)

>    B_ss := Matrix( Nx, Nu ):

>    B_ss := deriveB( Xqdd, B_ss, Nq, subs_XUzero ):

>    'B' = B_ss;

B = Matrix(%id = 671612)

>    C_ss := IdentityMatrix( Nx, Nx ):
'C' = C_ss;

C = Matrix(%id = 750472)

>    D_ss := Matrix( Nx, Nu, 0 ):
'D' = D_ss;

D = Matrix(%id = 709332)

Write A, B, C, and D to a Matlab file

Save the state-space matrices A, B, C and D to a MATLAB file.

>    Matlab_File_Name := "HELI_2D_ABCD_eqns.m":

unassign variables, when necessary, for those present in the "Matlab_Notations" substitution set

>    if assigned( B[p] ) then
  unassign( 'B[p]' );
end if;

>    if assigned( B[y] ) then
  unassign( 'B[y]' );
end if;

>    if assigned( J[eq_p] ) then
  unassign( 'J[eq_p]' );
end if;

>    if assigned( J[eq_y] ) then
  unassign( 'J[eq_y]' );
end if;

substitution set containing a notation consistent with that used in the MATLAB design script(s)

>    Matlab_Notations := {m[heli] = m_heli, l[cm] = l_cm, J[eq_p] = J_eq_p, J[eq_y]=J_eq_y, B[p] = B_p, B[y] = B_y, K[pp] = K_pp, K[yy] = K_yy, K[py] = K_py, K[yp] = K_yp, R[m_p] = R_m_p, R[m_y] = R_m_y, r[p] = r_p, r[y] = r_y}:

>    Experiment_Name := "2 DOF Helicopter":

>    write_ABCD_to_Mfile( Matlab_File_Name, Experiment_Name, Matlab_Notations, A_ss, B_ss, C_ss, D_ss );

Procedure Printing

default:

>    interface( verboseproc = 1 );

>    eval( lagrange_equations ):

>   

>   

>   

>   

>   

>   

>   

>   

>   

>   

>   

Click here to go back to top: Description Section.