Dynamic Equations for the
Flexible Pendulum (FLEXPEN) Experiment
© 2012 Quanser Consulting Inc.
NOTE: This worksheet presents the general dynamic equations modelling a Flexible Pendulum mounted on a linear cart.
Description
The Quanser_Tools Package
Worksheet Initialization
> | restart: interface( imaginaryunit = j ): |
> | with( LinearAlgebra ): |
> | libname := "C:/Program Files/Quanser/Maple Repository", ".", libname: |
> | with( Quanser_Tools ); |
environment variable representing the order of series calculations
> | Order := 2: |
Generalized Coordinates:
's
The generalized coordinates are also called Lagrangian coordinates.
= driving cart (i.e. IP02 ) linear position
= Position angle of the solid pendulum about the vertical: the zero angle [mod 2*pi] is defined when the IP is in the perfect upright position.
= Deflection angle of the flexible pendulum.
> | q := [ x[c](t), alpha(t), gamma(t) ]; |
Nq = number of Lagrangian coordinates
Nq is also the number of position states.
> | Nq := nops( q ): |
Np = number of pendulums
> | Np := Nq - 1: |
qd = first-order time derivative of the generalized coordinates, e.g. position and angular velocities
> | qd := map( diff, q, t ); |
Cartesian Coordinates of the Flexible Pendulum's Centre Of Gravity
conventions:
1) corresponds to the stiff pendulum being perfectly vertical, pointing upwards.
2) corresponds to the flexible pendulum being perfectly stiff. Having both and means the flexible pendulum is vertical, point upwards, and stiff.
3) Positive rotation is CCW when facing the cart.
= x-coordinate of the solid pendulum (i.e. subscript "sp") COG absolute Cartesian position
= y-coordinate of the solid pendulum (i.e. subscript "sp") COG absolute Cartesian position
> | x[sp] := q[1] - l[sp] * sin( q[2] ); y[sp] := l[sp] * cos( q[2] ); |
= x-coordinate of the flexible pendulum (i.e. subscript "fp") COG absolute Cartesian position
= y-coordinate of the flexible pendulum (i.e. subscript "fp") COG absolute Cartesian position
> | x[fp] := q[1] - l[sp] * sin( q[2] ) - l[fp] * sin(q[3]); y[fp] := l[sp] * cos( q[2] ) + l[fp] * cos(q[3]); |
= x-coordinate of the stiff IP's COG absolute Cartesian velocity
= y-coordinate of the stiff IP's COG absolute Cartesian velocity
> | xd[sp] := diff( x[sp], t ); yd[sp] := diff( y[sp], t ); |
= x-coordinate of the stiff IP's COG absolute Cartesian velocity
= y-coordinate of the stiff IP's COG absolute Cartesian velocity
> | xd[fp] := diff( x[fp], t ); yd[fp] := diff( y[fp], t ); |
State-Space Variables
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 ) }; |
Substitution set for the input(s).
set the input to be the motor voltage:
> | #subs_U := { V[m] = U[1] }: |
set the input to be the cart's driving force:
(if not expressed as a function of the motor voltage):
> | subs_U := { F[c] = U[1] }: |
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 ) }; |
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 ) ]; |
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 Lagragian of the system.
Total Potential Energy:
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] := potential_energy( 'spring', K[s], q[3] ); |
V[g] = Total Gravitational Potential Energy of the system
initialization:
> | V[g] := potential_energy( 'gravity', M[sp], g, y[sp] ) + potential_energy( 'gravity', M[fp], g, y[fp] ); |
V[T] = Total Potential Energy of the system
> | V[T] := simplify( V[g] + V[e] ); |
Total Kinetic Energy:
The total kinetic energy can be expressed in terms of the generalized coordinates and their first-time derivatives.
= translational kinetic energy of the motorized cart (e.g. IP02)
= cart total mass
> | Tt[c] := kinetic_energy( 'translation', M[c], qd[1] ); |
The cart's directions of translation and rotation are orthogonal.
= kinetic energy due to rotation tied to the motorized cart
= motor armature inertia;
= gear ratio;
= motor pinion radius
> | Tr[c] := kinetic_energy( 'rotation', J[m], omega[m](t) ): 'Tr[c]' = Tr[c]; |
> | omega[m](t) := K[g] * qd[1] / r[mp]; |
Since
< 0.14 kg <
, the rotational kinetic energy on the IP02 can be neglected:
> | Tr[c] := 0: |
= Total Kinetic Energy of the cart system
initialization:
> | T[T_c] := Tt[c] + Tr[c]; |
The rigid pendulum, or STIFFPEN, motion is composed of one rotation and one translation, both directions are orthogonal.
= stiff pendulum's rotational kinetic kinergy;
= stiff pendulum translational kinetic kinergy
Rotational energy of STIFFPEN
> | Tr[sp] := kinetic_energy( 'rotation', J[sp], qd[2] ); |
Translational energy of STIFFPEN
> | v[sp] := n_norm( [ xd[sp], yd[sp] ], 2 ): Tt[sp] := kinetic_energy( 'translation', M[sp], v[sp] ); |
Total kinetic energy of STIFFPEN
> | T[T_sp] := Tr[sp] + Tt[sp]; |
The flexible pendulum, or FLEXPEN, motion is composed of one rotation and one translation, both directions are orthogonal.
= FLEXPEN rotational kinetic kinergy;
= FLEXPEN translational kinetic kinergy
Rotational energy of flexpen.
> | Tr[fp] := kinetic_energy( 'rotation', J[fp], qd[3] ); |
Translational energy of flexpen
> | v[fp] := n_norm( [ xd[fp], yd[fp] ], 2 ): Tt[fp] := kinetic_energy( 'translation', M[fp], v[fp] ); |
Total kinetic energy of FLEXPEN.
> | T[T_fp] := Tr[fp] + Tt[fp]; |
Total kinetic energy of system
> | T_temp := T[T_c] + T[T_sp] + T[T_fp]: T[T] := collect( T_temp, diff ); |
Generalized Forces:
's
The non-conservative forces corresponding to the generalized coordinates are:
and the viscous damping forces, where
= linear force generated by the motorized cart (e.g. IP02)
= STIFFPEN viscous friction torque coefficient (a.k.a. viscous damping)
= FLEXPEN viscous friction torque coefficient (a.k.a. viscous damping)
= cart viscous damping force coefficient
= 0 and
= 0 and
= 0 if all viscous dampings are neglected
> | B[eq] := 0: B[sp] := 0: B[fp] := 0: |
Q[i] = generalized force applied on generalized coordinate q[i]
the Coulomb friction is neglected, as well as the force due to the pendulum and acting on the linear cart
> | Q[1] := F[c] - B[eq] * qd[1]; |
> | Q[2] := - B[sp] * qd[2]; |
> | Q[3] := - B[fp] * qd[3]; |
= Linear force produced by the motor at the motor pinion: cart driving force
rm: comment the following line out if
, uncomment it if
> | #F[c] := eta[g] * K[g] * eta[m] * K[t] * ( V[m] * r[mp] - K[g] * K[m] * qd[1] ) / R[m] / r[mp]^2; |
> | Q := [ seq( Q[i], i=1..Nq ) ]; |
Euler-Lagrange's Equations
For a N -DOF system, the Lagrange's equations can be written:
for
through
where:
's are special combinations of external forces and called the
generalized forces,
, ...,
, are
N
independent coordinates chosen to describe the system and called the
generalized coordinates
,
and is the Lagrangian of the system.
is defined by:
where is the total kinetic energy of the system and 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: alpha0 = 0, and alpha_dot0 = 0
> | EOM_ser := EOM_states: |
Generalized series expansions of the trigonometric functions is used (for small angles).
> | for i from 1 to Nq do for k from 1 to Np do EOM_ser[i] := subsop( 1 = convert( series( op( 1, EOM_ser[i] ), X[ k+1 ] ), polynom ), EOM_ser[i] ); end do: EOM_ser[i] := simplify( EOM_ser[i] ); end do: |
> | EOM_ser; |
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; |
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[ 2 ] ), polynom ); Fi_lin[ i, k ] := subs( subs_XUzero, Fi_lin[ i, k ] ); end do; end do: |
> | 'F_lin' = Fi_lin; |
Solving the Euler-Lagrange's Equations
To solve the Euler-Lagrange's equations, they need to be linear.
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] }: subs_U_rev := { U[1] = F[c] }: |
> | eom_collect_list := { seq( diff( q[i], t ), i=1..Nq ), seq( q[i], i=1..Nq ) }; |
> | if not assigned( J[sp] ) then eom_collect_list := eom_collect_list union { J[sp] }; end if; |
> | if not assigned( J[fp] ) then eom_collect_list := eom_collect_list union { J[fp] }; end if; |
Solution to the Non-Linear Equations of Motion
Solve the non-linear form of the equations of motion for the states' second time derivatives
> | #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: |
> | #for i from 1 to Nq do # diff( qd[i], t ) = collect( Xd_nl[i+Nq], eom_collect_list ): #end do: |
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; |
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; |
> | B_ss := Matrix( Nx, Nu ): |
> | B_ss := deriveB( Xqdd, B_ss, Nq, subs_XUzero ): 'B' = B_ss; |
> | C_ss := IdentityMatrix( Ny, Nx ); |
> | D_ss := Matrix( Ny, Nu, 0 ); |
> |
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 := "FLEXPEN_ABCD_eqns.m": |
unassign variables, when necessary, for those present in the "Matlab_Notations" substitution set
> | if assigned( B[eq] ) then unassign( 'B[eq]' ); end if; |
> | if assigned( B[sp] ) then unassign( 'B[sp]' ); end if; |
> | if assigned( J[sp] ) then unassign( 'J[sp]' ); end if; |
> | if assigned( B[fp] ) then unassign( 'B[fp]' ); end if; |
> | if assigned( J[fp] ) then unassign( 'J[fp]' ); end if; |
substitution set containing a notation consistent with that used in the MATLAB design script(s)
> | Matlab_Notations := { M[c] = Mc, M[sp] = Msp, l[sp] = lsp, J[sp] = Jsp, B[sp] = Bsp, M[fp] = Mfp, l[fp] = lfp, J[fp] = Jfp, B[fp] = Bfp, B[eq] = Beq, K[t] = Kt, K[m]=Km, K[g]=Kg, r[mp] = r_mp, eta[m] = Eff_m, eta[g] = Eff_g, R[m]=Rm, K[s] = Ks }: |
> | Experiment_Name := "IP02+FLEXPEN System": |
> | 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 ): |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |